Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
uart_async_rx.h File Reference

Helper module for receiving using UART Asynchronous API. More...

#include <zephyr/kernel.h>

Go to the source code of this file.

Data Structures

struct  uart_async_rx_buf
 
struct  uart_async_rx
 UART asynchronous RX helper structure. More...
 
struct  uart_async_rx_config
 UART asynchronous RX helper configuration structure. More...
 

Macros

#define UART_ASYNC_RX_BUF_OVERHEAD   offsetof(struct uart_async_rx_buf, buffer)
 Get amount of space dedicated for managing each buffer state.
 

Functions

static uint8_t uart_async_rx_get_buf_len (struct uart_async_rx *async_rx)
 Get RX buffer length.
 
int uart_async_rx_init (struct uart_async_rx *async_rx, const struct uart_async_rx_config *config)
 Initialize the helper instance.
 
void uart_async_rx_reset (struct uart_async_rx *async_rx)
 Reset state of the helper instance.
 
void uart_async_rx_on_rdy (struct uart_async_rx *async_rx, uint8_t *buffer, size_t length)
 Indicate received data.
 
uint8_tuart_async_rx_buf_req (struct uart_async_rx *async_rx)
 Get next RX buffer.
 
void uart_async_rx_on_buf_rel (struct uart_async_rx *async_rx, uint8_t *buf)
 Indicate that buffer is no longer used by the UART driver.
 
size_t uart_async_rx_data_claim (struct uart_async_rx *async_rx, uint8_t **data, size_t length)
 Claim received data for processing.
 
bool uart_async_rx_data_consume (struct uart_async_rx *async_rx, size_t length)
 Consume claimed data.
 

Detailed Description

Helper module for receiving using UART Asynchronous API.

Macro Definition Documentation

◆ UART_ASYNC_RX_BUF_OVERHEAD

#define UART_ASYNC_RX_BUF_OVERHEAD   offsetof(struct uart_async_rx_buf, buffer)

Get amount of space dedicated for managing each buffer state.

User buffer provided during the initialization is split into chunks and each chunk has overhead. This overhead can be used to calculate actual space used for UART data.

Returns
Overhead space in bytes.

Function Documentation

◆ uart_async_rx_buf_req()

uint8_t * uart_async_rx_buf_req ( struct uart_async_rx async_rx)

Get next RX buffer.

Returned pointer shall be provided to uart_rx_buf_rsp or uart_rx_enable. If null is returned that indicates that there are no available buffers since all buffers are used by the driver or contain not consumed data.

Parameters
async_rxPointer to the helper instance.
Returns
Pointer to the next RX buffer or null if no buffer available.

◆ uart_async_rx_data_claim()

size_t uart_async_rx_data_claim ( struct uart_async_rx async_rx,
uint8_t **  data,
size_t  length 
)

Claim received data for processing.

Helper module works in the zero copy mode. It provides a pointer to the buffer that was directly used by the UART driver. Since received data is spread across multiple buffers there is no possibility to read all data at once. It can only be consumed in chunks. After data is processed, uart_async_rx_data_consume is used to indicate that data is consumed.

Parameters
async_rxPointer to the helper instance.
dataLocation where address to the buffer is written. Untouched if no data to claim.
lengthAmount of requested data.
Returns
Amount valid of data in the data buffer. 0 is returned when there is no data.

◆ uart_async_rx_data_consume()

bool uart_async_rx_data_consume ( struct uart_async_rx async_rx,
size_t  length 
)

Consume claimed data.

It pairs with uart_async_rx_data_claim.

Parameters
async_rxPointer to the helper instance.
lengthAmount of data to consume. It must be less or equal than amount of claimed data.
Return values
trueIf there are free buffers in the pool after data got consumed.
falseIf there are no free buffers.

◆ uart_async_rx_get_buf_len()

static uint8_t uart_async_rx_get_buf_len ( struct uart_async_rx async_rx)
inlinestatic

Get RX buffer length.

Parameters
async_rxPointer to the helper instance.
Returns
Buffer length.

◆ uart_async_rx_init()

int uart_async_rx_init ( struct uart_async_rx async_rx,
const struct uart_async_rx_config config 
)

Initialize the helper instance.

Parameters
async_rxPointer to the helper instance.
configConfiguration. Must be persistent.
Return values
0on successful initialization.

◆ uart_async_rx_on_buf_rel()

void uart_async_rx_on_buf_rel ( struct uart_async_rx async_rx,
uint8_t buf 
)

Indicate that buffer is no longer used by the UART driver.

Function shall be called on UART_RX_BUF_RELEASED event.

Parameters
async_rxPointer to the helper instance.
bufBuffer pointer received in the UART driver event.

◆ uart_async_rx_on_rdy()

void uart_async_rx_on_rdy ( struct uart_async_rx async_rx,
uint8_t buffer,
size_t  length 
)

Indicate received data.

Function shall be called from UART_RX_RDY context.

Parameters
async_rxPointer to the helper instance.
bufferBuffer received in the UART driver event.
lengthLength received in the UART driver event.

◆ uart_async_rx_reset()

void uart_async_rx_reset ( struct uart_async_rx async_rx)

Reset state of the helper instance.

Helper can be reset after RX abort to discard all received data and bring the helper to its initial state.

Parameters
async_rxPointer to the helper instance.