oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
storage.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_STORAGE_H
10#define OVE_STORAGE_H
11
86#include "ove/types.h"
87#include "ove_config.h"
88
89/*
90 * Include the backend-specific storage header.
91 *
92 * __BINDGEN__ — Rust bindgen: use exact build-time-generated sizes
93 * (required for zero-heap static allocation).
94 * __ZIG_CIMPORT__ — Zig @cImport: use minimal opaque types (Zig only
95 * passes pointer handles, never allocates storage).
96 *
97 * Without either flag, the real backend header is included.
98 */
99#if defined(__ZIG_CIMPORT__)
100/* Try to include build-time storage sizes for zero-heap mode.
101 * zig_storage_sizes.h is generated by ove_zig.cmake and placed
102 * on the include path only for zero-heap builds. */
103#if __has_include("zig_storage_sizes.h")
104#include "zig_storage_sizes.h"
105#endif
106#endif
107
108#if defined(__ZIG_CIMPORT__) && !defined(OVE_SIZEOF_OVE_THREAD_STORAGE)
109#ifdef CONFIG_OVE_ZERO_HEAP
110#error "Zero-heap mode requires storage sizes. Run cmake with ove_zig.cmake to generate zig_storage_sizes.h"
111#endif
112/* Zig heap mode: minimal opaques — only pointer handles are used,
113 * the C backend mallocs real storage. */
114#include <stdint.h>
116typedef struct {
117 uint8_t _opaque;
118} ove_mutex_storage_t;
119typedef struct {
120 uint8_t _opaque;
121} ove_sem_storage_t;
122typedef struct {
123 uint8_t _opaque;
124} ove_event_storage_t;
125typedef struct {
126 uint8_t _opaque;
127} ove_condvar_storage_t;
128typedef struct {
129 uint8_t _opaque;
130} ove_thread_storage_t;
131typedef struct {
132 uint8_t _opaque;
133} ove_queue_storage_t;
134typedef struct {
135 uint8_t _opaque;
136} ove_timer_storage_t;
137typedef struct {
138 uint8_t _opaque;
139} ove_eventgroup_storage_t;
140typedef struct {
141 uint8_t _opaque;
142} ove_workqueue_storage_t;
143typedef struct {
144 uint8_t _opaque;
145} ove_work_storage_t;
146typedef struct {
147 uint8_t _opaque;
148} ove_stream_storage_t;
149typedef struct {
150 uint8_t _opaque;
151} ove_watchdog_storage_t;
152typedef struct {
153 uint8_t _opaque;
154} ove_file_storage_t;
155typedef struct {
156 uint8_t _opaque;
157} ove_dir_storage_t;
158#ifdef CONFIG_OVE_INFER
159typedef struct {
160 uint8_t _opaque;
161} ove_model_storage_t;
162#endif
163#ifdef CONFIG_OVE_NET
164typedef struct {
165 uint8_t _opaque;
166} ove_socket_storage_t;
167typedef struct {
168 uint8_t _opaque;
169} ove_netif_storage_t;
170#endif
171#ifdef CONFIG_OVE_NET_TLS
172typedef struct {
173 uint8_t _opaque;
174} ove_tls_storage_t;
175#endif
176#ifdef CONFIG_OVE_NET_HTTP
177typedef struct {
178 uint8_t _opaque;
179} ove_http_client_storage_t;
180#endif
181#ifdef CONFIG_OVE_NET_MQTT
182typedef struct {
183 uint8_t _opaque;
184} ove_mqtt_client_storage_t;
185#endif
186#ifdef CONFIG_OVE_UART
187typedef struct {
188 uint8_t _opaque;
189} ove_uart_storage_t;
190#endif
191#ifdef CONFIG_OVE_SPI
192typedef struct {
193 uint8_t _opaque;
194} ove_spi_storage_t;
195#endif
196#ifdef CONFIG_OVE_I2C
197typedef struct {
198 uint8_t _opaque;
199} ove_i2c_storage_t;
200#endif
201#ifdef CONFIG_OVE_I2S
202typedef struct {
203 uint8_t _opaque;
204} ove_i2s_storage_t;
205#endif
207#elif defined(__ZIG_CIMPORT__) || defined(__BINDGEN__)
208/*
209 * Opaque storage types for Rust bindings.
210 *
211 * When OVE_STORAGE_SIZES is generated at build time (by
212 * ove_rust.cmake), exact per-backend sizes are used.
213 * Otherwise, conservative upper bounds cover all backends.
214 */
215#include <stdint.h>
216
223#define OVE_OPAQUE_(name, size, align) \
224 typedef struct { \
225 _Alignas(align) uint8_t _opaque[size]; \
226 } name
227
228/*
229 * Sizes are generated at build time by ove_rust.cmake and injected
230 * via storage_sizes.h (included by build.rs before this header).
231 * If the defines are missing, the build system is misconfigured.
232 */
233#ifndef OVE_SIZEOF_OVE_THREAD_STORAGE
234#error "Storage sizes not generated. Rust/Zig zero-heap builds require ove_{rust,zig}.cmake to produce storage sizes."
235#endif
236
238OVE_OPAQUE_(ove_mutex_storage_t, OVE_SIZEOF_OVE_MUTEX_STORAGE, OVE_ALIGNOF_OVE_MUTEX_STORAGE);
239OVE_OPAQUE_(ove_sem_storage_t, OVE_SIZEOF_OVE_SEM_STORAGE, OVE_ALIGNOF_OVE_SEM_STORAGE);
240OVE_OPAQUE_(ove_event_storage_t, OVE_SIZEOF_OVE_EVENT_STORAGE, OVE_ALIGNOF_OVE_EVENT_STORAGE);
241OVE_OPAQUE_(ove_condvar_storage_t, OVE_SIZEOF_OVE_CONDVAR_STORAGE, OVE_ALIGNOF_OVE_CONDVAR_STORAGE);
242OVE_OPAQUE_(ove_thread_storage_t, OVE_SIZEOF_OVE_THREAD_STORAGE, OVE_ALIGNOF_OVE_THREAD_STORAGE);
243OVE_OPAQUE_(ove_queue_storage_t, OVE_SIZEOF_OVE_QUEUE_STORAGE, OVE_ALIGNOF_OVE_QUEUE_STORAGE);
244OVE_OPAQUE_(ove_timer_storage_t, OVE_SIZEOF_OVE_TIMER_STORAGE, OVE_ALIGNOF_OVE_TIMER_STORAGE);
245OVE_OPAQUE_(ove_eventgroup_storage_t, OVE_SIZEOF_OVE_EVENTGROUP_STORAGE,
246 OVE_ALIGNOF_OVE_EVENTGROUP_STORAGE);
247OVE_OPAQUE_(ove_workqueue_storage_t, OVE_SIZEOF_OVE_WORKQUEUE_STORAGE,
248 OVE_ALIGNOF_OVE_WORKQUEUE_STORAGE);
249OVE_OPAQUE_(ove_work_storage_t, OVE_SIZEOF_OVE_WORK_STORAGE, OVE_ALIGNOF_OVE_WORK_STORAGE);
250OVE_OPAQUE_(ove_stream_storage_t, OVE_SIZEOF_OVE_STREAM_STORAGE, OVE_ALIGNOF_OVE_STREAM_STORAGE);
251OVE_OPAQUE_(ove_watchdog_storage_t, OVE_SIZEOF_OVE_WATCHDOG_STORAGE,
252 OVE_ALIGNOF_OVE_WATCHDOG_STORAGE);
253OVE_OPAQUE_(ove_file_storage_t, OVE_SIZEOF_OVE_FILE_STORAGE, OVE_ALIGNOF_OVE_FILE_STORAGE);
254OVE_OPAQUE_(ove_dir_storage_t, OVE_SIZEOF_OVE_DIR_STORAGE, OVE_ALIGNOF_OVE_DIR_STORAGE);
255#if defined(CONFIG_OVE_INFER) && defined(OVE_SIZEOF_OVE_MODEL_STORAGE)
256OVE_OPAQUE_(ove_model_storage_t, OVE_SIZEOF_OVE_MODEL_STORAGE, OVE_ALIGNOF_OVE_MODEL_STORAGE);
257#endif
258#if defined(CONFIG_OVE_NET) && defined(OVE_SIZEOF_OVE_SOCKET_STORAGE)
259OVE_OPAQUE_(ove_socket_storage_t, OVE_SIZEOF_OVE_SOCKET_STORAGE, OVE_ALIGNOF_OVE_SOCKET_STORAGE);
260OVE_OPAQUE_(ove_netif_storage_t, OVE_SIZEOF_OVE_NETIF_STORAGE, OVE_ALIGNOF_OVE_NETIF_STORAGE);
261#endif
262#if defined(CONFIG_OVE_NET_TLS) && defined(OVE_SIZEOF_OVE_TLS_STORAGE)
263OVE_OPAQUE_(ove_tls_storage_t, OVE_SIZEOF_OVE_TLS_STORAGE, OVE_ALIGNOF_OVE_TLS_STORAGE);
264#endif
265#if defined(CONFIG_OVE_NET_HTTP) && defined(OVE_SIZEOF_OVE_HTTP_CLIENT_STORAGE)
266OVE_OPAQUE_(ove_http_client_storage_t, OVE_SIZEOF_OVE_HTTP_CLIENT_STORAGE,
267 OVE_ALIGNOF_OVE_HTTP_CLIENT_STORAGE);
268#endif
269#if defined(CONFIG_OVE_NET_MQTT) && defined(OVE_SIZEOF_OVE_MQTT_CLIENT_STORAGE)
270OVE_OPAQUE_(ove_mqtt_client_storage_t, OVE_SIZEOF_OVE_MQTT_CLIENT_STORAGE,
271 OVE_ALIGNOF_OVE_MQTT_CLIENT_STORAGE);
272#endif
273#if defined(CONFIG_OVE_UART) && defined(OVE_SIZEOF_OVE_UART_STORAGE)
274OVE_OPAQUE_(ove_uart_storage_t, OVE_SIZEOF_OVE_UART_STORAGE, OVE_ALIGNOF_OVE_UART_STORAGE);
275#endif
276#if defined(CONFIG_OVE_SPI) && defined(OVE_SIZEOF_OVE_SPI_STORAGE)
277OVE_OPAQUE_(ove_spi_storage_t, OVE_SIZEOF_OVE_SPI_STORAGE, OVE_ALIGNOF_OVE_SPI_STORAGE);
278#endif
279#if defined(CONFIG_OVE_I2C) && defined(OVE_SIZEOF_OVE_I2C_STORAGE)
280OVE_OPAQUE_(ove_i2c_storage_t, OVE_SIZEOF_OVE_I2C_STORAGE, OVE_ALIGNOF_OVE_I2C_STORAGE);
281#endif
282#if defined(CONFIG_OVE_I2S) && defined(OVE_SIZEOF_OVE_I2S_STORAGE)
283OVE_OPAQUE_(ove_i2s_storage_t, OVE_SIZEOF_OVE_I2S_STORAGE, OVE_ALIGNOF_OVE_I2S_STORAGE);
284#endif
287#undef OVE_OPAQUE_
288#else
289#if defined(CONFIG_OVE_RTOS_FREERTOS)
290#include "ove_storage_freertos.h"
291#elif defined(CONFIG_OVE_RTOS_ZEPHYR)
292#include "ove_storage_zephyr.h"
293#elif defined(CONFIG_OVE_RTOS_NUTTX)
294#include "ove_storage_nuttx.h"
295#elif defined(CONFIG_OVE_RTOS_POSIX)
296#if defined(CONFIG_OVE_BOARD_WASM)
297#include "ove_storage_wasm.h"
298#else
299#include "ove_storage_posix.h"
300#endif
301#endif
302#endif /* __BINDGEN__ */
303
318#if !defined(CONFIG_OVE_ZERO_HEAP)
319#define OVE_HEAP_SYNC 1
320#define OVE_HEAP_THREAD 1
321#define OVE_HEAP_QUEUE 1
322#define OVE_HEAP_TIMER 1
323#define OVE_HEAP_EVENTGROUP 1
324#define OVE_HEAP_WORKQUEUE 1
325#define OVE_HEAP_STREAM 1
326#define OVE_HEAP_WATCHDOG 1
327#define OVE_HEAP_FS 1
328#define OVE_HEAP_AUDIO 1
329#define OVE_HEAP_INFER 1
330#define OVE_HEAP_NET 1
331#define OVE_HEAP_NET_TLS 1
332#define OVE_HEAP_NET_HTTP 1
333#define OVE_HEAP_NET_MQTT 1
334#define OVE_HEAP_UART 1
335#define OVE_HEAP_SPI 1
336#define OVE_HEAP_I2C 1
337#define OVE_HEAP_I2S 1
338#endif /* !CONFIG_OVE_ZERO_HEAP */
348#include <assert.h>
349
350#ifndef OVE_STATIC_INIT_ASSERT
351#define OVE_STATIC_INIT_ASSERT(cond) assert(cond)
352#endif
353
373#define OVE_MUTEX_DEFINE(name) static ove_mutex_storage_t name
374
378#define OVE_SEM_DEFINE(name) static ove_sem_storage_t name
379
383#define OVE_EVENT_DEFINE(name) static ove_event_storage_t name
384
388#define OVE_CONDVAR_DEFINE(name) static ove_condvar_storage_t name
389
390/* Backend-specific thread stack definition (Zephyr needs K_THREAD_STACK_DEFINE) */
391#ifndef OVE_THREAD_STACK_DEFINE_
403#define OVE_THREAD_STACK_DEFINE_(name, size) static uint8_t __attribute__((aligned(8))) name[(size)]
404#endif
405
406/* File-static variant of the above — for stacks that need internal linkage
407 * (e.g. test framework stacks reused under the same symbol name across
408 * multiple TUs). Includes aligned(8) explicitly since the generic
409 * OVE_THREAD_STACK_DEFINE_ doesn't, and AAPCS requires 8-byte alignment
410 * for the stack pointer at function-call boundaries. Zephyr overrides
411 * this to pin 'static' onto K_THREAD_STACK_DEFINE since
412 * K_THREAD_STACK_DEFINE itself has external linkage. */
413#ifndef OVE_THREAD_STACK_DEFINE_STATIC_
414#define OVE_THREAD_STACK_DEFINE_STATIC_(name, size) \
415 static uint8_t __attribute__((aligned(8))) name[(size)]
416#endif
417
419/* Block-scope static variant — safe inside ({...}) statement expressions. */
420#ifndef OVE_THREAD_STACK_BLOCK_STATIC_
421#define OVE_THREAD_STACK_BLOCK_STATIC_(name, size) \
422 static uint8_t __attribute__((aligned(8))) name[(size)]
423#endif
426/* Class-member variant (no 'static') — for C++ class-embedded stacks.
427 * Overridden by backends that need special alignment (e.g. Zephyr MPU). */
428#ifndef OVE_THREAD_STACK_MEMBER_
442#define OVE_THREAD_STACK_MEMBER_(name, size) uint8_t __attribute__((aligned(8))) name[size]
443#endif
444
451#define OVE_THREAD_DEFINE(name, stack_size_bytes) \
452 static ove_thread_storage_t name; \
453 OVE_THREAD_STACK_DEFINE_(name##_stack, stack_size_bytes)
454
462#define OVE_QUEUE_DEFINE(name, item_sz, max) \
463 static ove_queue_storage_t name; \
464 static uint8_t name##_buffer[(item_sz) * (max)]
465
469#define OVE_TIMER_DEFINE(name) static ove_timer_storage_t name
470
474#define OVE_EVENTGROUP_DEFINE(name) static ove_eventgroup_storage_t name
475
482#define OVE_WORKQUEUE_DEFINE(name, stack_size_bytes) \
483 static ove_workqueue_storage_t name; \
484 OVE_THREAD_STACK_DEFINE_(name##_stack, stack_size_bytes)
485
492#define OVE_STREAM_DEFINE(name, buf_size) \
493 static ove_stream_storage_t name; \
494 static uint8_t name##_buffer[(buf_size) + 1]
495
499#define OVE_WATCHDOG_DEFINE(name) static ove_watchdog_storage_t name
500
501#ifdef CONFIG_OVE_INFER
505#define OVE_MODEL_DEFINE(name) static ove_model_storage_t name
506
510#define OVE_MODEL_ARENA_DEFINE(name, size) static uint8_t __attribute__((aligned(16))) name[(size)]
511#endif /* CONFIG_OVE_INFER */
512
513#ifdef CONFIG_OVE_UART
520#define OVE_UART_DEFINE(name, rx_buf_size) \
521 static ove_uart_storage_t name; \
522 static uint8_t name##_rx_buf[(rx_buf_size)]
523#endif /* CONFIG_OVE_UART */
524
525#ifdef CONFIG_OVE_SPI
529#define OVE_SPI_DEFINE(name) static ove_spi_storage_t name
530#endif /* CONFIG_OVE_SPI */
531
532#ifdef CONFIG_OVE_I2C
536#define OVE_I2C_DEFINE(name) static ove_i2c_storage_t name
537#endif /* CONFIG_OVE_I2C */
538
539#ifdef CONFIG_OVE_I2S
546#define OVE_I2S_DEFINE(name) static ove_i2s_storage_t name
547#endif /* CONFIG_OVE_I2S */
548
/* ove_storage_define */
550
574/* Helper: constructor preamble */
575#define OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
576 __attribute__((used)) static void __attribute__((constructor)) _##name##_ctor(void) \
577 {
578#define OVE_DEFINE_STATIC_CTOR_END_(name) \
579 OVE_STATIC_INIT_ASSERT(_err == OVE_OK); \
580 }
583/* ── Static storage + _init() — works in both heap and zero-heap modes ─ */
584
590#define OVE_MUTEX_DEFINE_STATIC(name) \
591 static ove_mutex_storage_t _##name##_storage; \
592 static ove_mutex_t name; \
593 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
594 int _err = ove_mutex_init(&name, &_##name##_storage); \
595 OVE_DEFINE_STATIC_CTOR_END_(name)
596
602#define OVE_RECURSIVE_MUTEX_DEFINE_STATIC(name) \
603 static ove_mutex_storage_t _##name##_storage; \
604 static ove_mutex_t name; \
605 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
606 int _err = ove_recursive_mutex_init(&name, &_##name##_storage); \
607 OVE_DEFINE_STATIC_CTOR_END_(name)
608
616#define OVE_SEM_DEFINE_STATIC(name, initial, max) \
617 static ove_sem_storage_t _##name##_storage; \
618 static ove_sem_t name; \
619 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
620 int _err = ove_sem_init(&name, &_##name##_storage, (initial), (max)); \
621 OVE_DEFINE_STATIC_CTOR_END_(name)
622
628#define OVE_EVENT_DEFINE_STATIC(name) \
629 static ove_event_storage_t _##name##_storage; \
630 static ove_event_t name; \
631 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
632 int _err = ove_event_init(&name, &_##name##_storage); \
633 OVE_DEFINE_STATIC_CTOR_END_(name)
634
640#define OVE_CONDVAR_DEFINE_STATIC(name) \
641 static ove_condvar_storage_t _##name##_storage; \
642 static ove_condvar_t name; \
643 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
644 int _err = ove_condvar_init(&name, &_##name##_storage); \
645 OVE_DEFINE_STATIC_CTOR_END_(name)
646
657#define OVE_THREAD_DEFINE_STATIC(hname, stack_sz, fn, ctx, prio, tname) \
658 static ove_thread_storage_t _##hname##_storage; \
659 OVE_THREAD_STACK_DEFINE_(_##hname##_stack, stack_sz); \
660 static ove_thread_t hname; \
661 OVE_DEFINE_STATIC_CTOR_BEGIN_(hname) \
662 int _err = ove_thread_init(&hname, &_##hname##_storage, (tname), (fn), (ctx), (prio), \
663 (stack_sz), _##hname##_stack); \
664 OVE_DEFINE_STATIC_CTOR_END_(hname)
665
673#define OVE_QUEUE_DEFINE_STATIC(name, item_sz, max) \
674 static ove_queue_storage_t _##name##_storage; \
675 static uint8_t _##name##_buf[(item_sz) * (max)]; \
676 static ove_queue_t name; \
677 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
678 int _err = ove_queue_init(&name, &_##name##_storage, _##name##_buf, (item_sz), (max)); \
679 OVE_DEFINE_STATIC_CTOR_END_(name)
680
690#define OVE_TIMER_DEFINE_STATIC(name, cb, user_data, period_ms, one_shot) \
691 static ove_timer_storage_t _##name##_storage; \
692 static ove_timer_t name; \
693 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
694 int _err = ove_timer_init(&name, &_##name##_storage, (cb), (user_data), (period_ms), \
695 (one_shot)); \
696 OVE_DEFINE_STATIC_CTOR_END_(name)
697
703#define OVE_EVENTGROUP_DEFINE_STATIC(name) \
704 static ove_eventgroup_storage_t _##name##_storage; \
705 static ove_eventgroup_t name; \
706 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
707 int _err = ove_eventgroup_init(&name, &_##name##_storage); \
708 OVE_DEFINE_STATIC_CTOR_END_(name)
709
718#define OVE_WORKQUEUE_DEFINE_STATIC(name, stack_sz, wq_name, prio) \
719 static ove_workqueue_storage_t _##name##_storage; \
720 OVE_THREAD_STACK_DEFINE_(_##name##_stack, (stack_sz)); \
721 static ove_workqueue_t name; \
722 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
723 int _err = ove_workqueue_init(&name, &_##name##_storage, (wq_name), (prio), (stack_sz), \
724 _##name##_stack); \
725 OVE_DEFINE_STATIC_CTOR_END_(name)
726
733#define OVE_WORK_DEFINE_STATIC(name, handler) \
734 static ove_work_storage_t _##name##_storage; \
735 static ove_work_t name; \
736 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
737 int _err = ove_work_init_static(&name, &_##name##_storage, (handler)); \
738 OVE_DEFINE_STATIC_CTOR_END_(name)
739
747#define OVE_STREAM_DEFINE_STATIC(name, buf_sz, trigger) \
748 static ove_stream_storage_t _##name##_storage; \
749 static uint8_t _##name##_buf[(buf_sz) + 1]; \
750 static ove_stream_t name; \
751 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
752 int _err = ove_stream_init(&name, &_##name##_storage, _##name##_buf, (buf_sz), (trigger)); \
753 OVE_DEFINE_STATIC_CTOR_END_(name)
754
761#define OVE_WATCHDOG_DEFINE_STATIC(name, timeout_ms) \
762 static ove_watchdog_storage_t _##name##_storage; \
763 static ove_watchdog_t name; \
764 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
765 int _err = ove_watchdog_init(&name, &_##name##_storage, (timeout_ms)); \
766 OVE_DEFINE_STATIC_CTOR_END_(name)
767
768#ifdef CONFIG_OVE_INFER
777#define OVE_MODEL_DEFINE_STATIC(name, model_ptr, model_sz, arena_sz) \
778 static ove_model_storage_t _##name##_storage; \
779 static uint8_t __attribute__((aligned(16))) _##name##_arena[(arena_sz)]; \
780 static ove_model_t name; \
781 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
782 struct ove_model_config _cfg = { \
783 .model_data = (model_ptr), \
784 .model_size = (model_sz), \
785 .arena_size = (arena_sz), \
786 }; \
787 int _err = ove_model_init(&name, &_##name##_storage, _##name##_arena, &_cfg); \
788 OVE_DEFINE_STATIC_CTOR_END_(name)
789#endif /* CONFIG_OVE_INFER */
790
791#ifdef CONFIG_OVE_I2C
799#define OVE_I2C_DEFINE_STATIC(name, inst, spd) \
800 static ove_i2c_storage_t _##name##_storage; \
801 static ove_i2c_t name; \
802 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
803 struct ove_i2c_cfg _cfg = { \
804 .instance = (inst), \
805 .speed = (spd), \
806 }; \
807 int _err = ove_i2c_init(&name, &_##name##_storage, &_cfg); \
808 OVE_DEFINE_STATIC_CTOR_END_(name)
809#endif /* CONFIG_OVE_I2C */
810
811#ifdef CONFIG_OVE_SPI
818#define OVE_SPI_DEFINE_STATIC(name, cfg_ptr) \
819 static ove_spi_storage_t _##name##_storage; \
820 static ove_spi_t name; \
821 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
822 int _err = ove_spi_init(&name, &_##name##_storage, (cfg_ptr)); \
823 OVE_DEFINE_STATIC_CTOR_END_(name)
824#endif /* CONFIG_OVE_SPI */
825
826#ifdef CONFIG_OVE_UART
834#define OVE_UART_DEFINE_STATIC(name, rx_buf_sz, cfg_ptr) \
835 static ove_uart_storage_t _##name##_storage; \
836 static uint8_t _##name##_rx_buf[(rx_buf_sz)]; \
837 static ove_uart_t name; \
838 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
839 int _err = ove_uart_init(&name, &_##name##_storage, _##name##_rx_buf, (cfg_ptr)); \
840 OVE_DEFINE_STATIC_CTOR_END_(name)
841#endif /* CONFIG_OVE_UART */
842
843#ifdef CONFIG_OVE_I2S
862#define OVE_I2S_DEFINE_STATIC(name, tx_dma_bytes, rx_dma_bytes, cfg_ptr) \
863 static ove_i2s_storage_t _##name##_storage; \
864 static uint8_t __attribute__((aligned(4))) _##name##_tx_buf[(tx_dma_bytes)]; \
865 static uint8_t __attribute__((aligned(4))) _##name##_rx_buf[(rx_dma_bytes)]; \
866 static ove_i2s_t name; \
867 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
868 int _err = ove_i2s_init(&name, &_##name##_storage, _##name##_tx_buf, _##name##_rx_buf, \
869 (cfg_ptr)); \
870 OVE_DEFINE_STATIC_CTOR_END_(name)
871#endif /* CONFIG_OVE_I2S */
872
873#ifdef CONFIG_OVE_NET
884#define OVE_NETIF_DEFINE_STATIC(name) \
885 static ove_netif_storage_t _##name##_storage; \
886 static ove_netif_t name; \
887 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
888 int _err = ove_netif_init(&name, &_##name##_storage); \
889 OVE_DEFINE_STATIC_CTOR_END_(name)
890
898#define OVE_SOCKET_DEFINE(name) static ove_socket_storage_t name
899#endif /* CONFIG_OVE_NET */
900
901#ifdef CONFIG_OVE_NET_TLS
911#define OVE_TLS_DEFINE_STATIC(name) \
912 static ove_tls_storage_t _##name##_storage; \
913 static ove_tls_t name; \
914 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
915 int _err = ove_tls_init(&name, &_##name##_storage); \
916 OVE_DEFINE_STATIC_CTOR_END_(name)
917#endif /* CONFIG_OVE_NET_TLS */
918
919#ifdef CONFIG_OVE_NET_HTTP
929#define OVE_HTTP_CLIENT_DEFINE_STATIC(name) \
930 static ove_http_client_storage_t _##name##_storage; \
931 static ove_http_client_t name; \
932 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
933 int _err = ove_http_client_init(&name, &_##name##_storage); \
934 OVE_DEFINE_STATIC_CTOR_END_(name)
935#endif /* CONFIG_OVE_NET_HTTP */
936
937#ifdef CONFIG_OVE_NET_MQTT
946#define OVE_MQTT_CLIENT_DEFINE_STATIC(name) \
947 static ove_mqtt_client_storage_t _##name##_storage; \
948 static ove_mqtt_client_t name; \
949 OVE_DEFINE_STATIC_CTOR_BEGIN_(name) \
950 int _err = ove_mqtt_client_init(&name, &_##name##_storage); \
951 OVE_DEFINE_STATIC_CTOR_END_(name)
952#endif /* CONFIG_OVE_NET_MQTT */
953
/* ove_storage_define_static */
955
/* ove_storage */
957
958#endif /* OVE_STORAGE_H */