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

📄 uart_test.c

📁 s3c6400 ADS下官方测试程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	printf("\n[Uart channel %d Rx Test]\n",sCh);
	printf("Input any character through the channel %d\n",sCh);
	printf("Press Enter key will stop test & show Rxstring\n");
	printf("\nRx : %s \n",UART_RxString(sCh));
	printf("\nRx Done~ \n");

	// Test End
	printf("\nComplete UART test!!! \n");
	UART_Close(sCh);
	Delay(10000);	
	UART_InitDebugCh(0,115200);
			
}


void Uart_SpeedPollingTx(void)
{
	s32 sCh;	
	s32 sBrate=0;
	u8 ucCnt;


	TxBufferInit();

	
	printf("Which channel do you want to check?\n");
	printf("[0 ~ 3] :");
	sCh = GetIntNum();
	if (sCh == -1)
		sCh = 1;
	else if (sCh == 0)
	{
	printf("Debug Channel will be channel 1\n");
	UART_InitDebugCh(1,115200);
	Delay(1000);
	}	

	printf("\n");
	
	printf("How much BaudRate do you want to use as a Tx?\n");
	printf("BaudRate (ex 9600, 115200[D], 921600) : ");
	sBrate = GetIntNum();
	if (sBrate == -1)
		sBrate = 115200;
	printf("\n");
	
	sCh = UART_SetConfig(sCh,0,1,1,4,3,1,1,sBrate,1,3,1,1);		// Tx 16/ Rx 8 FIFO mode
//	sCh = UART_SetConfig(sCh,0,1,1,4,1,1,1,sBrate,1,1,1,1);	//PCLK
//	sCh = UART_SetConfig(sCh,0,1,1,4,3,1,1,sBrate,1,1,1,1);		//EPLL
//	sCh = UART_SetConfig(1,0,1,1,4,3,1,1,sBrate,1,4,2,7);
	UART_Open2(sCh);

	printf("Press any key when you ready to Rx/n");
	UART_Getc();


	printf("\nPress Enter when you complete to check Rx\n");	
	ucCnt = 0;

	while(!UART_GetKey())
		{
				if(!(UART_RdUFSTAT(sCh)&0x4000)) 		//if TX Fifo is not Full
//				if(UART_RdUTRSTAT(sCh)&0x4) 				//if TX Fifo empty
				{
					UART_WrUtxh(sCh,ucCnt);
					//printf("%d\b\b",ucCnt);
					//Delay(100);
					ucCnt++;
					if(ucCnt == 0xf)
						ucCnt=0;
					
				}
		}
	

	UART_Getc();

	UART_Close(sCh);
	Delay(10000);
	UART_InitDebugCh(0,115200);	
}


void Uart_SpeedPollingRx(void)
{
	s32 sCh;	
	s32 sBrate=0;
	u8 ucCnt;
	u32 ucCnt2;
	

	TxBufferInit();
	RxBufferClear();
	
	printf("Which channel do you want to check?\n");
	printf("[0 ~ 3] :");
	sCh = GetIntNum();
	if (sCh == -1)
		sCh = 1;
	else if (sCh == 0)
	{
	printf("Debug Channel will be channel 1\n");
	UART_InitDebugCh(1,115200);
	Delay(1000);
	}	

	printf("\n");

	printf("How much BaudRate do you want to use as a Rx?\n");
	printf("BaudRate (ex 9600, 115200[D], 921600) : ");
	sBrate = GetIntNum();
	if (sBrate == -1)
		sBrate = 115200;


	printf("\n[Uart channel %d SpeedPolling Rx Test]\n",sCh);	
	printf("Operate SpeedPolling Tx through the channel %d\n",sCh);


	sCh = UART_SetConfig(sCh,0,1,1,4,3,1,1,sBrate,1,3,1,1);		// Tx 16/ Rx 8 FIFO mode
//	UART_SetConfig(sCh,0,1,1,4,1,1,1,sBrate,1,1,1,1);		//PCLK
//	UART_SetConfig(sCh,0,1,1,4,3,1,1,sBrate,1,1,1,1);		//EPLL
//	sCh = UART_SetConfig(1,0,1,1,4,3,1,1,sBrate,1,4,2,7);
	UART_Open2(sCh);

	ucCnt = 0;
//	pUartRxStr=(u8 *)(UART_BUF+0x200000);
	UART_RdUrxh(sCh);

	while(!UART_GetKey()) 
		{
//			if((UART_RdUFSTAT(sCh)&0x40)) 		//if Rx Fifo is Full
			if(UART_RdUTRSTAT(sCh)&0x1) 				//receive buffer has data
			{

				if(ucCnt == UART_RdUrxh(sCh))	
					{
					//printf("%d\b\b",ucCnt);
					ucCnt++;
						if(ucCnt==0xf)
							{
							ucCnt=0;
							ucCnt2++;
							}
					}
				else
					{
					printf("Test is failed!!!\n");
					printf("Cnt = %d\n",ucCnt);
					printf("Cnt2 = %d",ucCnt2*15);
					break;
					}

			}
		}

/*
	while(1) 
		{
			if(UART_RdUTRSTAT(sCh)&0x1) 
			{

			*pUartRxStr = UART_RdUrxh(sCh);


				if(*pUartRxStr == '\r')
					break;

				
				pUartRxStr++;
			}
		}

	pUartRxStr =(u8 *)(UART_BUF+0x200000);
	while(1) 
		{
			printf("%c",*pUartRxStr);
			if(*pUartRxStr == '\r')
				break;
			
			pUartRxStr++;
		}



	printf("\nRx Done~ \n");
	printf("Press Enter key to see the result!\n");
	UART_Getc();

	uUART_RX_Index = 0 ;
	
	for ( uUART_RX_Index = 0 ; uUART_RX_Index < 10000 ; uUART_RX_Index++)
	{
		if ( ( *(pRef_Buffer1 + uUART_RX_Index) ) == ( *(pRef_Buffer2 + uUART_RX_Index ) ) )
		{
			printf("Good!\n");
			uGood++;
		}
		else
		{
			printf("Bad~~     %x\n", pRef_Buffer2 + uUART_RX_Index);
			uFail++;
		}
	}
*/
	printf( "\nPress any Key!\n");

	UART_Getc();

	UART_Close(sCh);
	Delay(10000);	
	UART_InitDebugCh(0,115200);
}

void TxBufferInit(void)
{
	u32 uCnt;
 	u32 *pRec_buf = (u32 *)UART_BUF; 
	
	for(uCnt=0;uCnt<10000;uCnt++)
	{
		*(pRec_buf+uCnt)=0x55555555;
	}
	*(pRec_buf+uCnt) = 0x0d;
	*(pRec_buf) = 0x01020304;
}


// File Name : Uart_IrDATx
// File Description : Check Uart IrDA Operation(SIR) through the channel 2
// Input : NONE
// Output : Txstrings which has got throught the channel 2
// Version : 0.1
void Uart_IrDATx(void)
{
	s8 sCh;	
//	u8 acTestPString[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890->UART Tx Polling test is good!!!!\r";
	static u8 acTestIString[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890->UART IrDA Tx test is good!!!!\r";
		
	printf("Which channel do you want to check?\n");
	printf("[0 ~ 3] :");
	sCh = GetIntNum();
	if (sCh == -1)
		sCh = 1;
	else if (sCh == 0)
	{
	printf("Debug Channel will be channel 1\n");
	UART_InitDebugCh(1,115200);
	Delay(1000);
	}	

	printf("\n");
	
	sCh = UART_SetConfig(sCh,0,1,1,4,1,2,2,115200,1,1,1,1);
	UART_Open2(sCh);

	printf("\n[Uart channel %d Tx Test]\n",sCh);	
	UART_TxString(sCh, acTestIString);
	printf("\nTx Done~ \n");	
		

        UART_Close(sCh);                                   
	Delay(10000);		
	UART_InitDebugCh(0,115200);
}

// File Name : Uart_IrDARx
// File Description : Check Uart IrDA Operation (SIR) through the channel 2
// Input : Type any character throught the channel 2
// Output : Rxstrings which has got throught the channel 2
// Version : 0.1
void Uart_IrDARx(void)
{
	s8 sCh;	
	
	printf("Which channel do you want to check?\n");
	printf("[0 ~ 3] :");
	sCh = GetIntNum();
	if (sCh == -1)
		sCh = 1;
	else if (sCh == 0)
	{
	printf("Debug Channel will be channel 1\n");
	UART_InitDebugCh(1,115200);
	Delay(1000);
	}	

	printf("\n");

	UART_SetConfig(sCh,0,1,1,4,1,2,2,115200,1,1,1,1);
	UART_Open2(sCh);


	printf("\nRx : %s \n",UART_RxString(sCh));
	printf("\nRx Done~ \n");

        UART_Close(sCh);                                    
	Delay(10000);		
	UART_InitDebugCh(0,115200);			
}


// File Name : Uart_SendBreak
// File Description : Check Uart SendBreak signal 
// Input : NONE
// Output : NONE
// Version : 0.1
void Uart_SendBreak(void)
{
	s32 sCh;
	u8 cKey;
	

	printf("Which channel do you want to check?\n");
	printf("[0 ~ 3] :");
	sCh = GetIntNum();
	if (sCh == -1)
		sCh = 1;
	else if (sCh == 0)
	{
	printf("Debug Channel will be channel 1\n");
	UART_InitDebugCh(1,115200);
	Delay(1000);	
	}	

	UART_SetConfig(sCh,0,1,1,4,1,1,1,115200,1,1,1,1);    //ch1, Interrupt, no FIFO
	UART_Open2(sCh);
	
	printf("Press any key then you can have a SendBreak signal through the channel %d, check it out!\n",sCh);	
	printf("If You enter 'x' , Test will be finished!\n");

	while(1)
		{

			cKey = UART_Getc();

			if ( cKey == 'x')
			{
				break;
			}

			UART_SendBreak(sCh);
		
		}

	UART_Close(sCh);
	Delay(10000);
	UART_InitDebugCh(0,115200);	
	printf("Debug channel changed\n");
	
}


// File Name : Uart_LoopBack
// File Description : Check Uart LoopBack mode 
// Input : NONE
// Output : NONE
// Version : 0.1
void Uart_LoopBack(void)
{
	u32 Txdone;
	u32 Rxdone;
	s32 sCh;
	volatile u8 *pUartRxStr;
	volatile u8* pTestLBString="ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890->UART Tx LoopBack test is good!!!\r";

	pUartRxStr=(u8 *)(UART_BUF+0x200000);
	RxBufferClear();

	
	printf("Which channel do you want to check?\n");
	printf("[0 ~ 3] :");
	sCh = GetIntNum();
	if (sCh == -1)
		sCh = 1;
	else if (sCh == 0)
	{
	printf("Debug Channel will be channel 1\n");
	UART_InitDebugCh(1,115200);
	Delay(1000);
	}	

	printf("\n");
	
	UART_SetConfig(sCh,2,1,1,4,1,1,1,115200,1,1,1,1);    //Interrupt, no FIFO
	UART_Open2(sCh);
	Delay(1000);

	Txdone = 1;
	Rxdone = 1;
	while(Txdone|Rxdone)
		{
		if(Txdone)
			{
				if(UART_RdUTRSTAT(sCh)&0x4) 
				{
				UART_WrUtxh(sCh,*pTestLBString);

					if(*pTestLBString == '\r') 
					Txdone = 0;

				pTestLBString++;
				}
			}

		if(Rxdone)
			{

				if(UART_RdUTRSTAT(sCh)&0x1) 
				{

				*pUartRxStr = UART_RdUrxh(sCh);


					if(*pUartRxStr == '\r')
						Rxdone = 0;

					
					pUartRxStr++;
				}
			}

		}


	pUartRxStr =(u8 *)(UART_BUF+0x200000);
	
	while(1) 
		{
			printf("%c",*pUartRxStr);
			if(*pUartRxStr == '\r')
				break;
			
			pUartRxStr++;
		}
	
	UART_Close(sCh);
	Delay(10000);
	UART_InitDebugCh(0,115200);	

}


// File Name : Uart_LoopBack
// File Description : Check Uart LoopBack mode 
// Input : NONE
// Output : NONE
// Version : 0.1
void Uart_LoopBackPerformance(void)

⌨️ 快捷键说明

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