Receive

Informative

How a channel receives data, using the mid-transfer trigger and streaming reception. Binding rules: CHI-UART-MUST-12CHI-UART-MUST-17 in Uart — Requirements.

Start a reception

static uint8 rxBuf[16];

/* notify only when the 16-byte buffer is full */
Uart_StartRxTransaction(0u, rxBuf, 16u, 0u);   /* channel, buffer, length>0, trigger */

Reception runs asynchronously into rxBuf. Keep the buffer valid until Uart_Callout_OnReception fires. The last parameter is additionalRxLenTrg (below).

Mid-transfer trigger (additionalRxLenTrg)

Set additionalRxLenTrg > 0 to also be notified before the buffer fills — handy to inspect a command header, then decide how much more to read:

/* notify at 4 bytes (header), and again when the 16-byte buffer is full */
Uart_StartRxTransaction(0u, rxBuf, 16u, 4u);

void Uart_Callout_OnReception(uint8 channelId, uint16 length)
{
    if (length == 4u) {
        /* header arrived; re-arm the trigger for the announced payload size */
        Uart_SetAdditionalRxLenTrg(channelId, payloadLen);
    }
}

If the buffer length is a multiple of the trigger and both fire at once, Uart_Callout_OnReception is called once. Uart_SetAdditionalRxLenTrg may be called only from within Uart_Callout_OnReception.

Streaming reception (no dropped bytes)

The driver does not stop the hardware when the buffer fills — so you can hand over the next buffer from inside the callout without losing incoming bytes:

void Uart_Callout_OnReception(uint8 channelId, uint16 length)
{
    /* keep receiving into a fresh buffer */
    Uart_StartRxTransaction(channelId, nextBuf, sizeof(nextBuf), 0u);
}

If you do not call Uart_StartRxTransaction in the callout, the driver stops reception after the callout returns.

Cancel a reception

Uart_CancelRxTransaction(0u);   /* stop HW reception now */

Use it to stop the streaming hardware explicitly — for example after interpreting a command chunk and deciding no more data is needed. It returns E_OK even if no reception was ongoing.

Note

On an RX error (including HW buffer overflow) the driver stops reception and reports it via LogM_Report at runtime-error level with UART_RTERR_RX / UART_RTERR_RX_OVERFLOW (CHI-UART-MUST-17).