⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart0.c

📁 2410得测试程序
💻 C
📖 第 1 页 / 共 2 页
字号:

	while(isDone);

	/*********** UART0 Rx test with DMA0 ***********/ 
	isDone=1;
	uart0RxStr=(char *)UARTBUFFER;
	Uart_Printf("\n[Uart channel 0 DMA0 Rx Test]\n");
	Uart_Printf("Type any five keys!!!\n");	
	Uart_Printf("Then you will see what you typed.\n");

	pISR_DMA0=(unsigned)Uart0_RxDmaDone;
	pISR_UART0=(unsigned)Uart0_RxDmaOrErr;
	
	rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction	
	rUCON0 |= (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(2);
	//Clock,Tx:Def,Rx:Def,Rx timeout:x,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:dma0

	/***DMA0 init***/
	rDISRC0=(U32)URXH0;				// Start address
	rDISRCC0=(1<<1)|(1);			// APB,Fixed
	rDIDST0=(U32)uart0RxStr;		// Memory buffer Address
	rDIDSTC0= (0<<1)|(0);			// AHB,Increment
	rDCON0=((U32)1<<31)|(0<<30)|(1<<29)|(0<<28)|(0<<27)|(1<<24)|(1<<23)|(1<<22)|(0<<20)|(5);
	//handshake, sync PCLK, TC int, single tx, single service, Uart0, H/W request,auto-reload off, Byte size Tx, Tx count value

	// Clear Int Pending and Unmask	
	ClearPending(BIT_UART0);
	rINTMSK=~(BIT_DMA0|BIT_UART0);
	rSUBSRCPND=(BIT_SUB_TXD0|BIT_SUB_RXD0|BIT_SUB_ERR0);		
	rINTSUBMSK=~(BIT_SUB_ERR0);
	rDMASKTRIG0=(0<<2)|(1<<1)|(0);	//no-stop, DMA0 channel on, no-SW trigger 

	while(isDone);

	Uart_Printf("%s\n",uart0RxStr);
	Uart_Port_Return();
}

void __irq Uart0_TxFifo(void)
{
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);	// Just for the safety
	while (!(rUFSTAT0 & 0x200) && (*uart0TxStr != '\0'))	//until tx fifo full or end of string
		WrUTXH0(*uart0TxStr++);	
	
	if(*uart0TxStr == '\0') 
	{
		rINTMSK|=BIT_UART0;
		rSUBSRCPND=BIT_SUB_TXD0;	// Clear Sub int pending
		ClearPending(BIT_UART0);	// Clear master pending
	}
	else 
	{
		ClearPending(BIT_UART0);	// Clear master pending
		rSUBSRCPND=BIT_SUB_TXD0;	// Clear Sub int pending
		rINTSUBMSK&=~(BIT_SUB_TXD0);// Unmask sub int
	}
}

void __irq Uart0_RxFifoOrErr(void)
{
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	if(rSUBSRCPND&BIT_SUB_RXD0)
		__sub_Uart0_RxFifo();
	else
		__sub_Uart0_RxErrInt();
	ClearPending(BIT_UART0);
	rSUBSRCPND=(BIT_SUB_RXD0|BIT_SUB_ERR0);	// Clear Sub int pending	
	rINTSUBMSK&=~(BIT_SUB_RXD0|BIT_SUB_ERR0);	
}

void __sub_Uart0_RxFifo(void)
{
	while((rUFSTAT0&0x100)||(rUFSTAT0&0xf))	//During the Rx FIFO is not empty
	{
		rx_point++;
		if(rx_point<5)
			rx_filesize |= (RdURXH0()<<(8*(rx_point-1))); // First 4-bytes mean file size
		else if(rx_point>(rx_filesize-2))	
		{
			rx_dncs |= (RdURXH0()<<(8*(1-(rx_filesize-rx_point)))); //Last 2-bytes mean checksum.
			if(rx_point==rx_filesize) rx_isdone=0;
		}
		else
			rx_checksum+=RdURXH0();
	}
}

void Test_Uart0_Fifo(void)
{
	Uart_Port_Set(); 
	Uart_Select(0);
	/******* UART0 Tx FIFO test with interrupt ********/	
	Uart_Printf("[Uart channel 0 Tx FIFO Interrupt Test]\n");
	Uart_TxEmpty(0);	//wait until tx buffer is empty.
	
	/* <Tx Trigger Level:8Byte> */	
	uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890->UART0 Tx FIFO interrupt(8byte) test is good!!!!\r\n";
	pISR_UART0=(U32)Uart0_TxFifo;
	rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction	
	rUCON0 |= (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(0);
	//Clock,Tx:Def,Rx:Def,Rx timeout:x,Rx error int:x,Loop-back:x,Send break:x,Tx:int,Rx:x
	rUFCON0=(2<<6)|(1<<4)|(1<<2)|(1<<1)|(1);
	//Tx and Rx FIFO Trigger Level:8byte,Tx and Rx FIFO Reset,FIFO on
	rINTMSK=~(BIT_UART0);
	rINTSUBMSK=~(BIT_SUB_TXD0);
	Delay(500);
	rUFCON0=(2<<6)|(1<<4)|(1<<2)|(1<<1)|(0);
	//Tx and Rx FIFO Trigger Level:8byte,Tx and Rx FIFO Reset,FIFO off

	/* <Tx Trigger Level:12Byte> */	
	uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890->UART0 Tx FIFO interrupt(12byte) test is good!!!!\r\n";
	pISR_UART0=(unsigned)Uart0_TxFifo;
	rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction	
	rUCON0 |= (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(0);
	//Clock,Tx:Def,Rx:Def,Rx timeout:x,Rx error int:x,Loop-back:x,Send break:x,Tx:int,Rx:x
	rUFCON0=(3<<6)|(2<<4)|(1<<2)|(1<<1)|(1);
	//Tx and Rx FIFO Trigger Level:12byte,Tx and Rx FIFO Reset,FIFO on
	rINTMSK=~(BIT_UART0);
	rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	Delay(500);
	rUFCON0=(3<<6)|(2<<4)|(1<<2)|(1<<1)|(0);
	//Tx and Rx FIFO Trigger Level:12byte,Tx and Rx FIFO Reset,FIFO off

	
	/******* UART0 Rx FIFO test with interrupt ********/	
	rx_dncs=0;
	rx_point=0;
	rx_isdone=1;
	rx_filesize=0;
	rx_checksum=0;
	Uart_Printf("[Uart channel 0 Rx FIFO Interrupt Test]\n");
//----------------------------------------------------
	pISR_UART0=(unsigned)Uart0_RxFifoOrErr;

	rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction
	rUCON0 |= (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(1<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
	//Clock,Tx:Def,Rx:Def,Rx timeout:o,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int
	rUFCON0=(1<<6)|(0<<4)|(1<<2)|(1<<1)|(1);
	//Tx and Rx FIFO Trigger Level:4byte,Tx and Rx FIFO Reset,FIFO on

	// Clear Int Pending and Unmask 
	ClearPending(BIT_UART0);
	rINTMSK=~(BIT_UART0);
	rSUBSRCPND=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_ERR0);

	Uart_Printf("Download the target file[*.bin] by Uart0\n");
	
	while(rx_isdone);

	rINTMSK |= (BIT_UART0);	
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);

	rUFCON0=(3<<6)|(2<<4)|(1<<2)|(1<<1)|(0);
	//Tx and Rx FIFO Trigger Level:12byte,Tx and Rx FIFO Reset,FIFO off
			
	if(rx_dncs==(rx_checksum&0xffff)) 
		Uart_Printf("\nDownload test OK!!!\n");
	else 
		Uart_Printf("\nError!!!\n");
	Uart_Port_Return();	
}

void __irq Uart0_AfcTx(void)
{
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);

	if(tx_cnt<AFC_BUFLEN)
	{
		Uart_Printf("%d,",*txdataPt);
		WrUTXH0(*txdataPt++);
		tx_cnt++;
		ClearPending(BIT_UART0);
		rSUBSRCPND=(BIT_SUB_TXD0);
		rINTSUBMSK&=~(BIT_SUB_TXD0);
	}
	else
	{
		tx_end=1;
		while(rUFSTAT0 & 0x2f0);	//Until FIFO is empty
		ClearPending(BIT_UART0);
		rSUBSRCPND=(BIT_SUB_TXD0);
		rINTMSK|=BIT_UART0;
	}
}

void __irq Uart0_AfcRxOrErr(void)
{
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	if(rSUBSRCPND&BIT_SUB_RXD0)
		__sub_Uart0_RxAfc();	
	else
		__sub_Uart0_RxErrInt();

	ClearPending(BIT_UART0);
	rSUBSRCPND=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	rINTSUBMSK&=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
}

void __sub_Uart0_RxAfc(void)
{
	while( (rUFSTAT0 & 0x100) || ((rUFSTAT0 & 0xf) >0) )
	{
		*rxdataPt=rURXH0;
		Uart_Printf("%d,",*rxdataPt++);
		rx_cnt++;
	}
	if(rx_cnt == AFC_BUFLEN) 
	{
		rx_end=1;
		rINTMSK|=BIT_UART0;
	}
}
 
void Test_Uart0_AfcTx(void)
{
	int i;

	tx_cnt=0;
	tx_end=0;
	txdataFl=(volatile U8 *)UARTBUFFER;
	txdataPt=(volatile U8 *)UARTBUFFER;
	for(i=0;i<AFC_BUFLEN;i++)
		*txdataFl++=i;	// Initialize the AFC data
	Uart_Port_Set(); 
	Uart_Select(0);
	Uart_Printf("[Uart channel 0 AFC Tx Test]\n");
	Uart_Printf("This test should be configured two boards.\n");
	Uart_Printf("Connect Tx and Rx Board with twitsted(rx/tx, nCTS/nRTS) cable .\n");
	Uart_Printf("\nConnect PC[COM1 or COM2] and UART1 of SMDK2410 with a serial cable!!! \n");

	Uart_Printf("Then, press any key........\n");
	Uart_Select(1);		// Change the uart port	
	Uart_Getch();
	Uart_Printf("Start Rx first and then press any key to start Tx.....\n");
	Uart_Getch();

	pISR_UART0=(unsigned) Uart0_AfcTx;

	rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction	
	rUCON0 |= (1<<9)|(1<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
	//Clock,Tx:Lev,Rx:Lev,Rx timeout:x,Rx error int:x,Loop-back:x,Send break:x,Tx:int,Rx:int
	rUFCON0=(1<<6)|(0<<4)|(1<<2)|(1<<1)|(1);
	//Tx and Rx FIFO Trigger Level:4byte,Tx and Rx FIFO Reset,FIFO on
	rUMCON0=0x10;		// Enable Uart0 AFC 
	rINTMSK=~(BIT_UART0);
	rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);

	while(!tx_end);

	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	rUFCON0=(3<<6)|(2<<4)|(1<<2)|(1<<1)|(0);
	//Tx and Rx FIFO Trigger Level:12byte,Tx and Rx FIFO Reset,FIFO off
	Uart_Printf("\nEnd Tx, transfer data count=%d\n",tx_cnt);

	Uart_Printf("\nConnect PC[COM1 or COM2] and UART0 of SMDK2410 with a serial cable!!! \n");
	Uart_Printf("Then, press any key........\n");
	Uart_Select(0);
	Uart_Getch();
	Uart_Port_Return();
}

void Test_Uart0_AfcRx(void)
{
	unsigned int i;

	rx_cnt=0;
	rx_end=0;
	afc_err=0;
	rxdataCk=(volatile U8 *)UARTBUFFER;
	rxdataPt=(volatile U8 *)UARTBUFFER;
	Uart_Port_Set(); 
	Uart_Select(0);
	Uart_Printf("[Uart channel 0 AFC Rx Test]\n");
	Uart_Printf("This test should be configured two boards.\n");
	Uart_Printf("Connect Tx and Rx Board with twitsted(rx/tx, nCTS/nRTS) cable .\n");
	
	Uart_Printf("\nConnect PC[COM1 or COM2] and UART1 of SMDK2410 with a serial cable!!! \n");
	Uart_Printf("Then, press any key........\n");
	Uart_Select(1);		// Change the uart port	
	Uart_Getch();
	Uart_Printf("Press any key to start Rx and then Star Tx....\n");
	Uart_Getch();

	pISR_UART0=(unsigned) Uart0_AfcRxOrErr;

	rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction	
	rUCON0 |= (1<<9)|(1<<8)|(1<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
	//Clock,Tx:Lev,Rx:Lev,Rx timeout:o,Rx error int:o,Loop-back:x,Send break:x,Tx:o,Rx:o
	
	rUFCON0=(1<<6)|(0<<4)|(1<<2)|(1<<1)|(1);
	//Tx and Rx FIFO Trigger Level:4byte,Tx and Rx FIFO Reset,FIFO on
	rUMCON0=0x10;		// Enable Uart0 AFC 
	rINTMSK=~(BIT_UART0);
	rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);

	while(!rx_end);
	
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	rUFCON0=(3<<6)|(2<<4)|(1<<2)|(1<<1)|(0);
	//Tx and Rx FIFO Trigger Level:12byte,Tx and Rx FIFO Reset,FIFO off
	Uart_Printf("\nEnd Rx, receive data count=%d\n",rx_cnt);
	for(i=0;i<AFC_BUFLEN;i++) {
		if(i-(*rxdataCk++))
		{
			Uart_Printf("i=%d\n",i);
			afc_err++;
		}
	}
	if(afc_err)
		Uart_Printf("AFC test fail!! Error count=%d\n",afc_err);
	else
		Uart_Printf("AFC test is good!!\n");

	Uart_Printf("\nConnect PC[COM1 or COM2] and UART0 of SMDK2410 with a serial cable!!! \n");
	Uart_Printf("Then, press any key........\n");
	Uart_Select(0);
	Uart_Getch();
	Uart_Port_Return();
}
//---------------------------------------UART0 test function-------------------------------------

⌨️ 快捷键说明

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