oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
uart.h
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
34#include "ove/types.h"
35#include "ove_config.h"
36#include "ove/storage.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/* ── Enums ───────────────────────────────────────────────────────── */
43
44typedef enum {
45 OVE_UART_PARITY_NONE = 0,
46 OVE_UART_PARITY_ODD = 1,
47 OVE_UART_PARITY_EVEN = 2,
48} ove_uart_parity_t;
49
50typedef enum {
51 OVE_UART_STOP_1 = 0,
52 OVE_UART_STOP_1_5 = 1,
53 OVE_UART_STOP_2 = 2,
54} ove_uart_stop_t;
55
56typedef enum {
57 OVE_UART_FLOW_NONE = 0,
58 OVE_UART_FLOW_RTS_CTS = 1,
59} ove_uart_flow_t;
60
61/* ── Configuration ───────────────────────────────────────────────── */
62
67 unsigned int instance;
68 uint32_t baudrate;
69 uint8_t data_bits;
70 ove_uart_parity_t parity;
71 ove_uart_stop_t stop_bits;
72 ove_uart_flow_t flow_control;
73 size_t rx_buf_size;
74};
75
76#ifdef CONFIG_OVE_UART
77
78/* ── Lifecycle ───────────────────────────────────────────────────── */
79
89int ove_uart_init(ove_uart_t *uart, ove_uart_storage_t *storage,
90 void *rx_buf, const struct ove_uart_cfg *cfg);
91
92void ove_uart_deinit(ove_uart_t uart);
93
94#ifdef OVE_HEAP_UART
95int ove_uart_create(ove_uart_t *uart, const struct ove_uart_cfg *cfg);
96void ove_uart_destroy(ove_uart_t uart);
97#elif !defined(__ZIG_CIMPORT__)
98#define ove_uart_create(puart, cfg) \
99 ({ static ove_uart_storage_t _ove_stor_; \
100 static uint8_t _ove_buf_[(cfg)->rx_buf_size]; \
101 ove_uart_init((puart), &_ove_stor_, _ove_buf_, (cfg)); })
102#define ove_uart_destroy(uart) ove_uart_deinit(uart)
103#endif
104
105/* ── Operations ──────────────────────────────────────────────────── */
106
120int ove_uart_write(ove_uart_t uart, const void *data, size_t len,
121 uint32_t timeout_ms, size_t *bytes_written);
122
135int ove_uart_read(ove_uart_t uart, void *buf, size_t len,
136 uint32_t timeout_ms, size_t *bytes_read);
137
144size_t ove_uart_bytes_available(ove_uart_t uart);
145
154int ove_uart_flush(ove_uart_t uart);
155
156/* ── ISR helper (called by backend, not by application code) ─────── */
157
168void ove_uart_rx_isr_push(ove_uart_t uart, const void *data, size_t len);
169
170#else /* !CONFIG_OVE_UART */
171
172static inline int ove_uart_create(ove_uart_t *u, const struct ove_uart_cfg *c) { (void)u; (void)c; return OVE_ERR_NOT_SUPPORTED; }
173static inline void ove_uart_destroy(ove_uart_t u) { (void)u; }
174static inline int ove_uart_write(ove_uart_t u, const void *d, size_t l, uint32_t t, size_t *bw) { (void)u; (void)d; (void)l; (void)t; (void)bw; return OVE_ERR_NOT_SUPPORTED; }
175static inline int ove_uart_read(ove_uart_t u, void *b, size_t l, uint32_t t, size_t *br) { (void)u; (void)b; (void)l; (void)t; (void)br; return OVE_ERR_NOT_SUPPORTED; }
176static inline size_t ove_uart_bytes_available(ove_uart_t u) { (void)u; return 0; }
177static inline int ove_uart_flush(ove_uart_t u) { (void)u; return OVE_ERR_NOT_SUPPORTED; }
178static inline void ove_uart_rx_isr_push(ove_uart_t u, const void *d, size_t l) { (void)u; (void)d; (void)l; }
179
180#endif /* CONFIG_OVE_UART */
181
182#ifdef __cplusplus
183}
184#endif
185
188#endif /* OVE_UART_H */
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_uart * ove_uart_t
Opaque handle for a UART peripheral.
Definition types.h:136
UART configuration descriptor.
Definition uart.h:66
uint32_t baudrate
Definition uart.h:68
unsigned int instance
Definition uart.h:67
ove_uart_flow_t flow_control
Definition uart.h:72
size_t rx_buf_size
Definition uart.h:73
ove_uart_stop_t stop_bits
Definition uart.h:71
ove_uart_parity_t parity
Definition uart.h:70
uint8_t data_bits
Definition uart.h:69