/******************************************************************************* * Function Name: UART_1_SpiUartClearRxBuffer ******************************************************************************** * * Summary: * Clears the receive buffer and RX FIFO. * * Parameters: * None * * Return: * None * *******************************************************************************/ void UART_1_SpiUartClearRxBuffer(void) { #if(UART_1_INTERNAL_RX_SW_BUFFER_CONST) uint32 intSourceMask; #endif /* (UART_1_INTERNAL_RX_SW_BUFFER_CONST) */ #if(UART_1_CHECK_RX_SW_BUFFER) { intSourceMask = UART_1_SpiUartDisableIntRx(); UART_1_CLEAR_RX_FIFO; /* Flush RX software buffer */ UART_1_rxBufferHead = UART_1_rxBufferTail; UART_1_rxBufferOverflow = 0u; /* End RX transfer */ UART_1_ClearRxInterruptSource(UART_1_INTR_RX_ALL); UART_1_SpiUartEnableIntRx(intSourceMask); } #else { UART_1_CLEAR_RX_FIFO; } #endif }
/******************************************************************************* * Function Name: UART_1_UartGetByte ******************************************************************************** * * Summary: * Retrieves the next data element from the receive buffer, returns the received byte * and error condition. * - The RX software buffer is disabled: returns the data element retrieved from the RX FIFO. * Undefined data will be returned if the RX FIFO is empty. * - The RX software buffer is enabled: returns data element from the software receive * buffer. * * Parameters: * None * * Return: * Bits 15-8 contains status and bits 7-0 contains the next data element from * receive buffer. If the bits 15-8 are non-zero, an error has occurred. * *******************************************************************************/ uint32 UART_1_UartGetByte(void) { uint32 rxData; uint32 tmpStatus; uint32 intSourceMask; intSourceMask = UART_1_SpiUartDisableIntRx(); if(0u != UART_1_SpiUartGetRxBufferSize()) { /* * Enable interrupt to receive more bytes: at least one byte is in * buffer. */ UART_1_SpiUartEnableIntRx(intSourceMask); /* Get received byte */ rxData = UART_1_SpiUartReadRxData(); } else { /* * Read byte directly from RX FIFO: the underflow is raised in case * of empty. In other case the first received byte will be read. */ rxData = UART_1_RX_FIFO_RD_REG; /* * Enable interrupt to receive more bytes. * The RX_NOT_EMPTY interrupt is cleared by the interrupt routine in case * the byte was received and read above. */ UART_1_SpiUartEnableIntRx(intSourceMask); } /* Get and clear RX error mask */ tmpStatus = (UART_1_GetRxInterruptSource() & UART_1_INTR_RX_ERR); UART_1_ClearRxInterruptSource(UART_1_INTR_RX_ERR); /* * Put together data and error status: * MP mode and accept address: the 9th bit is set to notify mark. */ rxData |= ((uint32) (tmpStatus << 8u)); return(rxData); }