oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
UART

UART serial bus driver. More...

Data Structures

struct  ove_uart_cfg
 UART configuration descriptor. More...
 

Enumerations

enum  ove_uart_parity_t { OVE_UART_PARITY_NONE = 0 , OVE_UART_PARITY_ODD = 1 , OVE_UART_PARITY_EVEN = 2 }
 UART parity mode.
 
enum  ove_uart_stop_t { OVE_UART_STOP_1 = 0 , OVE_UART_STOP_1_5 = 1 , OVE_UART_STOP_2 = 2 }
 UART stop-bit count.
 
enum  ove_uart_flow_t { OVE_UART_FLOW_NONE = 0 , OVE_UART_FLOW_RTS_CTS = 1 }
 UART hardware flow control.
 

Functions

int ove_uart_init (ove_uart_t *uart, ove_uart_storage_t *storage, void *rx_buf, const struct ove_uart_cfg *cfg)
 Initialise a UART using caller-provided static storage.
 
void ove_uart_deinit (ove_uart_t uart)
 Release a UART handle previously created with ove_uart_init.
 
int ove_uart_create (ove_uart_t *uart, const struct ove_uart_cfg *cfg)
 Heap-mode counterpart of ove_uart_init() — allocates storage and RX buffer.
 
void ove_uart_destroy (ove_uart_t uart)
 Destroy a UART handle previously created with ove_uart_create.
 
int ove_uart_write (ove_uart_t uart, const void *data, size_t len, uint64_t timeout_ns, size_t *bytes_written)
 Write data to the UART.
 
int ove_uart_read (ove_uart_t uart, void *buf, size_t len, uint64_t timeout_ns, size_t *bytes_read)
 Read data from the UART RX buffer.
 
size_t ove_uart_bytes_available (ove_uart_t uart)
 Query the number of bytes available in the RX buffer.
 
int ove_uart_flush (ove_uart_t uart)
 Flush the TX hardware buffer.
 
void ove_uart_rx_isr_push (ove_uart_t uart, const void *data, size_t len)
 Push received bytes from ISR into the portable RX buffer.
 
int ove_uart_set_rx_notify (ove_uart_t uart, ove_notify_cb cb, void *user_data)
 Register a notify callback fired after every byte (or chunk) received into the RX buffer.
 

Detailed Description

UART serial bus driver.

Provides a portable, multi-instance UART API with configurable baud rate and framing, interrupt-driven RX buffering, thread-safe TX, and blocking read/write with timeout.

RX bytes are buffered internally via an Stream. Backend ISR handlers push received bytes through ove_uart_rx_isr_push() which the portable layer provides.

Two allocation strategies are supported:

Note
Requires CONFIG_OVE_UART.

Function Documentation

◆ ove_uart_init()

int ove_uart_init ( ove_uart_t uart,
ove_uart_storage_t *  storage,
void *  rx_buf,
const struct ove_uart_cfg cfg 
)

Initialise a UART using caller-provided static storage.

Parameters
[out]uartReceives the initialised UART handle.
[in]storagePointer to statically-allocated UART storage.
[in]rx_bufCaller-supplied RX ring buffer.
[in]cfgUART configuration descriptor.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_uart_create()

int ove_uart_create ( ove_uart_t uart,
const struct ove_uart_cfg cfg 
)

Heap-mode counterpart of ove_uart_init() — allocates storage and RX buffer.

Parameters
[out]uartReceives the initialised handle.
[in]cfgUART configuration descriptor.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_uart_write()

int ove_uart_write ( ove_uart_t  uart,
const void *  data,
size_t  len,
uint64_t  timeout_ns,
size_t *  bytes_written 
)

Write data to the UART.

Thread-safe (internal TX mutex). On success bytes_written holds the number of bytes actually accepted, which **may be less than len** on a short write — callers that require all bytes must check it and resubmit the remainder; OVE_OK alone does not guarantee a full write.

Note
timeout_ns is best-effort and is currently ignored by several backends (the posix/zephyr/freertos TX paths transmit synchronously); do not rely on it to bound a write.
Parameters
[in]uartUART handle.
[in]dataData to transmit.
[in]lenNumber of bytes to write.
[in]timeout_nsMaximum wait time (best-effort; see note).
[out]bytes_writtenActual bytes written (may be < len), or NULL.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_uart_read()

int ove_uart_read ( ove_uart_t  uart,
void *  buf,
size_t  len,
uint64_t  timeout_ns,
size_t *  bytes_read 
)

Read data from the UART RX buffer.

Blocks for up to timeout_ns until at least 1 byte is available.

Parameters
[in]uartUART handle.
[out]bufBuffer to receive data.
[in]lenMaximum bytes to read.
[in]timeout_nsMaximum wait time.
[out]bytes_readActual bytes read, or NULL.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_uart_bytes_available()

size_t ove_uart_bytes_available ( ove_uart_t  uart)

Query the number of bytes available in the RX buffer.

Parameters
[in]uartUART handle.
Returns
Number of bytes available, or 0 if empty or invalid.

◆ ove_uart_flush()

int ove_uart_flush ( ove_uart_t  uart)

Flush the TX hardware buffer.

Blocks until all pending TX bytes have been physically transmitted.

Parameters
[in]uartUART handle.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_uart_rx_isr_push()

void ove_uart_rx_isr_push ( ove_uart_t  uart,
const void *  data,
size_t  len 
)

Push received bytes from ISR into the portable RX buffer.

Backend UART ISR handlers call this function to deliver received bytes to the portable layer's internal Stream.

Parameters
[in]uartUART handle.
[in]dataPointer to received byte(s).
[in]lenNumber of bytes received.

◆ ove_uart_set_rx_notify()

int ove_uart_set_rx_notify ( ove_uart_t  uart,
ove_notify_cb  cb,
void *  user_data 
)

Register a notify callback fired after every byte (or chunk) received into the RX buffer.

Convenience delegate to ove_stream_set_notify on the UART's internal RX stream — exposes the wake hook without leaking the stream handle itself. Designed for the Rust binding's async Uart::read().await path, which registers an AtomicWaker::wake trampoline here.

The callback fires from whatever context the byte was pushed in — typically an ISR via ove_uart_rx_isr_push. Must be non-blocking and ISR-safe.

Parameters
[in]uartUART handle.
[in]cbCallback to invoke after each RX, or NULL.
[in]user_dataOpaque pointer forwarded to cb.
Returns
OVE_OK on success, negative error code on failure.