Hi all,
I'm porting an existing code base from another MCU. The existing code uses a UartAccessSend(UART_INSTANCE_t uart_inst, uint8_t datum) function to send a single byte from a software fifo, and expects to called back by ISR to send another byte, if any. My current implementation of UartAccessSend() function is as follows:
--------
/* Get Tx transfer status */
tx_status = LPUART_DRV_GetTransmitStatus(uart_inst, &remaining_bytes);
if ((0U) == remaining_bytes)
{
/* Update Tx byte */
uart_inst_state[uart_index].tx_byte = datum;
/* Check Tx transfer status */
if (STATUS_BUSY == tx_status)
{
/* Transfer still running, just reset buffer for next byte */
LPUART_DRV_SetTxBuffer(uart_inst, &(uart_inst_state[uart_index].tx_byte), (1U));
}
else
{
/* Transfer has stopped, restart it */
LPUART_DRV_SendData(uart_inst, &(uart_inst_state[uart_index].tx_byte), (1U));
}
/* Report success to caller */
result = STATUS_OK;
}
--------
Also, my ISR callback function (for both buffer empty e transmission end events) includes:
--------
/* Get next datum from queue (but don't remove it from queue, yet) */
if (STATUS_OK == ByteFifoReadSingleByte(terminal_tx_queue, 0U, &datum))
{
/* Request IRQ driven transmission */
if (STATUS_OK == UartAccessSend(TERMINAL_UART_INSTANCE, datum))
{
/* If successfully requested transmission, remove datum from queue */
ByteFifoGetSingleByte(&terminal_tx_queue, NULL);
}
}
--------
With the code above, Tx works, as far as I insert a single byte at a time, into the fifo. If I queue several bytes at once, however, lpuart driver gets stuck in a IRQ deadloop and my registered callback is never called. What am I missing/doing wrong?
Best regards,
Joao
UPDATE:
Have just found what seems to be some kind of race condition.
Code gets stuck because LPUART_DRV_TxCompleteIrqHandler() does nothing, due to if (lpuartState->txSize == 0U) failure. So it seems that I'm sending the next character at the wrong time, somehow.
Since this is a 'end of tx' processing, I tried changing port speed to 9600, and that seems to mask the issue. So I guess I'm getting the 'end of tx' event while I'm still processing the 'buffer empty' irq.