/***************************************************************************** * * Description: * Non-blocking receive function. * * Params: * [in] pRxChar - Pointer to buffer where the received character shall * be placed. * * Return: * TRUE if character was received, else FALSE. * ****************************************************************************/ tU8 uart1GetChar(tU8 *pRxChar) { volatile tU32 cpsrReg; tU32 tmpTail; /* buffer is empty */ if(uart1RxHead == uart1RxTail) return FALSE; tmpTail = (uart1RxTail + 1) & RX_BUFFER_MASK; uart1RxTail = tmpTail; *pRxChar = uart1RxBuf[tmpTail]; //disable IRQ cpsrReg = disIrq(); uart1RxInBuff--; if(uart1RxInBuff == (RX_BUFFER_SIZE - RX_BUFFER_LIMIT)) { //pull RTS high = accept bytes from other side again UART1_MCR = 0x02; } //enable IRQ restoreIrq(cpsrReg); return TRUE; }
/***************************************************************************** * * Description: * Blocking output routine, i.e., the routine waits until the uart * buffer is free and then sends the character. * * Params: * [in] charToSend - The character to print (to uart #1) * ****************************************************************************/ void uart1SendChar(tU8 charToSend) { volatile tU32 cpsrReg; tU32 tmpHead; //calculate head index tmpHead = (uart1TxHead + 1) & TX_BUFFER_MASK; //wait for free space in buffer while(tmpHead == uart1TxTail) ; //disable IRQ cpsrReg = disIrq(); U1IER &= ~0x02; //disable TX IRQ //enable IRQ restoreIrq(cpsrReg); if(uart1TxRunning == TRUE) { uart1TxBuf[tmpHead] = charToSend; uart1TxHead = tmpHead; } else { uart1TxRunning = TRUE; U1THR = charToSend; } //disable IRQ cpsrReg = disIrq(); U1IER |= 0x02; //enable TX IRQ //enable IRQ restoreIrq(cpsrReg); }