oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
stream.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
31#ifndef OVE_STREAM_H
32#define OVE_STREAM_H
33
34#include "ove/types.h"
35#include "ove_config.h"
36#include "ove/storage.h"
37#include "ove/time.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#ifdef CONFIG_OVE_STREAM
44
61int ove_stream_init(ove_stream_t *stream, ove_stream_storage_t *storage, void *buffer, size_t size,
62 size_t trigger);
63
75
90#ifdef OVE_HEAP_STREAM
91int ove_stream_create(ove_stream_t *stream, size_t size, size_t trigger);
92
103#endif /* OVE_HEAP_STREAM */
104
121int ove_stream_send(ove_stream_t stream, const void *data, size_t len, uint64_t timeout_ns,
122 size_t *bytes_sent);
123
141static inline int ove_stream_send_until(ove_stream_t stream, const void *data, size_t len,
142 uint64_t deadline_ns, size_t *bytes_sent)
143{
144 return ove_stream_send(stream, data, len, ove_time_deadline_to_timeout_ns(deadline_ns),
145 bytes_sent);
146}
147
165int ove_stream_receive(ove_stream_t stream, void *buf, size_t len, uint64_t timeout_ns,
166 size_t *bytes_received);
167
185static inline int ove_stream_receive_until(ove_stream_t stream, void *buf, size_t len,
186 uint64_t deadline_ns, size_t *bytes_received)
187{
188 return ove_stream_receive(stream, buf, len, ove_time_deadline_to_timeout_ns(deadline_ns),
189 bytes_received);
190}
191
205int ove_stream_send_from_isr(ove_stream_t stream, const void *data, size_t len, size_t *bytes_sent);
206
220int ove_stream_receive_from_isr(ove_stream_t stream, void *buf, size_t len, size_t *bytes_received);
221
233
243
266int ove_stream_set_notify(ove_stream_t stream, ove_notify_cb cb, void *user_data);
267
268#else /* !CONFIG_OVE_STREAM */
269
270/* P0-3: _init/_deinit stubs so OVE_STREAM_DEFINE_STATIC links cleanly when
271 * CONFIG_OVE_STREAM=n. */
272static inline int ove_stream_init(ove_stream_t *s, ove_stream_storage_t *st, void *b, size_t sz,
273 size_t t)
274{
275 (void)s;
276 (void)st;
277 (void)b;
278 (void)sz;
279 (void)t;
281}
282static inline void ove_stream_deinit(ove_stream_t s)
283{
284 (void)s;
285}
286
287static inline int ove_stream_create(ove_stream_t *s, size_t sz, size_t t)
288{
289 (void)s;
290 (void)sz;
291 (void)t;
293}
294static inline void ove_stream_destroy(ove_stream_t s)
295{
296 (void)s;
297}
298static inline int ove_stream_send(ove_stream_t s, const void *d, size_t l, uint64_t t, size_t *bs)
299{
300 (void)s;
301 (void)d;
302 (void)l;
303 (void)t;
304 (void)bs;
306}
307static inline int ove_stream_receive(ove_stream_t s, void *b, size_t l, uint64_t t, size_t *br)
308{
309 (void)s;
310 (void)b;
311 (void)l;
312 (void)t;
313 (void)br;
315}
316static inline int ove_stream_send_from_isr(ove_stream_t s, const void *d, size_t l, size_t *bs)
317{
318 (void)s;
319 (void)d;
320 (void)l;
321 (void)bs;
323}
324static inline int ove_stream_receive_from_isr(ove_stream_t s, void *b, size_t l, size_t *br)
325{
326 (void)s;
327 (void)b;
328 (void)l;
329 (void)br;
331}
332static inline int ove_stream_reset(ove_stream_t s)
333{
334 (void)s;
336}
337static inline size_t ove_stream_bytes_available(ove_stream_t s)
338{
339 (void)s;
340 return 0;
341}
342static inline int ove_stream_set_notify(ove_stream_t s, ove_notify_cb cb, void *ud)
343{
344 (void)s;
345 (void)cb;
346 (void)ud;
348}
349
350#endif /* CONFIG_OVE_STREAM */
351
352#ifdef __cplusplus
353}
354#endif
355
/* end of ove_stream group */
357
358#endif /* OVE_STREAM_H */
int ove_stream_init(ove_stream_t *stream, ove_stream_storage_t *storage, void *buffer, size_t size, size_t trigger)
Initialise a stream using caller-provided static storage.
int ove_stream_send(ove_stream_t stream, const void *data, size_t len, uint64_t timeout_ns, size_t *bytes_sent)
Send bytes into the stream from task context.
static int ove_stream_receive_until(ove_stream_t stream, void *buf, size_t len, uint64_t deadline_ns, size_t *bytes_received)
Deadline-based variant of ove_stream_receive.
Definition stream.h:185
int ove_stream_receive(ove_stream_t stream, void *buf, size_t len, uint64_t timeout_ns, size_t *bytes_received)
Receive bytes from the stream in task context.
int ove_stream_send_from_isr(ove_stream_t stream, const void *data, size_t len, size_t *bytes_sent)
Send bytes into the stream from an ISR.
void ove_stream_destroy(ove_stream_t stream)
Destroy a heap-allocated stream.
void ove_stream_deinit(ove_stream_t stream)
Deinitialise a statically-allocated stream.
size_t ove_stream_bytes_available(ove_stream_t stream)
Query the number of bytes currently available in the stream.
int ove_stream_create(ove_stream_t *stream, size_t size, size_t trigger)
Allocate and initialise a heap-backed stream.
int ove_stream_set_notify(ove_stream_t stream, ove_notify_cb cb, void *user_data)
Register a notify callback fired after every successful send.
int ove_stream_reset(ove_stream_t stream)
Discard all bytes currently held in the stream.
int ove_stream_receive_from_isr(ove_stream_t stream, void *buf, size_t len, size_t *bytes_received)
Receive bytes from the stream from an ISR.
static int ove_stream_send_until(ove_stream_t stream, const void *data, size_t len, uint64_t deadline_ns, size_t *bytes_sent)
Deadline-based variant of ove_stream_send.
Definition stream.h:141
static uint64_t ove_time_deadline_to_timeout_ns(uint64_t deadline_ns)
Convert a steady-clock deadline to a duration suitable for the existing timeout_ns-taking APIs.
Definition time.h:162
struct ove_stream * ove_stream_t
Opaque handle for a byte-stream (ring-buffer) object.
Definition types.h:232
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