in lib/nxp/drivers/fsl_usart.c [527:601]
status_t USART_ReadBlocking(USART_Type *base, uint8_t *data, size_t length)
{
uint32_t statusFlag;
status_t status = kStatus_Success;
#if UART_RETRY_TIMES
uint32_t waitTimes;
#endif
/* check arguments */
assert(!((NULL == base) || (NULL == data)));
if ((NULL == base) || (NULL == data))
{
return kStatus_InvalidArgument;
}
/* Check whether rxFIFO is enabled */
if ((base->FIFOCFG & USART_FIFOCFG_ENABLERX_MASK) == 0U)
{
return kStatus_Fail;
}
for (; length > 0U; length--)
{
/* loop until rxFIFO have some data to read */
#if UART_RETRY_TIMES
waitTimes = UART_RETRY_TIMES;
while (((base->FIFOSTAT & USART_FIFOSTAT_RXNOTEMPTY_MASK) == 0U) && (--waitTimes != 0U))
#else
while ((base->FIFOSTAT & USART_FIFOSTAT_RXNOTEMPTY_MASK) == 0U)
#endif
{
}
#if UART_RETRY_TIMES
if (waitTimes == 0U)
{
status = kStatus_USART_Timeout;
break;
}
#endif
/* check rxFIFO statusFlag */
if ((base->FIFOSTAT & USART_FIFOSTAT_RXERR_MASK) != 0U)
{
base->FIFOCFG |= USART_FIFOCFG_EMPTYRX_MASK;
base->FIFOSTAT |= USART_FIFOSTAT_RXERR_MASK;
status = kStatus_USART_RxError;
break;
}
/* check receive statusFlag */
statusFlag = base->STAT;
/* Clear all status flags */
base->STAT |= statusFlag;
if ((statusFlag & USART_STAT_PARITYERRINT_MASK) != 0U)
{
status = kStatus_USART_ParityError;
}
if ((statusFlag & USART_STAT_FRAMERRINT_MASK) != 0U)
{
status = kStatus_USART_FramingError;
}
if ((statusFlag & USART_STAT_RXNOISEINT_MASK) != 0U)
{
status = kStatus_USART_NoiseError;
}
if (kStatus_Success == status)
{
*data = (uint8_t)base->FIFORD;
data++;
}
else
{
break;
}
}
return status;
}