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.

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_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

Constants§

NROS_PLATFORM_RET_ERROR
NROS_PLATFORM_RET_OK
NROS_PLATFORM_RET_UNSUPPORTED

Functions§

nros_platform_alloc
nros_platform_clock_ms
nros_platform_clock_us
nros_platform_condvar_drop
nros_platform_condvar_init
nros_platform_condvar_signal
nros_platform_condvar_signal_all
nros_platform_condvar_signal_from_isr
Phase 124.B.7.a — ISR-safe variant of signal. See <nros/platform.h> for per-platform contract.
nros_platform_condvar_wait
nros_platform_condvar_wait_until
nros_platform_critical_section_acquire
nros_platform_critical_section_release
nros_platform_dealloc
nros_platform_heap_total_bytes
nros_platform_heap_used_bytes
nros_platform_log_flush
nros_platform_log_write
nros_platform_mutex_drop
nros_platform_mutex_init
nros_platform_mutex_lock
nros_platform_mutex_rec_drop
nros_platform_mutex_rec_init
nros_platform_mutex_rec_lock
nros_platform_mutex_rec_try_lock
nros_platform_mutex_rec_unlock
nros_platform_mutex_try_lock
nros_platform_mutex_unlock
nros_platform_network_poll
nros_platform_random_fill
nros_platform_random_u8
nros_platform_random_u16
nros_platform_random_u32
nros_platform_random_u64
nros_platform_realloc
nros_platform_register_log_writer
Register a board writer + optional flusher (Phase 88.9). Available only when the linked platform impl is one of the no-native-logger backends (FreeRTOS / ThreadX / bare-metal).
nros_platform_sleep_ms
nros_platform_sleep_s
nros_platform_sleep_us
nros_platform_socket_accept
nros_platform_socket_close
nros_platform_socket_set_non_blocking
nros_platform_socket_wait_event
nros_platform_task_cancel
nros_platform_task_detach
nros_platform_task_exit
nros_platform_task_free
nros_platform_task_init
nros_platform_task_join
nros_platform_tcp_close
nros_platform_tcp_create_endpoint
nros_platform_tcp_free_endpoint
nros_platform_tcp_listen
nros_platform_tcp_open
nros_platform_tcp_read
nros_platform_tcp_read_exact
nros_platform_tcp_send
nros_platform_time_now_ms
nros_platform_time_since_epoch_nanos
nros_platform_time_since_epoch_secs
nros_platform_timer_cancel
nros_platform_timer_create_oneshot
nros_platform_timer_create_periodic
nros_platform_timer_destroy
nros_platform_udp_close
nros_platform_udp_create_endpoint
nros_platform_udp_free_endpoint
nros_platform_udp_listen
nros_platform_udp_mcast_close
nros_platform_udp_mcast_listen
nros_platform_udp_mcast_open
nros_platform_udp_mcast_read
nros_platform_udp_mcast_read_exact
nros_platform_udp_mcast_send
nros_platform_udp_open
nros_platform_udp_read
nros_platform_udp_read_exact
nros_platform_udp_send
nros_platform_udp_set_recv_timeout
nros_platform_wake_drop
nros_platform_wake_init
nros_platform_wake_signal
nros_platform_wake_signal_from_isr
nros_platform_wake_storage_align
nros_platform_wake_storage_size
nros_platform_wake_wait_ms
nros_platform_yield_now

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
Mirrors C nros_platform_ret_t.