今天笔试题里面有一个关于UART驱动的伪代码实现,实在是没有仔细看过,直接拿来就用了
回来打开VDSP里面UART实现的源码分析了一下,学习学习
/******************************************************************* * Function: PutChar * Description: Writes a character to the UART. *******************************************************************/ int PutChar(const char cVal) { int nStatus = 0; unsigned int count = 0; do { if( (*pUART0LSR & UARTTHRE) ) { *pUART0THR = cVal; nStatus = 1; break; } count++; } while( count < 0x100000 ); return nStatus; }
/******************************************************************* * Function: GetChar * Description: Reads a character from the UART.hkcren.com *******************************************************************/ int GetChar(char *const cVal) { int nStatus = 0; unsigned int count = 0x0; do{ if( 1 /*UARTDR == (*pUART0LSR & UARTDR)*/ ) { *cVal = (char)*pUART0RBR; nStatus = 1; break; } /*count++;*/ }while( count < 0x100000 ); return nStatus; }
while(UARTflag) { if( 1 == GetChar( &Testputchar ) ) { if( 0 != Testputchar&&Testputchar==TST_CHAR[i]) { UARTflag=0; // DEBUG_STATEMENT( "\nUartGerChar" ); // DEBUG_PRINT("\nTestputchar is %c ",Testputchar); OK_number++; } else if( 'z' == Testputchar ) break; } }