oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
stream.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
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
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#ifdef CONFIG_OVE_STREAM
43
60 ove_stream_storage_t *storage,
61 void *buffer, size_t size, size_t trigger);
62
74
88#ifdef OVE_HEAP_STREAM
89int ove_stream_create(ove_stream_t *stream, size_t size,
90 size_t trigger);
91
102#elif !defined(__ZIG_CIMPORT__) /* !OVE_HEAP_STREAM — zero-heap mode */
103
104/* Unified macro — size must be a compile-time constant. */
105#define ove_stream_create(pstream, size, trigger) \
106 ({ static ove_stream_storage_t _ove_stor_; \
107 static uint8_t _ove_buf_[(size) + 1]; \
108 ove_stream_init((pstream), &_ove_stor_, _ove_buf_, \
109 (size), (trigger)); })
110#define ove_stream_destroy(stream) ove_stream_deinit(stream)
111
112#endif /* OVE_HEAP_STREAM */
113
130int ove_stream_send(ove_stream_t stream, const void *data,
131 size_t len, uint32_t timeout_ms,
132 size_t *bytes_sent);
133
151int ove_stream_receive(ove_stream_t stream, void *buf,
152 size_t len, uint32_t timeout_ms,
153 size_t *bytes_received);
154
169 const void *data, size_t len,
170 size_t *bytes_sent);
171
186 void *buf, size_t len,
187 size_t *bytes_received);
188
200
210
211#else /* !CONFIG_OVE_STREAM */
212
213static inline int ove_stream_create(ove_stream_t *s, size_t sz, size_t t) { (void)s; (void)sz; (void)t; return OVE_ERR_NOT_SUPPORTED; }
214static inline void ove_stream_destroy(ove_stream_t s) { (void)s; }
215static inline int ove_stream_send(ove_stream_t s, const void *d, size_t l, uint32_t t, size_t *bs) { (void)s; (void)d; (void)l; (void)t; (void)bs; return OVE_ERR_NOT_SUPPORTED; }
216static inline int ove_stream_receive(ove_stream_t s, void *b, size_t l, uint32_t t, size_t *br) { (void)s; (void)b; (void)l; (void)t; (void)br; return OVE_ERR_NOT_SUPPORTED; }
217static inline int ove_stream_send_from_isr(ove_stream_t s, const void *d, size_t l, size_t *bs) { (void)s; (void)d; (void)l; (void)bs; return OVE_ERR_NOT_SUPPORTED; }
218static inline int ove_stream_receive_from_isr(ove_stream_t s, void *b, size_t l, size_t *br) { (void)s; (void)b; (void)l; (void)br; return OVE_ERR_NOT_SUPPORTED; }
219static inline int ove_stream_reset(ove_stream_t s) { (void)s; return OVE_ERR_NOT_SUPPORTED; }
220static inline size_t ove_stream_bytes_available(ove_stream_t s) { (void)s; return 0; }
221
222#endif /* CONFIG_OVE_STREAM */
223
224#ifdef __cplusplus
225}
226#endif
227
/* end of ove_stream group */
229
230#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_receive(ove_stream_t stream, void *buf, size_t len, uint32_t timeout_ms, 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_send(ove_stream_t stream, const void *data, size_t len, uint32_t timeout_ms, size_t *bytes_sent)
Send bytes into the stream from task context.
int ove_stream_create(ove_stream_t *stream, size_t size, size_t trigger)
Allocate and initialise a heap-backed stream.
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.
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_stream * ove_stream_t
Opaque handle for a byte-stream (ring-buffer) object.
Definition types.h:106