oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
uart.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
9#ifndef OVE_UART_H
10#define OVE_UART_H
11
36#include "ove/types.h"
37#include "ove_config.h"
38#include "ove/storage.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* ── Enums ───────────────────────────────────────────────────────── */
45
47typedef enum {
48 OVE_UART_PARITY_NONE = 0,
49 OVE_UART_PARITY_ODD = 1,
50 OVE_UART_PARITY_EVEN = 2,
52
54typedef enum {
55 OVE_UART_STOP_1 = 0,
56 OVE_UART_STOP_1_5 = 1,
57 OVE_UART_STOP_2 = 2,
59
61typedef enum {
62 OVE_UART_FLOW_NONE = 0,
63 OVE_UART_FLOW_RTS_CTS = 1,
65
66/* ── Configuration ───────────────────────────────────────────────── */
67
80
81#ifdef CONFIG_OVE_UART
82
83/* ── Lifecycle ───────────────────────────────────────────────────── */
84
94int ove_uart_init(ove_uart_t *uart, ove_uart_storage_t *storage, void *rx_buf,
95 const struct ove_uart_cfg *cfg);
96
99
100#ifdef OVE_HEAP_UART
107int ove_uart_create(ove_uart_t *uart, const struct ove_uart_cfg *cfg);
110#endif /* OVE_HEAP_UART */
111
112/* ── Operations ──────────────────────────────────────────────────── */
113
133int ove_uart_write(ove_uart_t uart, const void *data, size_t len, uint64_t timeout_ns,
134 size_t *bytes_written);
135
148int ove_uart_read(ove_uart_t uart, void *buf, size_t len, uint64_t timeout_ns, size_t *bytes_read);
149
157
167
168/* ── ISR helper (called by backend, not by application code) ─────── */
169
180void ove_uart_rx_isr_push(ove_uart_t uart, const void *data, size_t len);
181
201int ove_uart_set_rx_notify(ove_uart_t uart, ove_notify_cb cb, void *user_data);
202
203#else /* !CONFIG_OVE_UART */
204
205/* No _init/_deinit stubs: OVE_UART_DEFINE_STATIC is itself gated by
206 * #ifdef CONFIG_OVE_UART in storage.h. */
207static inline int ove_uart_create(ove_uart_t *u, const struct ove_uart_cfg *c)
208{
209 (void)u;
210 (void)c;
212}
213static inline void ove_uart_destroy(ove_uart_t u)
214{
215 (void)u;
216}
217static inline int ove_uart_write(ove_uart_t u, const void *d, size_t l, uint64_t t, size_t *bw)
218{
219 (void)u;
220 (void)d;
221 (void)l;
222 (void)t;
223 (void)bw;
225}
226static inline int ove_uart_read(ove_uart_t u, void *b, size_t l, uint64_t t, size_t *br)
227{
228 (void)u;
229 (void)b;
230 (void)l;
231 (void)t;
232 (void)br;
234}
235static inline size_t ove_uart_bytes_available(ove_uart_t u)
236{
237 (void)u;
238 return 0;
239}
240static inline int ove_uart_set_rx_notify(ove_uart_t u, ove_notify_cb cb, void *ud)
241{
242 (void)u;
243 (void)cb;
244 (void)ud;
246}
247static inline int ove_uart_flush(ove_uart_t u)
248{
249 (void)u;
251}
252static inline void ove_uart_rx_isr_push(ove_uart_t u, const void *d, size_t l)
253{
254 (void)u;
255 (void)d;
256 (void)l;
257}
258
259#endif /* CONFIG_OVE_UART */
260
261#ifdef __cplusplus
262}
263#endif
264
267#endif /* OVE_UART_H */
struct ove_uart * ove_uart_t
Opaque handle for a UART peripheral.
Definition types.h:262
void(* ove_notify_cb)(void *user_data)
Notify-callback signature used by the _set_notify variants of the comm primitives (stream / queue / e...
Definition types.h:298
@ OVE_ERR_NOT_SUPPORTED
Definition types.h:98
size_t ove_uart_bytes_available(ove_uart_t uart)
Query the number of bytes available in the RX buffer.
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.
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.
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.
void ove_uart_destroy(ove_uart_t uart)
Destroy a UART handle previously created with ove_uart_create.
ove_uart_stop_t
UART stop-bit count.
Definition uart.h:54
int ove_uart_flush(ove_uart_t uart)
Flush the TX hardware buffer.
ove_uart_parity_t
UART parity mode.
Definition uart.h:47
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_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.
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.
ove_uart_flow_t
UART hardware flow control.
Definition uart.h:61
UART configuration descriptor.
Definition uart.h:71
uint32_t baudrate
Definition uart.h:73
unsigned int instance
Definition uart.h:72
ove_uart_flow_t flow_control
Definition uart.h:77
size_t rx_buf_size
Definition uart.h:78
ove_uart_stop_t stop_bits
Definition uart.h:76
ove_uart_parity_t parity
Definition uart.h:75
uint8_t data_bits
Definition uart.h:74