Skip to main content

Crate nros_platform

Crate nros_platform 

Source
Expand description

Unified platform abstraction traits for nros.

This crate defines the backend-agnostic interface that platform implementations (POSIX, Zephyr, FreeRTOS, bare-metal, etc.) must satisfy. RMW backends consume these traits via thin shim crates that translate RMW-specific C symbols (e.g., z_clock_now, uxr_millis) into calls on the active platform implementation.

§Trait hierarchy

Capabilities are split into independent sub-traits so each RMW backend can declare exactly what it needs:

§Compile-time resolution

Exactly one platform feature must be enabled. The ConcretePlatform type alias (gated on any platform-* feature) resolves to the active backend, eliminating generic parameters.

Modules§

boot_config
log
The LogSink that speaks the platform ABI.
sched
The kernel’s deadline reservation on the calling thread.
task
One place that spawns a platform task from Rust.
termination
A termination signal ENDS a hosted image’s spin, so the boot funnel can close the RMW session before the process exits.
wake
Ergonomic Rust wrapper around PlatformThreading’s wake primitive.
xorshift32
Xorshift32 PRNG helpers shared by RTOS platform crates that lack a hardware RNG.

Structs§

BakedBootConfig
Build-time-baked boot config, emitted into the .nros_boot_config linker section by the entry macro / cmake. Fixed-size + pointer-free so a future post-link tool can patch it in place. The resolver reads it on embedded via BootConfig::from_baked (in nros-node).
DeployOverlay
Deploy-metadata overlay threaded from nros::main!() into the board’s boot config (issue #48 cause 1).
NullNodeRuntime
No-op NodeDispatchRuntime for tests / placeholders. Every call returns Err(()) so callers that depend on a populated runtime fail loud rather than silently no-op.
RuntimeCtx
Runtime context handed to BoardEntry::run(setup).
SchedTaskSpec
One sched task: an RTOS task running an Executor over the shared session, admitting only the listed callback groups.
SchedTaskSpinGap
One sched task spin loop’s scheduled gap. Construct beside the loop, call SchedTaskSpinGap::after_spin at the bottom of every iteration.
SignaledCallback
Layer-clean substitute for nros::node_metadata::CallbackId + nros::node::CallbackCtx at the NodeDispatchRuntime boundary. nros-platform sits below nros in the dep graph, so the trait surface cannot reference those types directly. The nros-side runtime impl wraps a real (CallbackId, &mut CallbackCtx) pair into this opaque shape before invoking NodeDispatchRuntime::signal_callback; the concrete dispatcher casts ctx_ptr back to &mut nros::CallbackCtx<'_> at the call site.
Wake
RAII wrapper around the platform’s wake primitive.
WallClockState
nros_wall_clock_state_t: whether the wall clock is synced, which source answers (WALL_CLOCK_SOURCE_*), and how many times that source changed since boot.

Enums§

DispatchStrategy
How a Node expects its callbacks to fire.
LinkKind
The link kind an image rides — its locator’s scheme.
NetworkError
Network bringup failure mode.
PriorityDirection
Which way a kernel’s raw priority numbers run.
RuntimeError
Error returned by the codegen-emitted run_plan(runtime) body and by Node pkg register(runtime) wrappers.
SchedError
Errors returned by PlatformScheduler entry points.
SchedPolicy
Per-thread OS scheduling policy.
TimerError
Errors returned by PlatformTimer entry points.
WakeInitError
Errors at construction time.
WakeReason
Reason wait_ms returned.

Constants§

BOOT_SET_DOMAIN
Bit 2 — domain_id field is set.
BOOT_SET_LOCATOR
Bit 1 — locator field is set.
BOOT_SET_NAMESPACE
Bit 3 — namespace field is set.
BOOT_SET_NODE_NAME
Bit 0 — node_name field is set.
BOOT_SET_RMW
Bit 4 — rmw field is set (layout version 2).
NET_ENDPOINT_ALIGN
NET_ENDPOINT_SIZE
NET_SOCKET_ALIGN
NET_SOCKET_EOF
What a TCP read returns when the peer closed the stream (NROS_PLATFORM_NET_SOCKET_EOF): distinct from NET_SOCKET_ERROR and from 0, which means “nothing read yet”. A port returns it only when it knows the peer closed; zenoh-pico then closes the session and reconnects, where a 0 would leave it polling a dead socket forever.
NET_SOCKET_ERROR
What a socket read returns on error (NROS_PLATFORM_NET_SOCKET_ERROR).
NET_SOCKET_SIZE
NROS_BOOT_CONFIG_MAGIC
0x4E524243 = ASCII “NRBC”. A post-link tool scans for this magic to locate the struct in a firmware image.
NROS_BOOT_CONFIG_VERSION
Layout version — lets the resolver reject a mismatched baked struct.
WAKE_STORAGE_ALIGN
Alignment of the inline storage buffer. Wide enough for every pointer-aligned primitive on 64-bit hosts.
WAKE_STORAGE_BYTES
Maximum bytes the wake primitive may occupy on any supported platform. Sized generously so we never have to bump for a new RTOS port. Asserted against the runtime probe in Wake::new.
WALL_CLOCK_SOURCE_BOARD
NROS_WALL_CLOCK_SOURCE_BOARD.
WALL_CLOCK_SOURCE_PLATFORM
NROS_WALL_CLOCK_SOURCE_PLATFORM: the port’s own clock.
WALL_CLOCK_SOURCE_SNTP
NROS_WALL_CLOCK_SOURCE_SNTP.
WALL_CLOCK_SOURCE_ZENOH_HLC
NROS_WALL_CLOCK_SOURCE_ZENOH_HLC.

Traits§

Board
Super-trait every board impl carries (mirrors nros-board-common::board_init::Board).
BoardConfig
Universal board configuration accessors.
BoardEntry
Per-board boot driver.
BoardExit
Per-board termination contract.
BoardInit
Per-board hardware-init contract.
BoardPrint
Per-board stdout contract.
NodeDispatchRuntime
Node runtime sink the codegen-emitted run_plan(runtime) body talks to.
PlatformAlloc
Heap memory allocation.
PlatformCan
The implementer surface of <nros/platform_can.h>, the CAN frame driver.
PlatformClock
Monotonic clock.
PlatformCriticalSection
Global mutual exclusion against preemption + ISR delivery.
PlatformIvc
Inter-processor mailbox transport, modelled after NVIDIA Tegra IVC.
PlatformLibc
Standard C library functions needed by zenoh-pico on bare-metal targets.
PlatformLog
Per-platform leveled log delivery.
PlatformNetworkPoll
Network poll callback for bare-metal platforms using smoltcp.
PlatformPanic
The image’s one ending.
PlatformRandom
Pseudo-random number generation.
PlatformScheduler
PlatformSerial
Serial (byte-stream) transport.
PlatformSleep
Sleep primitives.
PlatformSocketHelpers
Socket helper operations called by zenoh-pico’s transport layer.
PlatformTcp
TCP networking.
PlatformThreading
Threading primitives: tasks, mutexes, and condition variables.
PlatformTime
Wall-clock / system time.
PlatformTimer
Periodic timer for ISR-driven sporadic-server budget refill. The trait factors out the per-platform timer surface so the executor (nros-node) can register an atomic refill callback without becoming generic over the platform — see docs/design/0017-platform-timer.md.
PlatformUdp
UDP unicast networking.
PlatformUdpMulticast
UDP multicast networking (used for zenoh scouting on desktop platforms).
PlatformYield
Scheduler yield primitive.
RticBoardEntry
Board-side hook for RTIC integration. The nros::main!() proc-macro (216.B.3) generates a #[rtic::app] module that calls Self::init_hardware from inside the framework-generated #[init] body and wires the returned pair into RTIC #[local] storage.

Functions§

boot_sched_task_index
Index of the sched task the BOOT task should run: the least urgent one.
freertos_priority_for
FreeRTOS native priority (0..=configMAX_PRIORITIES-1, here 0–7) for a normalized 0–31 priority. Linear interpolation (n*7 + 15) / 31 (round-to-nearest), so 0→0 (idle) and 31→7 (highest). Higher number = higher priority on FreeRTOS.
posix_nice_for
POSIX nice value (-20..=19, lower = more CPU) for a normalized 0–31 priority. Best-effort: native preemption normally uses the default scheduler (strict ordering needs SCHED_FIFO + privileges), so this is an advisory niceness, linear over the scale and clamped, with idle (0) pinned to the maximum 19. Anchors track the normalized scale (12→0 normal, 31→-20 critical).
rtic_dispatchers_agree
Do two dispatcher lists name the same interrupts, in the same order? const, for the assertion the nros::main! RTIC app emits: the macro restates the board’s RticBoardEntry::DISPATCHERS (an expansion cannot read a const of the crate it targets), and this keeps the copy from drifting.
stack_unused_bytes
Smallest number of bytes ever left unused on the CALLING task’s stack, or 0 if this port does not instrument it.
stack_unused_bytes_upto
stack_unused_bytes, capped at limit: min(unused, limit), reading at most limit bytes of the calling task’s stack.
threadx_priority_for
ThreadX native priority (0..=31, lower = higher priority) for a normalized 0–31 priority. Inverted scale 31 - n, so the normalized idle (0) maps to ThreadX 31 (lowest) and normalized critical (31) maps to ThreadX 0 (highest).
yield_now
Give up the processor to another ready task, through the port’s nros_platform_yield_now. For a thread that must wait for another to finish a short critical step (the executor’s wake fan-out waits out a backend callback this way) without spinning a single core it shares with that thread.

Type Aliases§

ConcretePlatform