nros platform-cffi
Canonical C ABI for porting the nros platform abstraction
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1#ifndef NROS_PLATFORM_H
2#define NROS_PLATFORM_H
3
4#include <stdint.h>
5#include <stddef.h>
6#include <stdbool.h>
7
47
48/* ---- Platform capability defaults ----
49 *
50 * Platform-*constant* capabilities. The single source of truth for a board's
51 * *variable* capabilities is its `nros-board.toml` `[board.capabilities]`, lowered
52 * to `-DNROS_PLATFORM_HAS_MALLOC` (etc.) by the build. These
53 * blocks supply only the per-platform constants, and never override a `-D` the
54 * board already set (every `#define` is `#ifndef`-guarded).
55 *
56 * - `NROS_PLATFORM_HAS_MALLOC` gates the canonical `malloc`/`free` shim below.
57 * Absent → a TU using the nros-cpp heap containers fails to *compile* (not
58 * link).
59 * - `NROS_PLATFORM_HAS_ATOMICS` is true on every supported target today.
60 *
61 * RTOS-config-derived capabilities are intentionally NOT defaulted here:
62 * - FreeRTOS heap ← `configSUPPORT_DYNAMIC_ALLOCATION` (FreeRTOSConfig.h),
63 * - Zephyr heap/mutex ← `CONFIG_HEAP_MEM_POOL_SIZE` / `CONFIG_MULTITHREADING`.
64 * Those boards declare `heap = true` in board.toml and the build lowers it to
65 * the Kconfig/FreeRTOSConfig knob, keeping the C view tied to the RTOS config.
66 */
67/* HAS_ATOMICS is a constant on every supported target. */
68#ifndef NROS_PLATFORM_HAS_ATOMICS
69# define NROS_PLATFORM_HAS_ATOMICS
70#endif
71
72/* HAS_MALLOC by platform. POSIX (and the POSIX-mapped hosted platforms: NuttX,
73 * ThreadX-linux, native) and the heap RTOSes (Zephyr, FreeRTOS) always run with
74 * an allocator under nros — the generator always configures the RTOS heap
75 * (`CONFIG_HEAP_MEM_POOL_SIZE`, `configSUPPORT_DYNAMIC_ALLOCATION`), and each
76 * declares `heap = true` in its `nros-board.toml`. They get the canonical
77 * malloc/free unconditionally here.
78 *
79 * Bare-metal / ThreadX-RV64 / ESP / custom do NOT default a heap: they opt in
80 * via the board.toml-derived `-DNROS_PLATFORM_HAS_MALLOC`, so a
81 * genuinely heap-less board still fails to compile a heap container. */
82/* Every hosted/RTOS platform has a heap (POSIX, Zephyr, FreeRTOS, ThreadX-linux,
83 * NuttX, and the default/unspecified case). This mirrors the retired nros-c
84 * dispatch, where any non-bare-metal platform fell through to `posix.h`'s
85 * unconditional malloc. Only bare-metal (incl. ThreadX-RV64 / ESP, which map to
86 * `NROS_PLATFORM_BAREMETAL`) withholds the heap and opts in via the
87 * board.toml-derived `-DNROS_PLATFORM_HAS_MALLOC`. */
88#if !defined(NROS_PLATFORM_BAREMETAL)
89# ifndef NROS_PLATFORM_HAS_MALLOC
90# define NROS_PLATFORM_HAS_MALLOC
91# endif
92#endif
93
94#ifdef __cplusplus
95extern "C" {
96#endif
97
98/* ---- Return codes ----
99 *
100 * This vocabulary was once declared and used by NO
101 * port: 26 entry points returned a bare `int8_t` 0/-1, so "this platform
102 * never does this" and "this failed just now" were the same value.
103 *
104 * That distinction is not academic. A caller may cache `UNSUPPORTED` forever
105 * and MUST retry `NOMEM`: `pthread_create` fails transiently on NuttX under
106 * load, and a worker pool that cannot tell the two apart caches
107 * every refusal, disabling a priority level for the process on what may have
108 * been a momentary shortage.
109 *
110 * `nros_platform_ret_t` is `int8_t` because that is the width the functions
111 * already return; it was `int32_t` and, having no users, cost nothing to
112 * narrow. Every code below is non-zero, so a caller testing `!= 0` — which is
113 * every caller today — is unaffected by ports becoming more specific.
114 *
115 * The values are written WITHOUT a cast on purpose. `((nros_platform_ret_t) 0)`
116 * is the more careful C, and it is why bindgen emitted none of these: it cannot
117 * evaluate a cast into a constant, so `nros-platform-cffi` carried a
118 * hand-written Rust copy of all three — a mirror of exactly the kind
119 * `check-ffi-struct-mirrors` exists to prevent, kept in step by nothing. Bare
120 * integer literals cross the generator, so there is now one definition. */
121
122typedef int8_t nros_platform_ret_t;
123
125#define NROS_PLATFORM_RET_OK 0
127#define NROS_PLATFORM_RET_ERROR -1
132#define NROS_PLATFORM_RET_UNSUPPORTED -5
136#define NROS_PLATFORM_RET_NOMEM -6
140#define NROS_PLATFORM_RET_INVALID -7
144#define NROS_PLATFORM_RET_TIMEOUT -8
145
146/* ---- Clock (monotonic) ---- */
147
163
177
178/* `nros_platform_clock_ms` and
179 * ~~`nros_platform_clock_us`~~ are RETIRED. They were kept for one release as
180 * `static inline` wrappers behind NROS_PLATFORM_LEGACY_CLOCK_UNITS; both
181 * the wrappers and the escape hatch are now gone. Callers divide
182 * `nros_platform_clock_ns()` themselves — and a caller that hand-declares
183 * either retired name is caught by
184 * `scripts/check-retired-platform-clock-symbols.py`. */
185
186/* ---- Clock (wall-clock epoch) ---- */
187
223
224/* ---- Allocation ---- */
225
228void *nros_platform_alloc(size_t size);
229
233void *nros_platform_realloc(void *ptr, size_t size);
234
236void nros_platform_dealloc(void *ptr);
237
238/* Canonical `malloc`/`free` C-ABI surface. nros-cpp's heap
239 * containers (`heap_string.hpp`, `heap_sequence.hpp`) allocate through
240 * `nros_platform_malloc` / `nros_platform_free` so C and C++ share one
241 * allocator. Defined ONCE here (replacing the former 5 per-header copies) as a
242 * thin forward to the platform `alloc`/`dealloc` funnel, GATED on
243 * the heap capability: a board without `NROS_PLATFORM_HAS_MALLOC` does not get
244 * the canonical malloc/free, so using a heap container on a heap-less board is a
245 * compile error, not a latent link failure. */
246#ifdef NROS_PLATFORM_HAS_MALLOC
247static inline void *nros_platform_malloc(size_t size) {
248 return nros_platform_alloc(size);
249}
250
251static inline void nros_platform_free(void *ptr) {
253}
254#endif /* NROS_PLATFORM_HAS_MALLOC */
255
261
291
308
311
312/* ---- Atomics ---- */
313/* Single portable atomic-bool pair (was per-RTOS
314 * `static inline` in the retired nros-c sub-headers: posix `__atomic`, zephyr
315 * `atomic_set`, freertos critical-section, bare-metal barrier). The `__atomic_*`
316 * builtins lower to a plain load/store + acquire/release fence for a
317 * naturally-aligned 1-byte `bool` on every target nros builds — no CAS /
318 * A-extension needed (riscv32imc never builds nros-c). Used directly (not C11
319 * `<stdatomic.h>`, which does not compile under g++). Header-only inline, so
320 * there is no extern symbol + no Rust-mirror entry. */
321static inline void nros_platform_atomic_store_bool(bool *ptr, bool value) {
322 __atomic_store_n(ptr, value, __ATOMIC_RELEASE);
323}
324
325static inline bool nros_platform_atomic_load_bool(const bool *ptr) {
326 return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
327}
328
329/* ---- Sleep ---- */
330
334
337
340
341/* ---- Cooperative yield ---- */
342
349
350/* ---- Random ---- */
351
363void nros_platform_random_fill(void *buf, size_t len);
364
365/* ---- Wall clock ---- */
366
390
391/* The state type and its values. Under the guard nros-c's public copy
392 * (`rclc/detail/wall_clock_state.h`) shares, so a TU including both gets one
393 * definition. The two copies are one struct, member for member. */
394#ifndef NROS_WALL_CLOCK_STATE_T_DEFINED
395#define NROS_WALL_CLOCK_STATE_T_DEFINED
397#define NROS_WALL_CLOCK_SOURCE_PLATFORM 0u
398#define NROS_WALL_CLOCK_SOURCE_SNTP 1u
399#define NROS_WALL_CLOCK_SOURCE_ZENOH_HLC 2u
400#define NROS_WALL_CLOCK_SOURCE_BOARD 3u
401
406 bool synced;
409 uint8_t source;
412 uint32_t steps;
414#endif
415
426
427/* ~~`nros_platform_time_now_ms`~~,
428 * ~~`nros_platform_time_since_epoch_secs`~~ and
429 * ~~`nros_platform_time_since_epoch_nanos`~~ are RETIRED, the same way
430 * `clock_ms` / `clock_us` were retired rather than keeping
431 * wrappers. A caller that hand-declares any of the three is caught by
432 * `scripts/check-retired-platform-clock-symbols.py`. */
433
434/* ---- Threading: tasks ---- */
435
436/* ---- Task attributes ----
437 *
438 * `attr` used to be an undefined `void *`: IGNORED
439 * by the posix and zephyr ports, a PRIVATE struct in the freertos and esp-idf
440 * ports, and MANDATORY on threadx (a `NULL` was a hard failure). Three struct
441 * types, no shared definition, and therefore no portable way to ask for a stack
442 * size — which is why a bespoke C shim once spawned a NuttX sched task
443 * with a 64 KiB stack, and why a generic spawn that passed `NULL` would fail
444 * on ThreadX.
445 *
446 * One type now, defined here, and `attr == NULL` means "every default" on
447 * EVERY port. */
448typedef struct {
451 const char *name;
491 int32_t priority;
493 int8_t core;
495 uint8_t flags;
497
499#define NROS_PLATFORM_TASK_DETACHED 0x01u
500
501/* ---- Normalised priority band ----
502 *
503 * `0` = least urgent … `NROS_PLATFORM_PRIORITY_MAX` = most urgent. A port maps
504 * the band onto its native range; the map is documented at each port's
505 * `task_init` and is the ONLY place a direction is decided.
506 *
507 * The band is deliberately small. It is a portable ORDERING, not a claim that
508 * every RTOS has 256 usable levels — ThreadX ships 32 by default, FreeRTOS's
509 * `configMAX_PRIORITIES` is commonly 5 to 32, and a map that pretended
510 * otherwise would collapse distinct sched tasks onto one level without saying so. */
511#define NROS_PLATFORM_PRIORITY_MIN 0
512#define NROS_PLATFORM_PRIORITY_MAX 255
514#define NROS_PLATFORM_PRIORITY_INHERIT INT32_MIN
515
521#define NROS_PLATFORM_PRIORITY_RAW(n) (-0x40000000 - (int32_t) (n))
523#define NROS_PLATFORM_PRIORITY_IS_RAW(p) \
524 ((p) <= -0x40000000 && (p) != NROS_PLATFORM_PRIORITY_INHERIT)
525
526#define NROS_PLATFORM_PRIORITY_RAW_VALUE(p) (-0x40000000 - (int32_t) (p))
527
534
543int8_t nros_platform_task_init(void *task, void *attr,
544 void *(*entry)(void *), void *arg);
545
547int8_t nros_platform_task_join(void *task);
548
551int8_t nros_platform_task_detach(void *task);
552
555int8_t nros_platform_task_cancel(void *task);
556
559
562void nros_platform_task_free(void **task);
563
584
585/* ---- Opaque-storage sizes, at COMPILE time ----
586 *
587 * The probes above answer a caller that allocates
588 * at runtime. They cannot answer one that embeds these objects BY VALUE —
589 * zenoh-pico's `_z_mutex_t` is a type, and a function call cannot size an
590 * array — so the same facts are also available as macros.
591 *
592 * These are UPPER BOUNDS over every supported port, not per-port exact sizes: a
593 * single header cannot know which port will link, and a consumer that embeds by
594 * value must reserve enough for the one that does. Each port asserts its own
595 * type fits (`_Static_assert` in its `platform.c`), so a bound that stops being
596 * true is a compile error in the port rather than a silent overrun in the
597 * consumer.
598 *
599 * They replace a hand-computed table in `zpico-sys` that recorded other
600 * platforms' sizes as `≈` values with a "2× safety margin", checked by nobody,
601 * about structs that are Kconfig-dependent on at least two of those platforms —
602 * the same shape as the `pthread_attr_t` mismatch above. The numbers below are
603 * deliberately generous for the same reason the old ones were; the difference
604 * is that they are now checked.
605 *
606 * A port may raise a bound by defining it before including this header. */
607#ifndef NROS_PLATFORM_TASK_STORAGE_SIZE
608/* 512. ThreadX is the large one, and the number here is MEASURED, not
609 * estimated: `sizeof(TX_THREAD)` is **360** bytes on the 64-bit Linux port,
610 * plus this port's owned-stack pointer and padding.
611 *
612 * The estimate it replaces is worth keeping visible. `zpico-sys` recorded
613 * "ThreadX TX_THREAD ≈ 232" and sized its task storage at 256 — correct for a
614 * 32-bit port and 128 bytes short on a 64-bit one. That table was hand-written
615 * prose about another platform's struct, which is why it was replaced
616 * with probes and `_Static_assert`s; this bound was raised BECAUSE one of those
617 * asserts failed on the first real ThreadX build, rather than because someone
618 * re-read the comment. */
619# define NROS_PLATFORM_TASK_STORAGE_SIZE 512
620#endif
621#ifndef NROS_PLATFORM_MUTEX_STORAGE_SIZE
622/* 256, not a tighter fit, and the reason is recorded rather than guessed:
623 * `zpico-sys` bounded this at 64 B, met ThreadX's `TX_MUTEX` (~120 B with
624 * ownership / inheritance / suspension-list fields), and silently corrupted the
625 * neighbouring field — presenting as a HANG in `Executor::open` after the zenoh
626 * handshake, because every mutex op on the in-band executor trampled a
627 * neighbour. Over-reserving costs bytes; under-reserving costs that. */
628# define NROS_PLATFORM_MUTEX_STORAGE_SIZE 256
629#endif
630#ifndef NROS_PLATFORM_MUTEX_REC_STORAGE_SIZE
631# define NROS_PLATFORM_MUTEX_REC_STORAGE_SIZE 256
632#endif
633#ifndef NROS_PLATFORM_CONDVAR_STORAGE_SIZE
634/* POSIX `pthread_cond_t` is 48 B; a composite RTOS condvar
635 * (`TX_MUTEX + TX_SEMAPHORE + UINT`) is ~184. Same reasoning as the mutex. */
636# define NROS_PLATFORM_CONDVAR_STORAGE_SIZE 256
637#endif
638#ifndef NROS_PLATFORM_STORAGE_ALIGN
639/* Every opaque type on every supported port is at most 8-byte aligned. */
640# define NROS_PLATFORM_STORAGE_ALIGN 8
641#endif
642
643
644/* ---- Threading: non-recursive mutex ----
645 *
646 * Both mutex kinds INHERIT PRIORITY on every port: Zephyr's
647 * `k_mutex`, FreeRTOS's mutex semaphores and ThreadX's `TX_INHERIT` do it
648 * natively, and the POSIX port sets `PTHREAD_PRIO_INHERIT` (on NuttX that
649 * needs CONFIG_PRIORITY_INHERITANCE, which it refuses to build without). A
650 * new port must do the same: a mutex wait is exempt from the "no unbounded
651 * wait" rule only because inheritance bounds it. */
652
658
659/* ---- Threading: recursive mutex ---- */
660
668
669/* ---- Threading: condition variables ----
670 *
671 * The mutex a wait releases must be held by the caller EXACTLY ONCE (issue
672 * 1907). Several ports build every mutex as a recursive one, and the kernels'
673 * condition waits release one level: a caller holding `m` twice would keep it
674 * across the wait, and every signaller would block on it. POSIX gives the
675 * same advice for a recursive mutex. ThreadX and Zephyr's native arm refuse
676 * such a wait (-1). NuttX releases every level, which is not portable.
677 * FreeRTOS and Zephyr's POSIX arm cannot see the count, so there such a wait
678 * deadlocks. */
679
684
713
736int8_t nros_platform_condvar_wait_until(void *cv, void *m, uint64_t abstime);
737
738/* ---- Threading: wake primitive ----
739 *
740 * Binary-semaphore-shaped primitive used by the executor's wake_flag /
741 * spin_once cv-wait pair. Separate from `nros_platform_condvar_*` so
742 * the executor doesn't inherit zenoh-pico's pthread-shaped Zephyr
743 * ABI (which on libc hangs past `pthread_cond_timedwait` deadlines).
744 *
745 * Per-platform impl:
746 * * POSIX: `sem_t` with `sem_clockwait(CLOCK_MONOTONIC)` (glibc >= 2.30;
747 * elsewhere `sem_timedwait` on a re-anchored REALTIME deadline).
748 * * Zephyr: `k_sem` (kernel-native, libc-pthread-free).
749 * * FreeRTOS: `xSemaphoreCreateBinary` + `xSemaphoreGiveFromISR`.
750 * * NuttX: the POSIX source, via NuttX libc (`sem_clockwait`).
751 * * ThreadX: `tx_semaphore` (ISR-safe `tx_semaphore_put`).
752 * * bare: atomic flag + busy-spin against the platform clock.
753 *
754 * `wait_ms` returns 0 on signal, 1 on timeout, -1 on error.
755 * `signal_from_isr` is what an interrupt handler (on POSIX, a signal
756 * handler) may call: interrupt-safe, bounded, non-blocking. It returns -1 if
757 * the backend has no such path, and the caller must NOT then call `signal()`
758 * from the interrupt (FreeRTOS's `xSemaphoreGive` corrupts the scheduler
759 * there); the waiter sees the wake at its own deadline.
760 * POSIX's is async-signal-safe: `sem_post` and a pipe `write`, with no
761 * `sem_getvalue`.
762 * Storage is opaque to the caller; size/alignment via the probe
763 * helpers below. */
766int8_t nros_platform_wake_wait_ms(void *w, uint32_t timeout_ms);
769
792int8_t nros_platform_wake_park_until_us(void *w, uint64_t deadline_us);
793
796#define NROS_PLATFORM_PARK_SIGNALLED 0
797#define NROS_PLATFORM_PARK_EXPIRED 1
798#define NROS_PLATFORM_PARK_YIELDED 2
799
804
819int8_t nros_platform_wake_park_handles_us(void *w, const int32_t *handles, size_t n,
820 uint64_t deadline_us);
821
826
827/* ---- Critical section ---- */
828/* Global mutual exclusion against preemption + ISR
829 * delivery. Backs the Rust `critical_section::Impl` registration used
830 * by DDS, nros-rmw-{xrce,zenoh}, and any consumer of
831 * `critical_section::with()`. Reentrant by contract: every acquire
832 * must be paired with exactly one release, and the platform handles
833 * nesting (PRIMASK already stacks; pthread side uses a recursive
834 * mutex).
835 *
836 * The `uint32_t` token holds whatever the platform needs to restore
837 * the prior posture — Cortex-M PRIMASK bit, Cortex-R CPSR I-bit,
838 * RISC-V `mstatus.MIE` snapshot, pthread depth counter — and is
839 * opaque to the caller. */
842
843/* ---- Logging ---- */
844/* Per-platform leveled log delivery, following the usual
845 * split: portable facade (`nros-log`) formats into a buffer and
846 * hands the rendered text to whichever `nros-platform-<rtos>` is
847 * linked in. POSIX writes to stderr; Zephyr routes through
848 * `LOG_MODULE_DECLARE(nros)` (or `printk` fallback); ESP-IDF goes
849 * through `esp_log_write`; NuttX through `syslog`; FreeRTOS /
850 * ThreadX / bare-metal expose a `register_log_writer(...)` helper
851 * in their platform crate so boards register the actual writer
852 * (UART / semihosting / defmt / RTT) once at startup.
853 *
854 * `severity`: matches `nros_log::Severity::as_u8()`:
855 * 0 = Trace, 1 = Debug, 2 = Info, 3 = Warn, 4 = Error, 5 = Fatal.
856 * Implementors should map onto the platform's nearest level.
857 *
858 * `name_ptr` / `name_len`: logger name (NOT null-terminated; UTF-8).
859 * May be empty (the catch-all logger).
860 * `msg_ptr` / `msg_len`: already-formatted message body (NOT null-
861 * terminated; UTF-8). Implementors that need a `CStr` must copy
862 * into their own buffer + append `'\0'`.
863 *
864 * No return value: log delivery never fails from the caller's POV.
865 * Platforms drop silently on internal overflow (e.g. RTT ring full).
866 *
867 * `nros_platform_log_flush`: best-effort drain of any internal
868 * buffer (RTT, syslog buffered chan, etc.). Default impl = no-op.
869 *
870 * Thread / ISR safety is documented per platform. The ABI itself is
871 * synchronous + reentrant-safe at the caller layer (a recursion
872 * guard in `nros-log` prevents fan-out re-entry). */
874 uint8_t severity,
875 const uint8_t *name_ptr, uintptr_t name_len,
876 const uint8_t *msg_ptr, uintptr_t msg_len);
878
879/* Board-supplied writer hook. ONLY meaningful on platforms whose
880 * `nros_platform_log_write` impl is itself a thin dispatcher to a
881 * board-registered fn (FreeRTOS, ThreadX, bare-metal). On platforms
882 * with a native logger (POSIX, Zephyr, ESP-IDF, NuttX), the symbol
883 * is absent and the board should not link against it.
884 *
885 * Board crates call this ONCE at startup, before any task / thread
886 * begins logging. Re-calling replaces the registration.
887 *
888 * `writer` matches the signature of `nros_platform_log_write`.
889 * `flusher` is optional (pass NULL for fully-synchronous writers). */
891 uint8_t severity,
892 const uint8_t *name_ptr, uintptr_t name_len,
893 const uint8_t *msg_ptr, uintptr_t msg_len);
894
895typedef void (*nros_platform_log_flush_fn_t)(void);
896
900
901/*
902 * Runtime locator override.
903 *
904 * Returns a middleware locator to use INSTEAD of the build-time-baked default
905 * (`CONFIG_NROS_LOCATOR` / `option_env!("NROS_ENTRY_LOCATOR")`), or NULL to keep
906 * the bake. Only the native_sim/native_posix platform impl returns non-NULL
907 * (from `-testargs --nros-locator=<loc>`); every real-embedded impl returns
908 * NULL. Entry points (Rust `zephyr_component_main!`, the C/C++ entries) prefer
909 * this when non-NULL so native_sim tests can each dial a distinct per-test
910 * zenohd, retiring the shared-baked-port serialization.
911 *
912 * The returned pointer is owned by the platform (argv-backed) and valid for the
913 * process lifetime; the caller must not free it.
914 */
916
917/* ---- Fatal error ----
918 *
919 * The image's one ending. Rust's `#[panic_handler]`, a C precondition failure
920 * and a C++ terminate all arrive here, so an operator debugging a board has one
921 * place to look instead of four.
922 *
923 * Before this existed the ABI could express ALLOCATION but not fatality, so each
924 * language invented its own: `nros-c` spun silently, `nros-board-nuttx` printed
925 * and exited 1, the ThreadX RV64 board wrote UART and exited QEMU, the FreeRTOS
926 * board did semihosting + `bkpt` + spin. Four reasonable answers to four
927 * different questions, none of them the image's to choose.
928 *
929 * `msg` is a DIAGNOSTIC, not a C string: `len` bytes, no NUL required, possibly
930 * empty (`msg` may be NULL only when `len == 0`). It is not necessarily UTF-8 —
931 * a port that forwards to a text sink should treat it as bytes.
932 *
933 * Contract on the implementor:
934 * - MUST NOT return. Declared `_Noreturn` so a caller (and Rust's `-> !`) can
935 * rely on it.
936 * - MUST tolerate being called from ANY context — interrupt, scheduler
937 * locked, or before the kernel starts. That rules out anything needing a
938 * scheduler, which is why this is not simply "log at Fatal then halt".
939 * - SHOULD emit `msg` somewhere a human can read before terminating. A silent
940 * halt is the one behaviour no RTOS in this tree chose for itself.
941 *
942 * Spelled through `NROS_PLATFORM_NORETURN` because this header is included from
943 * C++ too (`nros-cpp`), where `_Noreturn` is not a keyword — that mismatch is a
944 * hard `'_Noreturn' does not name a type` in every C++ TU, which is how it was
945 * found.
946 *
947 * Ports map it to the fatal path they already have (`k_panic`, `PANIC()`,
948 * `esp_system_abort`, the FreeRTOS hook, `abort()`). A C/C++ image overrides the
949 * port's definition by defining this symbol strongly; a Rust image declares its
950 * own `#[panic_handler]` in the entry package. Either way the choice belongs to
951 * whoever builds the image.
952 */
953#if defined(__cplusplus)
954# define NROS_PLATFORM_NORETURN [[noreturn]]
955#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
956# define NROS_PLATFORM_NORETURN _Noreturn
957#else
958# define NROS_PLATFORM_NORETURN __attribute__((noreturn))
959#endif
960
961NROS_PLATFORM_NORETURN void nros_platform_panic(const char *msg, size_t len);
962
963#ifdef __cplusplus
964} /* extern "C" */
965#endif
966
967#endif /* NROS_PLATFORM_H */
int8_t nros_platform_ret_t
Definition platform.h:122
size_t nros_platform_condvar_storage_size(void)
int8_t nros_platform_task_detach(void *task)
size_t nros_platform_mutex_rec_storage_size(void)
size_t nros_platform_condvar_storage_align(void)
static void * nros_platform_malloc(size_t size)
Definition platform.h:247
int8_t nros_platform_wake_init(void *w)
uint64_t nros_platform_wake_park_granularity_us(void)
uint16_t nros_platform_random_u16(void)
void nros_platform_critical_section_release(uint32_t token)
void(* nros_platform_log_flush_fn_t)(void)
Definition platform.h:895
int8_t nros_platform_mutex_lock(void *m)
void nros_platform_log_flush(void)
size_t nros_platform_task_stack_unused_bytes_upto(size_t limit)
int8_t nros_platform_mutex_rec_init(void *m)
uint64_t nros_platform_epoch_us(void)
int8_t nros_platform_wake_signal_from_isr(void *w)
int8_t nros_platform_condvar_wait_until(void *cv, void *m, uint64_t abstime)
int8_t nros_platform_task_join(void *task)
int8_t nros_platform_mutex_init(void *m)
void nros_platform_random_fill(void *buf, size_t len)
size_t nros_platform_task_storage_align(void)
int8_t nros_platform_task_init(void *task, void *attr, void *(*entry)(void *), void *arg)
const char * nros_runtime_locator_override(void)
uint8_t nros_platform_random_u8(void)
int8_t nros_platform_mutex_try_lock(void *m)
void nros_platform_sleep_s(size_t s)
int8_t nros_platform_mutex_rec_unlock(void *m)
size_t nros_platform_heap_used_bytes(void)
int8_t nros_platform_mutex_rec_try_lock(void *m)
void nros_platform_dealloc(void *ptr)
void nros_platform_sleep_ms(size_t ms)
uint64_t nros_platform_clock_ns(void)
int8_t nros_platform_wake_drop(void *w)
void nros_platform_task_attr_init(nros_platform_task_attr_t *attr)
#define NROS_PLATFORM_NORETURN
Definition platform.h:958
int8_t nros_platform_task_cancel(void *task)
size_t nros_platform_task_stack_unused_bytes(void)
int8_t nros_platform_mutex_drop(void *m)
size_t len
Definition platform.h:961
int8_t nros_platform_condvar_signal(void *cv)
static bool nros_platform_atomic_load_bool(const bool *ptr)
Definition platform.h:325
size_t nros_platform_wake_storage_align(void)
int8_t nros_platform_mutex_rec_lock(void *m)
void nros_platform_register_log_writer(nros_platform_log_writer_fn_t writer, nros_platform_log_flush_fn_t flusher)
int8_t nros_platform_wake_park_handles_us(void *w, const int32_t *handles, size_t n, uint64_t deadline_us)
int8_t nros_platform_condvar_signal_from_isr(void *cv)
void nros_platform_log_write(uint8_t severity, const uint8_t *name_ptr, uintptr_t name_len, const uint8_t *msg_ptr, uintptr_t msg_len)
void nros_platform_yield_now(void)
size_t nros_platform_mutex_rec_storage_align(void)
static void nros_platform_atomic_store_bool(bool *ptr, bool value)
Definition platform.h:321
size_t nros_platform_mutex_storage_size(void)
void nros_platform_sleep_us(size_t us)
size_t nros_platform_task_storage_size(void)
int8_t nros_platform_mutex_rec_drop(void *m)
uint32_t nros_platform_critical_section_acquire(void)
int8_t nros_platform_wake_signal(void *w)
static void nros_platform_free(void *ptr)
Definition platform.h:251
void * nros_platform_realloc(void *ptr, size_t size)
int8_t nros_platform_mutex_unlock(void *m)
int8_t nros_platform_condvar_signal_all(void *cv)
size_t nros_platform_wake_storage_size(void)
uint64_t nros_platform_random_u64(void)
size_t nros_platform_heap_total_bytes(void)
void(* nros_platform_log_writer_fn_t)(uint8_t severity, const uint8_t *name_ptr, uintptr_t name_len, const uint8_t *msg_ptr, uintptr_t msg_len)
Definition platform.h:890
int8_t nros_platform_wake_wait_ms(void *w, uint32_t timeout_ms)
uint32_t nros_platform_random_u32(void)
uint64_t nros_platform_time_now_ns(void)
void nros_platform_task_free(void **task)
size_t nros_platform_mutex_storage_align(void)
uint64_t nros_platform_clock_resolution_ns(void)
int8_t nros_platform_condvar_drop(void *cv)
int8_t nros_platform_wake_park_until_us(void *w, uint64_t deadline_us)
int8_t nros_platform_condvar_init(void *cv)
nros_wall_clock_state_t nros_platform_wall_clock_state(void)
void * nros_platform_alloc(size_t size)
void nros_platform_task_exit(void)
Definition platform.h:448
const char * name
Definition platform.h:451
size_t stack_bytes
Definition platform.h:468
int32_t priority
Definition platform.h:491
void * stack_mem
Definition platform.h:474
uint8_t flags
Definition platform.h:495
int8_t core
Definition platform.h:493
Definition platform.h:403
bool synced
Definition platform.h:406
uint32_t steps
Definition platform.h:412
uint8_t source
Definition platform.h:409