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

📄 uart0.c

📁 YC2440_ADS1.2示例代码.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
    while( rUFSTAT0 & 0x7f )
    {
	*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(1);
    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");
     
   
    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 

    Uart_Printf("\nKeep the connection between PC[COM1 or COM2] and UART1 of SMDK2410!!! \n");
    Uart_Printf("Press any key to start Rx and then Star Tx....\n");
    Uart_TxEmpty(1);
    Uart_Getch();
  
    // Clear Int Pending and Unmask 
    rINTMSK=~(BIT_UART0);
    rINTSUBMSK=~(BIT_SUB_TXD0);
	
     while(!tx_end);

     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
    Uart_Printf("\nEnd Tx, transfer data count=%d\n",tx_cnt);
	

    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(1);
    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");
    
    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 

    
    Uart_Printf("\nKeep the connection between PC[COM1 or COM2] and UART0 of SMDK2410!!! \n");
    Uart_Printf("Press any key to start Rx and then Star Tx....\n");
    Uart_Getch();

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

    while(!rx_end);

  //  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
    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_Port_Return();
}


// added by junon start
void __irq Uart0_RxOverrunErr(void)
{
    rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
    if(rSUBSRCPND&BIT_SUB_ERR0) 
	{
		__sub_Uart0_RxErrInt();
    	ClearPending(BIT_UART0); 
	    rSUBSRCPND=(BIT_SUB_RXD0|BIT_SUB_ERR0);	// Clear Sub int pending    
		return;
    }
    rINTSUBMSK&=~(BIT_SUB_RXD0|BIT_SUB_ERR0);    
}


void Test_Uart0_RxErr(void) // need two serial port cables.
{
	U8 ch;
	U8 cError;
	
    Uart_Port_Set(); 
   
    Uart_Select(1);
    Uart_Printf("\nConnect PC[COM1 or COM2] and UART0 of SMDK2440 with a serial cable!!! \n");
    Uart_Printf("In this case, Uart0 : test port,  Uart1 : debug port\n");
    Uart_Printf("Then, press any key........\n");
//    Uart_Select(0);	// Change the uart port    
    Uart_Getch();
			
  	while(1)
	{
	    /*********** UART0 Rx test with interrupt ***********/
	    isRxInt=1;
	    uart0RxStr=(char *)UARTBUFFER;			
	    Uart_Printf("\n[Uart channel 0 Rx Error Check]\n");
	    Uart_TxEmpty(1); //wait until tx buffer is empty.

		rUFCON0=(1<<6)|(0<<4)|(1<<2)|(1<<1)|0; // FIFO disable

		// for 2440A. add Frame error, Parity error, Break detect check.
	    Uart_Printf("\n1. Overrun Error check[D]   2. Frame error   3. Parity error  \n"); 
		cError = Uart_Getch();
	    if (cError== '2')
		{
			pISR_UART0 =(unsigned)Uart0_RxIntOrErr;

			rULCON0=(0<<6)|(4<<3)|(0<<2)|(0); // Normal,No parity,One stop bit, 7bit
			rUCON0 = (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
			//Clock,Tx:pulse,Rx:pulse,Rx timeout:x,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int
			Uart_Printf("This port was set 7 data bit, no parity, 1 stop bit. Send just characters..\n");
	    }
		else if (cError== '3')
		{
			pISR_UART0 =(unsigned)Uart0_RxIntOrErr;
		
			rULCON0=(0<<6)|(5<<3)|(0<<2)|(3); // Normal,Even parity,One stop bit, 8bit
			rUCON0 = (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
			//Clock,Tx:pulse,Rx:pulse,Rx timeout:x,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int
			Uart_Printf("This port was set 8 data bit, even parity, 1 stop bit. Send just characters..\n");
		}
	    else 
		{
			pISR_UART0 = (unsigned)Uart0_RxOverrunErr;

			rULCON0=(0<<6)|(0<<3)|(0<<2)|(3); // Normal,No parity,One stop bit, 8bit
		    rUCON0 = (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
		    //Clock,Tx:pulse,Rx:pulse,Rx timeout:x,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int

			Uart_Printf("1. Using FIFO	2. Not using FIFO[D] \n");
			if (Uart_Getch() == '1') 
			{
				rUFCON0 |= 1;
				Uart_Printf("Press Any key as 65 times in UART0 terminal window..\n");
				Uart_Printf("then Overrun error will be occured.. \n"); 
			}
			else
			{
				rUFCON0 &= ~1;
				Uart_Printf("Press Any key as 2 times in UART0 terminal window..\n");
				Uart_Printf("then Overrun error will be occured.. \n");
			}
		}
		
	    // Clear Int Pending and Unmask    
	    rSUBSRCPND=(BIT_SUB_TXD0|BIT_SUB_RXD0|BIT_SUB_ERR0);    
	    ClearPending(BIT_UART0);
	    rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_ERR0);
	    rINTMSK=~(BIT_UART0);

	    while(isRxInt);

		// UART0 mask
    	rINTSUBMSK|=(BIT_SUB_TXD0|BIT_SUB_RXD0|BIT_SUB_ERR0);
		rINTMSK|=(BIT_UART0);

		rUFCON0 |= 3<<1; // fifo reset
		Uart_Printf("1. One more  2. Exit[D] \n");
		if (Uart_Getch() == '1') continue;
		else break;
	}	

    Uart_Port_Return();	
}

#if 0
void Enter_Uart0_ISR(void)
{
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	rINTMSK |= BIT_UART0;
	ClearPending(BIT_UART0);
	rSUBSRCPND=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);	
}

void Exit_Uart0_ISR(void)
{
	rINTSUBMSK&=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
	rINTMSK &= ~(BIT_UART0);
}

void __irq Uart0_Cts(void)
{
	Enter_Uart0_ISR();

	Exit_Uart0_ISR();	
}

void Test_Rts_Rx(void)
{
    int i = 1;

    Uart_Port_Set(); 
    //U32 safc_rGPHCON,safc_rGPHDAT,safc_rGPHUP;
    tx_cnt=0;
    Uart_Select(1);
    Uart_Printf("[Uart channel 0 CTS Rx Test]\n");
    Uart_Printf("Check nCTS0 signal with oscilloscope! \n");
	Uart_Printf("When FIFO nuber is 32, Active nRTS0... \n");
    
//    pISR_UART0=(unsigned) Uart0_Cts;

    rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
    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=(3<<6)|(3<<4)|(1<<2)|(1<<1)|(1);
    //Tx and Rx FIFO Trigger Level:32byte,Tx and Rx FIFO Reset,FIFO on
    rUMCON0=0x10;   // Enable Uart0 AFC 

//	rINTMSK&=~(BIT_UART0);
//	rINTSUBMSK&=~(BIT_SUB_RXD0);
	rINTMSK |= (BIT_UART0); 
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);

	while( Uart_Getch() != '\r');  // just press any key at 32 times..

	Uart_Printf("\nEnd Tx, transfer data count=%d\n",tx_cnt);

	Uart_Select(0);
    Uart_Port_Return();
}
#endif

void Test_Uart0_Temp(void)
{
	U8 ch;
	int iBaud;
	volatile char *cStartBuf;
	
    Uart_Port_Set(); 

    Uart_Select(1);    

	/******** For operating clock test *********/
	Uart_Printf("[Uart channel 0 Interrupt test]\n");
	Uart_Printf("Select operating clock 1. PCLK    2. UCLK     3. FCLK/n(D)  \nChoose : ");
	ch = Uart_Getch();	
	switch (ch)
	{
	case '1' :
		Uart_Pclk_En(0, 115200);
		break;
	case '2' :
		rMISCCR = rMISCCR & ~(7<<8) | (1<<10); // CLKOUT1 = PCLK
		Uart_Uextclk_En(0, 115200, Pclk);
		break;
	default :
		Uart_Printf("Type the baudrate and then change the same baudrate of host, too.\n");
		Uart_Printf("Baudrate (ex 9600, 115200, 921600[D]) : ");
		iBaud = Uart_GetIntNum();
		if (iBaud == -1) iBaud = 921600;
		Uart_Fclkn_En(0, iBaud);
		Uart_Getch();
		break;
	}

	/*********** UART0 Tx test with interrupt ***********/  
    isTxInt=1;
    uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890->UART0 Tx interrupt test is good!!!!\r\n";
	cStartBuf = uart0TxStr;
    Uart_Printf("[Uart channel 0 Tx Interrupt Test]\n");

    pISR_UART0=(unsigned)Uart0_TxInt;

    rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
    rUCON0 |= (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
    //Clock,Tx:Def,Rx:Def,Rx timeout:x,Rx error int:x,Loop-back:x,Send break:x,Tx:int,Rx:int
	Uart_Printf("BRDIV0 = 0x%x\n", rUBRDIV0);
	Uart_Printf("UCON0 = 0x%x\n", rUCON0);
	Uart_Printf("UCON1 = 0x%x\n", rUCON1);
	Uart_Printf("Press enter key to exit \n");

    Uart_TxEmpty(0); //wait until tx buffer is empty.
    rINTMSK&=~(BIT_UART0);
    rINTSUBMSK&=~(BIT_SUB_TXD0);

	
    while(1)
	{
		if (isTxInt==0)
		{
			uart0TxStr = cStartBuf;
			rINTMSK&=~(BIT_UART0);
			rINTSUBMSK&=~(BIT_SUB_TXD0|BIT_SUB_RXD0|BIT_SUB_ERR0);
			isTxInt=1;
		}
		if (Uart_GetKey()=='\r') break;		
   	}
    
    rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_ERR0);
    rINTMSK|=(BIT_UART0);
 
    Uart_Port_Return();
}

// junon end

//---------------------------------------UART0 test function-------------------------------------

⌨️ 快捷键说明

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