Example #1
0
/******************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void) {
  uint32_t i;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();

  UARTInit(0, 115200);
  UARTInit(1, 115200);

  u0_src = (uint8_t *)UART0_DMA_TX_SRC;
  u0_dst = (uint8_t *)UART0_DMA_RX_DST;
  u1_src = (uint8_t *)UART1_DMA_TX_SRC;
  u1_dst = (uint8_t *)UART1_DMA_RX_DST;
  for ( i = 0; i < UART_DMA_SIZE; i++ )
  {
	*u0_src++ = *u1_src++ = ConvertDigital(i);
	*u0_dst++ = *u1_dst++ = 0;
  }

  DMA_Init();

  /* Connect UART0 and UART1 via a RS232 cable. The sequence is, UART DMA starts 
  from UART0 TX, lookback to UART1 RX using channel 0 and 1. Then, UART DMA starts
  from UART1 TX, lookback to UART0 RX using channel 2 and 3.
  So, both M2P+P2M on UART0 and UART1 are tested. */

  /* DMA from UART0 TX to UART1 RX using channel 0 and 1. */
  DMAChannel_Init( 0, M2P );
  LPC_GPDMACH0->CConfig |= 0x0C001|(0x00<<1)|(DMA_UART0_TX<<6)|(0x01 << 11);
  LPC_UART0->FCR |= 0x08;

  /* DMA request was sent inside DMA ISR when DMA is done.
  The data should arrive at UART1 RX already. */
  while ( !UARTDMA0Done );
  UARTDMA0Done = 0;
  while ( !UARTDMA1Done );
  UARTDMA1Done = 0;

  /* Between UART0 TX and UART1 RX, the data should match, or fatal DMA error. */
  u1_src = (uint8_t *)UART0_DMA_TX_SRC;
  u1_dst = (uint8_t *)UART1_DMA_RX_DST;
  for ( i = 0; i < UART_DMA_SIZE; i++ )
  {
	if ( *u1_src++ != *u1_dst++ )
	{
	  while ( 1 );
	}
  }

  /* DMA from UART1 TX to UART0 RX using channel 2 and 3. */
  DMAChannel_Init( 2, M2P );
  NVIC_EnableIRQ(DMA_IRQn);
  LPC_GPDMACH2->CConfig |= 0x0C001|(0x00<<1)|(DMA_UART1_TX<<6)|(0x01 << 11);
  LPC_UART1->FCR |= 0x08;

  /* DMA request was sent inside DMA ISR when DMA is done.
  The data should arrive at UART1 RX already. */
  while ( !UARTDMA2Done );
  UARTDMA2Done = 0;
  while ( !UARTDMA3Done );
  UARTDMA3Done = 0;
  LPC_GPDMA->Sync = (0x1<<DMA_UART0_RX)|(0x1<<DMA_UART1_TX);

  /* The data is transferred from M2U0TX-U1RX-, M2U1TX-U0RX. */
  /* Between UART0 TX and UART0 RX, the data should match, or fatal DMA error. */
  u1_src = (uint8_t *)UART1_DMA_TX_SRC;
  u1_dst = (uint8_t *)UART0_DMA_RX_DST;
  for ( i = 0; i < UART_DMA_SIZE; i++ )
  {
	if ( *u1_src++ != *u1_dst++ )
	{
	  while ( 1 );
	}
  }
  while ( 1 );
  return(0);
}
Example #2
0
/*****************************************************************************
** Function name:		PrintoutADCValue
**
** Descriptions:		Dump ADC reading to the UART
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
static void PrintoutADCValue( void )
{
  uint32_t i, j = 0;

  /* Bring cursor to home on terminal, write headers */
  UARTBuffer[j++] = 'C';
  UARTBuffer[j++] = 'h';
  UARTBuffer[j++] = ' ';
  UARTBuffer[j++] = 'C';
  UARTBuffer[j++] = 'U';
  UARTBuffer[j++] = 'R';
  UARTBuffer[j++] = ' ';
  UARTBuffer[j++] = 'M';
  UARTBuffer[j++] = 'I';
  UARTBuffer[j++] = 'N';
  UARTBuffer[j++] = ' ';
  UARTBuffer[j++] = 'M';
  UARTBuffer[j++] = 'A';
  UARTBuffer[j++] = 'X';
  UARTBuffer[j++] = '\r';
  UARTBuffer[j++] = '\n';
  UARTSend( (uint8_t *)UARTBuffer, j );

  /* Update current, min, and max values on terminal */
  for ( i = 0; i < ADC_NUM; i++ )
  {
    j = 0;
	UARTBuffer[j++] = ConvertDigital(i);
	UARTBuffer[j++] = ' ';
    UARTBuffer[j++] = ConvertDigital( (uint8_t)((ADCValue[i]>>8)&0xF));
    UARTBuffer[j++] = ConvertDigital( (uint8_t)((ADCValue[i]>>4)&0xF));
    UARTBuffer[j++] = ConvertDigital( (uint8_t)(ADCValue[i]&0xF));
    UARTBuffer[j++] = ' ';
    UARTBuffer[j++] = ConvertDigital( (uint8_t)((ADCMinValue[i]>>8)&0xF));
    UARTBuffer[j++] = ConvertDigital( (uint8_t)((ADCMinValue[i]>>4)&0xF));
    UARTBuffer[j++] = ConvertDigital( (uint8_t)(ADCMinValue[i]&0xF));
    UARTBuffer[j++] = ' ';
    UARTBuffer[j++] = ConvertDigital( (uint8_t)((ADCMaxValue[i]>>8)&0xF));
    UARTBuffer[j++] = ConvertDigital( (uint8_t)((ADCMaxValue[i]>>4)&0xF));
    UARTBuffer[j++] = ConvertDigital( (uint8_t)(ADCMaxValue[i]&0xF));
    UARTBuffer[j++] = '\r';
    UARTBuffer[j++] = '\n';
    UARTSend( (uint8_t *)UARTBuffer, j );
  }

  /* Show number of samples until next clear */
  j=0;
  UARTBuffer[j++] = 'N';
  UARTBuffer[j++] = 'o';
  UARTBuffer[j++] = ' ';
  UARTBuffer[j++] = 'o';
  UARTBuffer[j++] = 'f';
  UARTBuffer[j++] = ' ';
  UARTBuffer[j++] = 'S';
  UARTBuffer[j++] = 'a';
  UARTBuffer[j++] = 'm';
  UARTBuffer[j++] = 'p';
  UARTBuffer[j++] = 'l';
  UARTBuffer[j++] = 'e';
  UARTBuffer[j++] = 's';
  UARTBuffer[j++] = ':';
  UARTBuffer[j++] = ' ';
  UARTBuffer[j++] = ConvertDigital( (uint8_t)((ClearCounter>>8)&0xF));
  UARTBuffer[j++] = ConvertDigital( (uint8_t)((ClearCounter>>4)&0xF));
  UARTBuffer[j++] = ConvertDigital( (uint8_t)(ClearCounter&0xF));
  UARTBuffer[j++] = '\r';
  UARTBuffer[j++] = '\n';
  UARTBuffer[j++] = '\n';
  UARTSend( (uint8_t *)UARTBuffer, j );

  return;
}