Skip to main content

Crate nros_platform_api

Crate nros_platform_api 

Source
Expand description

Platform capability sub-traits for nros.

This crate exists to break the dependency cycle between nros-platform (which depends on every platform crate via its feature-gated ConcretePlatform resolver) and the platform crates themselves (which need to implement these traits on their ZSTs). It contains only trait definitions — no implementations, no dependencies — so platform crates can take a build-time dep on it without creating a cycle back through nros-platform.

nros-platform re-exports everything from this crate, so downstream code that writes use nros_platform::PlatformClock; continues to work unchanged.

Each trait covers an independent system capability. Platform implementations pick which traits to implement based on what the hardware/RTOS provides. RMW shim crates declare trait bounds for the capabilities they need.

§Naming convention

Method names drop redundant prefixes when the trait name already supplies the namespace — e.g., PlatformTcp::open rather than PlatformTcp::tcp_open. Dispatch is always through a qualified path (<ConcretePlatform as PlatformTcp>::open(...)), so trait-to-trait collisions (PlatformTcp::open vs PlatformUdp::open) are disambiguated at the call site without needing a prefix on the trait method itself.

Three categories still keep sub-namespace prefixes internally:

  • PlatformThreadingmutex_*, condvar_*, task_* because the trait bundles three independent primitive families and unprefixed init / drop would be ambiguous within the trait itself.
  • PlatformUdpMulticastmcast_* because these methods have different signatures from PlatformUdp’s same-name methods; keeping the prefix makes call sites that use both traits self-documenting.
  • The close method appears on both PlatformTcp and PlatformSocketHelpers — the first is TCP teardown, the second is zenoh-pico’s generic “shutdown + close” helper. Both live unprefixed in their respective traits; call sites disambiguate via the qualified path.

§Status (Phase 84.F4)

The platform ZSTs (PosixPlatform, ZephyrPlatform, etc.) do not currently implement these traits — every platform exposes its methods as inherent impl Platform { fn foo() {} } blocks, and shim crates dispatch by name match. 84.F4 migrates each platform to impl PlatformX for Platform { fn foo() {} } one trait at a time, with the shims switching to <P as PlatformX>::foo(). Until that work is complete the traits here are a target specification.

Re-exports§

pub use wake::WAKE_STORAGE_ALIGN;
pub use wake::WAKE_STORAGE_BYTES;
pub use wake::Wake;
pub use wake::WakeInitError;
pub use wake::WakeReason;

Modules§

wake
Phase 130 — ergonomic Rust wrapper around PlatformThreading’s wake primitive.
xorshift32
Xorshift32 PRNG helpers shared by RTOS platform crates that lack a hardware RNG.

Enums§

SchedError
Errors returned by PlatformScheduler entry points.
SchedPolicy
Per-thread OS scheduling policy.
TimerError
Errors returned by PlatformTimer entry points.

Traits§

PlatformAlloc
Heap memory allocation.
PlatformClock
Monotonic clock.
PlatformCriticalSection
Global mutual exclusion against preemption + ISR delivery (Phase 121.9).
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.
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 (Phase 110.E.b). 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.