uarttest.c

来自「nxp的LPC2888处理器的示例代码.」· C语言 代码 · 共 110 行

C
110
字号
/*****************************************************************************
 *   uarttest.c:  main C entry file for NXP LPC23xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.07.13  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC288x.h"                        /* LPC2xxx definitions */
#include "type.h"
#include "target.h"
#include "irq.h"
#include "uart.h"
#if UART_DMA_ENABLE
#include "ex_sdram.h"
#include "dma.h"
#endif

extern volatile DWORD UART0Count;
extern volatile BYTE UART0Buffer[BUFSIZE];

#if UART_DMA_ENABLE
extern volatile DWORD DMACompCount[DMA_CHANNELS];
#endif
/*****************************************************************************
**   Main Function  main()
*****************************************************************************/
int main (void)
{
#if UART_DMA_ENABLE
  DWORD i;
  BYTE *src_addr, *dest_addr;
#endif
  TargetResetInit();

  UARTInit(115200);	/* baud rate setting */

#if UART_DMA_ENABLE
  /* SDRAM is used for DMA test, it's to be initialized first. */
  SDRAMInit();
  DMA_UART_Init();

  for ( i=0; i < DMA_CHANNELS; i++ )
  {
	DMACompCount[i] = 0;
  }

  /* test channel 2 and 3 for UART TX and RX, test in pair, in another 
  word, start two channels, finished TX and then RX, verify the RX and 
  TX buffer. */
  /* In order to test UART DMA, start this test program, ASCII data 
  should be dumped to the terminal, the length of the data block is
  UART_DATA_LENGTH, save the data from the terminal to a file, 
  make sure CR and LF are not appended to the file. Then, from the
  terminal, send this file, right after the UART TX, it will wait for
  the data to be received, once the file sent from the terminal,
  the UART data will be received on the DMA channel 3(RX), DMACompCount[3]
  will be non-zero upon completion. The data will be saved in the
  SDRAM_RD_ADDR area, the content of SDRAM_WR_ADDR and SDRAM_RD_ADDR,
  size UART_DATA_LENGTH, should match. */             
  src_addr = (BYTE *)SDRAM_WR_ADDR;
  dest_addr = (BYTE *)SDRAM_RD_ADDR;
  for ( i = 0; i < UART_DATA_LENGTH; i++ )
  {
	*src_addr++ = (i % 10) + 0x30;	/* ASCII code for dumping UART data */
	*dest_addr++ = 0;
  }

  DMA_CH_Enable( 2 );				
  while ( !DMACompCount[2] );	/* Wait until DMA TX is done */
  DMACompCount[2] = 0;

  DMA_CH_Enable( 3 );
  while ( !DMACompCount[3] );	/* Wait until DMA RX is done */
  DMACompCount[3] = 0;

  /* Verify result */
  src_addr = (BYTE *)SDRAM_WR_ADDR;
  dest_addr = (BYTE *)SDRAM_RD_ADDR;
  for ( i = 0; i < UART_DATA_LENGTH; i++ )
  {
	if ( *src_addr != *dest_addr )
	{
	  while ( 1 );	/* fatal error */
	}
	src_addr++;
	dest_addr++;
  }
  /* Match successfully after both UART DMA TX and RX complete */
#else
  while (1) 
  {				/* Loop forever */
	if ( UART0Count != 0 )
	{
	  UART_IER = IER_THRE | IER_RLS;			/* Disable RBR */
	  UARTSend( (BYTE *)UART0Buffer, UART0Count );
	  UART0Count = 0;
	  UART_IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */
	}
  }
#endif
  return 0;
}

/*****************************************************************************
**                            End Of File
*****************************************************************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?