in lib/nxp/drivers/fsl_usart.c [457:509]
status_t USART_WriteBlocking(USART_Type *base, const uint8_t *data, size_t length)
{
/* Check arguments */
assert(!((NULL == base) || (NULL == data)));
#if UART_RETRY_TIMES
uint32_t waitTimes;
#endif
if ((NULL == base) || (NULL == data))
{
return kStatus_InvalidArgument;
}
/* Check whether txFIFO is enabled */
if (0U == (base->FIFOCFG & USART_FIFOCFG_ENABLETX_MASK))
{
return kStatus_InvalidArgument;
}
for (; length > 0U; length--)
{
/* Loop until txFIFO get some space for new data */
#if UART_RETRY_TIMES
waitTimes = UART_RETRY_TIMES;
while ((0U == (base->FIFOSTAT & USART_FIFOSTAT_TXNOTFULL_MASK)) && (--waitTimes != 0U))
#else
while (0U == (base->FIFOSTAT & USART_FIFOSTAT_TXNOTFULL_MASK))
#endif
{
}
#if UART_RETRY_TIMES
if (0U == waitTimes)
{
return kStatus_USART_Timeout;
}
#endif
base->FIFOWR = *data;
data++;
}
/* Wait to finish transfer */
#if UART_RETRY_TIMES
waitTimes = UART_RETRY_TIMES;
while ((0U == (base->STAT & USART_STAT_TXIDLE_MASK)) && (--waitTimes != 0U))
#else
while (0U == (base->STAT & USART_STAT_TXIDLE_MASK))
#endif
{
}
#if UART_RETRY_TIMES
if (0U == waitTimes)
{
return kStatus_USART_Timeout;
}
#endif
return kStatus_Success;
}