?? uart0.c
字號:
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("\nThen 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=(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\n\n",uart0RxStr);
Uart_Port_Return();
}
volatile U32 *fifo_cnt; //temporary for fifo count test
volatile U32 fcnt = 0;
void __irq Uart0_TxFifo(void)
{
rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0); // Just for the safety
rINTMSK|=BIT_UART0;
rSUBSRCPND=BIT_SUB_TXD0; // Clear Sub int pending
ClearPending(BIT_UART0); // Clear master pending
*fifo_cnt++ = ++fcnt;
*fifo_cnt++ = rUFCON0;
*fifo_cnt++ = (rUFSTAT0>>8)&0x3f;
*fifo_cnt = 0;
while (!(rUFSTAT0 & 0x4000) && (*uart0TxStr != '\0')) //until tx fifo full or end of string
WrUTXH0(*uart0TxStr++);
if(*uart0TxStr != '\0')
{
rINTSUBMSK&=~(BIT_SUB_TXD0); // Unmask sub int
rINTMSK&=~(BIT_UART0);
}
}
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&0x7f) //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)
{
int i;
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.
Uart_Printf("Connect PC[COM1 or COM2] and UART0 of MBA2440 with a serial cable!!! \n");
Uart_Printf("Then, press any key........\n");
Uart_Select(0);
Uart_Getch();
fifo_cnt = (U32 *)_NONCACHE_STARTADDRESS; // temporary buffer
/* <Tx Trigger Level:empty> */
uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ->UART0 Tx FIFO interrupt(TL 48byte) 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=(3<<6)|(2<<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=(3<<6)|(2<<4)|(1<<2)|(1<<1)|(0);
// edited by junon
/* <Tx Trigger Level:16Byte> */
rUFCON0=(2<<6)|(2<<4)|(1<<2)|(1<<1)|(1);
uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ->UART0 Tx FIFO interrupt(TL 32byte) test is good!!!!\r\n";
rINTMSK=~(BIT_UART0);
rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
Delay(500);
/* <Tx Trigger Level:32Byte> */
rUFCON0=(1<<6)|(2<<4)|(1<<2)|(1<<1)|(1);
uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ->UART0 Tx FIFO interrupt(TL 16byte) test is good!!!!\r\n";
rINTMSK=~(BIT_UART0);
rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
Delay(500);
/* <Tx Trigger Level:48Byte> */
rUFCON0=(0<<6)|(2<<4)|(1<<2)|(1<<1)|(1);
uart0TxStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ->UART0 Tx FIFO interrupt(TL 0byte) test is good!!!!\r\n";
rINTMSK=~(BIT_UART0);
rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);
Delay(500);
rUFCON0=(0<<6)|(2<<4)|(1<<2)|(1<<1)|(0);
//Tx and Rx FIFO Trigger Level:48byte,Tx and Rx FIFO Reset,FIFO off
Uart_Printf("Saved FIFO current count in ISR!! Interrupt count : %d\n",fcnt);
fifo_cnt = (U32 *)_NONCACHE_STARTADDRESS;
while(*fifo_cnt)
Uart_Printf("[0x%x,%d,0x%x,%d] ", fifo_cnt, *fifo_cnt++, *fifo_cnt++,*fifo_cnt++);
fcnt = 0;
/******* UART0 Rx FIFO test with interrupt ********/
rx_dncs=0;
rx_point=0;
rx_isdone=1;
rx_filesize=0;
rx_checksum=0;
Uart_Printf("\n\n\n[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)|(2<<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");
Uart_Printf("Use DNW.. (Serial Port->Transmit menu)\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");
Uart_Printf("file size : 0x%x(%d)bytes[added header and checksum field].\n",
rx_filesize, rx_filesize);
}else{
Uart_Printf("\nError!!!\n");
}
Uart_Printf("\n\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 & 0x7f00); //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 & 0x7f )
{
*rxdataPt=rURXH0;
Uart_Printf("%d,",*rxdataPt++);
rx_cnt++;
}
if(rx_cnt == AFC_BUFLEN)
{
rx_end=1;
rINTMSK|=BIT_UART0;
}
}
/*****************************************************************
* for MODEM test
* This part is not tested
* If developer use this, You must do modified this source
*****************************************************************
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");
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 MBA2410!!! \n");
Uart_Printf("Press any key to start Rx and then Star Tx....\n");
Uart_TxEmpty(0);
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(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");
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 MBA2410!!! \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(0);
Uart_Printf("\nConnect PC[COM1 or COM2] and UART0 of MBA2440 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_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(0); //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();
}
//---------------------------------------UART0 test function-------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -