Skip to main content

Crate nros_platform_cffi

Crate nros_platform_cffi 

Source
Expand description

Rust mirror of the canonical C ABI in <nros/platform.h>.

Every nros binary links exactly one platform implementation; the free extern "C" symbols declared below are resolved at link time. There is no runtime registration step. To inject a platform from C, drop a translation unit defining the symbols (or link against a static library that does).

Rust platform crates implement the nros_platform_api traits as before; a sibling -cffi shim crate re-exports the Rust impl as #[unsafe(no_mangle)] extern "C" symbols matching the names in the header. That separation lets the same Rust impl serve both trait-driven Rust callers and C-ABI consumers.

§Usage

  • C implementor: implement the functions in <nros/platform.h> and link against the nros binary.
  • Rust consumer: enable the platform-cffi feature on nros-platform; CffiPlatform dispatches every trait call to the linked C symbols.

§Companion

Platform sits one tier below RMW. The Phase 117 RMW vtable (<nros/rmw_vtable.h>) is a runtime-pluggable struct; the platform layer is link-time-bound free symbols. Different choice because RMW backends genuinely swap per session (zenoh vs cyclonedds vs xrce in the same binary at test time) while a platform is fixed for the life of a binary.

Re-exports§

pub use crate::generated::NROS_PLATFORM_RET_ERROR;
pub use crate::generated::NROS_PLATFORM_RET_INVALID;
pub use crate::generated::NROS_PLATFORM_RET_NOMEM;
pub use crate::generated::NROS_PLATFORM_RET_OK;
pub use crate::generated::NROS_PLATFORM_RET_TIMEOUT;
pub use crate::generated::NROS_PLATFORM_RET_UNSUPPORTED;
pub use generated::*;

Modules§

generated
AUTO-GENERATED by scripts/gen-abi-bindings.sh (bindgen 0.72.1) — DO NOT EDIT.
log
The LogSink that speaks the platform ABI.

Macros§

nros_platform_export
Convenience: emit every nros_platform_* symbol declared in <nros/platform.h> by delegating to the corresponding nros_platform_api::Platform* trait method on $ty. The caller must implement every trait covered by the capability macros.
nros_platform_export_alloc
Emit nros_platform_{alloc,realloc,dealloc} delegating to <$ty as PlatformAlloc>.
nros_platform_export_clock
Emit nros_platform_clock_{ms,us} delegating to <$ty as PlatformClock>.
nros_platform_export_critical_section
Phase 121.9 — emit the two nros_platform_critical_section_* symbols by delegating to the caller’s PlatformCriticalSection impl.
nros_platform_export_log
Phase 88.11 — emit nros_platform_log_write + nros_platform_log_flush from a PlatformLog-implementing ZST. Use this on bare-metal / custom platforms (mps2-an385, stm32f4, esp32-baremetal, …) that don’t ship a separate C implementation file. The implementor’s write receives the rendered body + logger name as &[u8] slices.
nros_platform_export_net
Emit every nros_platform_tcp_* / nros_platform_udp_* / nros_platform_udp_mcast_* / nros_platform_socket_* / nros_platform_network_poll symbol declared in <nros/platform_net.h> by delegating to the corresponding trait method on $ty. The caller must implement PlatformTcp, PlatformUdp, PlatformUdpMulticast, PlatformSocketHelpers, and PlatformNetworkPoll.
nros_platform_export_panic
Emit nros_platform_panic delegating to <$ty as PlatformPanic> (phase-366 / RFC-0077).
nros_platform_export_random
Emit nros_platform_random_* delegating to <$ty as PlatformRandom>.
nros_platform_export_sleep
Emit nros_platform_sleep_{us,ms,s} delegating to <$ty as PlatformSleep>.
nros_platform_export_threading
Emit nros_platform_task_*, nros_platform_mutex_*, nros_platform_mutex_rec_*, and nros_platform_condvar_* delegating to <$ty as PlatformThreading>. Skip this macro on platforms without kernel threads.
nros_platform_export_time
Emit nros_platform_time_* delegating to <$ty as PlatformTime>.
nros_platform_export_timer
Emit every nros_platform_timer_* symbol declared in <nros/platform_timer.h> by delegating to the corresponding PlatformTimer trait method on $ty.
nros_platform_export_yield
Emit nros_platform_yield_now delegating to <$ty as PlatformYield>.

Structs§

CffiPlatform
Zero-sized type implementing the platform traits via the canonical nros_platform_* C symbols.
CffiTimerHandle

Type Aliases§

NrosPlatformLogFlushFn
Board-supplied flush fn type. Pass None to nros_platform_register_log_writer when the writer is fully synchronous.
NrosPlatformLogWriterFn
Board-supplied writer fn type. ONLY meaningful on platforms whose nros_platform_log_write impl is itself a thin dispatcher to a board-registered fn (FreeRTOS, ThreadX, bare-metal). On platforms with a native logger (POSIX, Zephyr, ESP-IDF, NuttX), the symbol is absent and the board should not link against it.
NrosPlatformRet
The C nros_platform_ret_t, from the generated bindings.