char UARTpeekBlocking(uint8_t UART) { // If there is data in the buffer return that if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Wait for data if the buffer is empty while (!rxQSize(UART)) flushReadFIFO(UART); // Return what was read without popping it from the queue return rxBuff[UART][rxBufferTail[UART]]; }
int UARTpeek(uint8_t UART) { // If there is data in the buffer return that if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Try flushing the hardware FIFO and see if we can get data from there flushReadFIFO(UART); if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // No data was found return -255; }
char UARTgetc(uint8_t UART) { // Wait for data if the buffer is empty while (!rxQSize(UART)) flushReadFIFO(UART); return (char)rxDequeue(UART); }
char UARTgetc(uint8_t UART) { if (!rxQSize(UART)) { // Disable interrupt to avoid possible race condition ROM_UARTIntDisable(UARTBASE[UART], UART_INT_RX); // Wait for data if the buffer is empty while (!rxQSize(UART)) flushReadFIFO(UART); // Return to the previous state ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); } return (char)rxDequeue(UART); }
// Called when UART RX FIFO has data in it static void flushReadFIFO(uint8_t UART) { // Read from the FIFO and place in the circular buffer in memory while (ROM_UARTCharsAvail(UARTBASE[UART])) { if (rxQSize(UART) < UART_BUFFSIZE - 1) rxEnqueue(UART, ROM_UARTCharGet(UARTBASE[UART])); else ROM_UARTCharGet(UARTBASE[UART]); } // If the circular queue is full, set the overflow flag and return if (rxQSize(UART) == UART_BUFFSIZE - 1) overflow |= bit8[UART]; // Clear the appropriate interrupt flag ROM_UARTIntClear(UARTBASE[UART], UART_INT_RX); }
char UARTpeekBlocking(uint8_t UART) { // If there is data in the buffer return that if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Disable interrupt to avoid possible race condition ROM_UARTIntDisable(UARTBASE[UART], UART_INT_RX); // Wait for data if the buffer is empty while (!rxQSize(UART)) flushReadFIFO(UART); // Return to the previous state ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); // Return what was read without popping it from the queue return rxBuff[UART][rxBufferTail[UART]]; }
int UARTpeek(uint8_t UART) { // If there is data in the buffer return that if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Disable interrupt to avoid possible race condition ROM_UARTIntDisable(UARTBASE[UART], UART_INT_RX); // Try flushing the hardware FIFO and see if we can get data from there flushReadFIFO(UART); if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Return to the previous state ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); // No data was found return -255; }
int16_t UARTgetBufferLevel(uint8_t UART) { flushReadFIFO(UART); return rxQSize(UART); }