|
oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
|
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. | |
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:
_create() / _destroy() — heap-allocated. Available only when OVE_HEAP_UART is defined (i.e. CONFIG_OVE_ZERO_HEAP is not set)._init() / _deinit() — caller-supplied storage and RX buffer. Available in both modes. See OVE_UART_DEFINE_STATIC for a one-step static helper.CONFIG_OVE_UART. | 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.
| [out] | uart | Receives the initialised UART handle. |
| [in] | storage | Pointer to statically-allocated UART storage. |
| [in] | rx_buf | Caller-supplied RX ring buffer. |
| [in] | cfg | UART configuration descriptor. |
| 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.
| [out] | uart | Receives the initialised handle. |
| [in] | cfg | UART configuration descriptor. |
| 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.
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.| [in] | uart | UART handle. |
| [in] | data | Data to transmit. |
| [in] | len | Number of bytes to write. |
| [in] | timeout_ns | Maximum wait time (best-effort; see note). |
| [out] | bytes_written | Actual bytes written (may be < len), or NULL. |
| 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.
| [in] | uart | UART handle. |
| [out] | buf | Buffer to receive data. |
| [in] | len | Maximum bytes to read. |
| [in] | timeout_ns | Maximum wait time. |
| [out] | bytes_read | Actual bytes read, or NULL. |
| size_t ove_uart_bytes_available | ( | ove_uart_t | uart | ) |
Query the number of bytes available in the RX buffer.
| [in] | uart | UART handle. |
| int ove_uart_flush | ( | ove_uart_t | uart | ) |
Flush the TX hardware buffer.
Blocks until all pending TX bytes have been physically transmitted.
| [in] | uart | UART handle. |
| 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.
| [in] | uart | UART handle. |
| [in] | data | Pointer to received byte(s). |
| [in] | len | Number of bytes received. |
| 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.
| [in] | uart | UART handle. |
| [in] | cb | Callback to invoke after each RX, or NULL. |
| [in] | user_data | Opaque pointer forwarded to cb. |