Skip to main content

CffiPlatform

Struct CffiPlatform 

Source
pub struct CffiPlatform;
Expand description

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

The crate that pulls CffiPlatform into a final binary is responsible for ensuring the symbols are supplied at link time (either by a C translation unit or a Rust -cffi shim crate).

Trait Implementations§

Source§

impl PlatformAlloc for CffiPlatform

Source§

fn alloc(size: usize) -> *mut c_void

Allocate size bytes. Returns null on failure.
Source§

fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void

Reallocate a previously allocated block. Returns null on failure.
Source§

fn dealloc(ptr: *mut c_void)

Free a previously allocated block.
Source§

fn heap_used_bytes() -> usize

Phase 230 Z5 / RFC-0034 D7 — bytes currently allocated from the platform heap. The true unified figure where the platform owns one kernel heap shared by the C side (alloc) and the Rust #[global_allocator]. Default 0 = “unknown / not instrumented”.
Source§

fn heap_total_bytes() -> usize

Total managed heap size in bytes (used + free), or 0 if unknown.
Source§

impl PlatformClock for CffiPlatform

Source§

fn epoch_us() -> u64

issue 0758 — forwards to the C symbol. NOT defaulted here: a C port that supplies the symbol must be able to answer, and one that does not returns 0 from its own definition. Taking the trait default instead would silently ignore a C implementation that exists.

Source§

fn clock_ns() -> u64

Monotonic nanoseconds since a platform-defined epoch. Never decreases. See <nros/platform.h> for the full contract (RFC-0073).
Source§

fn clock_resolution_ns() -> u64

Granularity of Self::clock_ns in nanoseconds: the smallest non-zero difference two successive reads can report. Non-zero, and constant after platform init.
Source§

impl PlatformCriticalSection for CffiPlatform

Source§

fn acquire() -> u32

Enter a critical section. Returns an opaque token to pass to Self::release.
Source§

fn release(token: u32)

Leave a critical section, restoring the posture captured at Self::acquire.
Source§

impl PlatformLog for CffiPlatform

Source§

fn write(severity: u8, name: &[u8], message: &[u8])

Deliver one record. Severity is a stable u8 matching nros_log::Severity::as_u8().
Source§

fn flush()

Best-effort drain of any internal buffer. Default = no-op.
Source§

impl PlatformNetworkPoll for CffiPlatform

Source§

fn network_poll()

Poll the network stack to process pending I/O. Read more
Source§

impl PlatformRandom for CffiPlatform

Source§

fn random_u8() -> u8

Source§

fn random_u16() -> u16

Source§

fn random_u32() -> u32

Source§

fn random_u64() -> u64

Source§

fn random_fill(buf: *mut c_void, len: usize)

Fill buffer with random bytes.
Source§

impl PlatformScheduler for CffiPlatform

Source§

fn yield_now()

Cooperative yield. Same semantics as PlatformYield::yield_now; mirrored here so consumers don’t need to import both traits when only the scheduler control surface is in scope. Default is a core::hint::spin_loop().
Source§

fn set_current_thread_policy(_p: SchedPolicy) -> Result<(), SchedError>

Apply the requested policy to the calling thread. Read more
Source§

fn set_affinity(_cpu_mask: u32) -> Result<(), SchedError>

Pin the calling thread to the CPUs whose bit is set in _cpu_mask. Default returns SchedError::Unsupported — platforms with affinity APIs override.
Source§

impl PlatformSleep for CffiPlatform

Source§

fn sleep_us(us: usize)

Sleep for the given number of microseconds.
Source§

fn sleep_ms(ms: usize)

Sleep for the given number of milliseconds.
Source§

fn sleep_s(s: usize)

Sleep for the given number of seconds.
Source§

impl PlatformSocketHelpers for CffiPlatform

Source§

fn set_non_blocking(sock: *const c_void) -> i8

Set socket to non-blocking mode.
Source§

fn accept(sock_in: *const c_void, sock_out: *mut c_void) -> i8

Accept a pending connection.
Source§

fn close(sock: *mut c_void)

Close a socket (shutdown + close).
Source§

fn wait_event(peers: *mut c_void, mutex: *mut c_void) -> i8

Wait for socket events (multi-threaded platforms).
Source§

impl PlatformTcp for CffiPlatform

Source§

fn create_endpoint(ep: *mut c_void, address: *const u8, port: *const u8) -> i8

Resolve address + port strings into an endpoint handle.
Source§

fn free_endpoint(ep: *mut c_void)

Free endpoint resources.
Source§

fn open(sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32) -> i8

Open a TCP client connection. endpoint is by-value (opaque bytes on stack).
Source§

fn listen(sock: *mut c_void, endpoint: *const c_void) -> i8

Open a TCP listening socket.
Source§

fn close(sock: *mut c_void)

Close a TCP socket.
Source§

fn read(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Read up to len bytes. Returns bytes read, or usize::MAX on error.
Source§

fn read_exact(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Read exactly len bytes. Returns len on success, usize::MAX on error.
Source§

fn send(sock: *const c_void, buf: *const u8, len: usize) -> usize

Send len bytes. Returns bytes sent, or usize::MAX on error.
Source§

fn set_rx_notify( sock: *const c_void, notify: Option<unsafe extern "C" fn(*mut c_void)>, ctx: *mut c_void, ) -> i8

phase-521 W6 (RFC-0113 D4) — install (Some) or remove (None) the connected socket’s receive notification, called from the stack’s own context each time data is queued, so it must only signal. Read more
Source§

impl PlatformThreading for CffiPlatform

Source§

fn task_init( task: *mut c_void, attr: *mut c_void, entry: Option<unsafe extern "C" fn(*mut c_void) -> *mut c_void>, arg: *mut c_void, ) -> i8

Spawn a new task. task is opaque caller-provided storage; attr carries scheduling hints (priority, stack size) or null for defaults; entry is the task entry point; arg is forwarded to entry. Returns 0 on success, non-zero on failure.
Source§

fn task_join(task: *mut c_void) -> i8

Block until task exits. Cleans up the task storage on success.
Source§

fn task_detach(task: *mut c_void) -> i8

Mark task as detached — its storage is reclaimed on exit without a join.
Source§

fn task_cancel(task: *mut c_void) -> i8

Request task to terminate at the next cancellation point. Cooperative.
Source§

fn task_exit()

Terminate the calling task immediately. Does not return.
Source§

fn task_free(task: *mut *mut c_void)

Free the task storage allocated by task_init.
Source§

fn mutex_init(m: *mut c_void) -> i8

Initialise a non-recursive mutex in caller-provided storage.
Source§

fn mutex_drop(m: *mut c_void) -> i8

Tear down a non-recursive mutex.
Source§

fn mutex_lock(m: *mut c_void) -> i8

Lock; block if held.
Source§

fn mutex_try_lock(m: *mut c_void) -> i8

Try to lock; non-zero return immediately if held.
Source§

fn mutex_unlock(m: *mut c_void) -> i8

Unlock; only the owning thread may call this.
Source§

fn mutex_rec_init(m: *mut c_void) -> i8

Initialise a recursive mutex (same-thread re-entrancy permitted). Required by zenoh-pico.
Source§

fn mutex_rec_drop(m: *mut c_void) -> i8

Tear down a recursive mutex.
Source§

fn mutex_rec_lock(m: *mut c_void) -> i8

Lock; re-entry from the owning thread must succeed.
Source§

fn mutex_rec_try_lock(m: *mut c_void) -> i8

Try to lock; same re-entry semantics as mutex_rec_lock.
Source§

fn mutex_rec_unlock(m: *mut c_void) -> i8

Unlock; releases when the lock count returns to zero.
Source§

fn condvar_init(cv: *mut c_void) -> i8

Initialise a condition variable in caller-provided storage.
Source§

fn condvar_drop(cv: *mut c_void) -> i8

Tear down a condition variable.
Source§

fn condvar_signal(cv: *mut c_void) -> i8

Wake one waiter on the condition variable.
Source§

fn condvar_signal_all(cv: *mut c_void) -> i8

Wake all waiters on the condition variable.
Source§

fn condvar_signal_from_isr(cv: *mut c_void) -> i8

Phase 124.B.7.a — ISR-safe variant of Self::condvar_signal. Callable from interrupt / signal-handler context. Backends implement via async-signal-safe primitives (POSIX: pipe write forwarded by a worker thread — Linux may use eventfd, which is a Linux syscall and not POSIX; RTOS: xSemaphoreGiveFromISR, tx_event_flags_set from ISR, k_sem_give from ISR). Returns non-zero when the backend has no ISR-safe path — caller can fall back to condvar_signal (with the obvious latency cost). Read more
Source§

fn condvar_wait_until(cv: *mut c_void, m: *mut c_void, abstime: u64) -> i8

Atomically release m and block on cv until signalled or until the absolute monotonic deadline abstime (milliseconds since the PlatformClock::clock_ns epoch); the mutex is re-acquired before this returns. Returns 0 when signalled, 1 on timeout and -1 on error (issue 1906). The remaining time rounds UP to the port’s tick. Read more
Source§

fn wake_init(w: *mut c_void) -> i8

Initialise a binary-semaphore-shaped wake primitive in caller-provided storage. See <nros/platform.h> for the per-platform backing primitive (POSIX sem_t, Zephyr k_sem, FreeRTOS xSemaphoreBinary, …). Default returns -1 (unsupported).
Source§

fn wake_drop(w: *mut c_void) -> i8

Tear down a wake primitive. Default returns -1 (unsupported).
Source§

fn wake_wait_ms(w: *mut c_void, timeout_ms: u32) -> i8

Block until signaled or timeout_ms elapses. Returns 0 on signal, 1 on timeout, -1 on error. Default returns -1 (unsupported).
Source§

fn wake_signal(w: *mut c_void) -> i8

Wake one waiter. Idempotent — a signal pending when another arrives is coalesced (the primitive stays at value 1). Default returns -1 (unsupported).
Source§

fn wake_signal_from_isr(w: *mut c_void) -> i8

ISR-safe signal. Returns -1 when the backend has no ISR path; callers may fall back to wake_signal (with the obvious latency cost). Default forwards to wake_signal.
Source§

fn wake_storage_size() -> usize

Caller-storage size requirement (bytes). Default 0 — signals “no wake primitive available”. May be called before wake_init.
Source§

fn wake_storage_align() -> usize

Caller-storage alignment requirement (bytes). Default 1.
Source§

fn task_storage_size() -> usize

Caller-storage size requirement (bytes) for a task handle. Read more
Source§

fn task_storage_align() -> usize

Caller-storage alignment requirement (bytes) for a task handle. Default 1.
Source§

fn task_stack_unused_bytes() -> usize

Smallest number of bytes ever left unused on the CALLING task’s stack, or 0 if this platform does not instrument it. Read more
Source§

fn task_stack_unused_bytes_upto(limit: usize) -> usize

task_stack_unused_bytes, capped at limit, reading at most limit bytes of the stack (phase-436 E5). Read more
Source§

fn wake_park_until_us(_w: *mut c_void, _deadline_us: u64) -> i8

phase-436 W7 — OPTIONAL microsecond park. Read more
Source§

fn wake_park_granularity_us() -> u64

The finest park wake_park_until_us can express, in microseconds. Read more
Source§

fn wake_park_handles_us( _w: *mut c_void, _handles: *const i32, _n: usize, _deadline_us: u64, ) -> i8

phase-521 W3 (RFC-0113 D3) — park on the wake object and on OS handles: the same park as wake_park_until_us, ended also when one of n handles at handles becomes readable. Read more
Source§

fn mutex_storage_size() -> usize

Caller-storage size requirement (bytes) for a plain mutex. Read more
Source§

fn mutex_storage_align() -> usize

Caller-storage alignment requirement (bytes) for a plain mutex.
Source§

fn mutex_rec_storage_size() -> usize

Caller-storage size requirement (bytes) for a RECURSIVE mutex.
Source§

fn mutex_rec_storage_align() -> usize

Caller-storage alignment requirement (bytes) for a recursive mutex.
Source§

fn condvar_storage_size() -> usize

Caller-storage size requirement (bytes) for a condition variable.
Source§

fn condvar_storage_align() -> usize

Caller-storage alignment requirement (bytes) for a condition variable.
Source§

impl PlatformTime for CffiPlatform

Source§

fn time_now_ns() -> u64

Wall-clock nanoseconds since the Unix epoch, or 0 if this platform has no real-time clock.
Source§

impl PlatformTimer for CffiPlatform

Source§

type TimerHandle = CffiTimerHandle

Opaque per-platform handle (FreeRTOS TimerHandle_t, Zephyr *mut k_timer, ThreadX *mut TX_TIMER, POSIX timer_t). Must be Send + Sync + 'static so the executor can stash it across thread boundaries.
Source§

fn create_periodic( period_us: u32, callback: extern "C" fn(*mut c_void), user_data: *mut c_void, ) -> Result<Self::TimerHandle, TimerError>

Register a periodic timer that fires callback(user_data) every period_us microseconds. Returns the platform-native handle for later destruction. Read more
Source§

fn create_oneshot( timeout_us: u32, callback: extern "C" fn(*mut c_void), user_data: *mut c_void, ) -> Result<Self::TimerHandle, TimerError>

Phase 110.E.b follow-up — register a one-shot timer that fires callback(user_data) exactly once after timeout_us microseconds. Used by per-callback runtime measurement: arm just before dispatch with timeout_us = budget_us; on callback completion call cancel. If the timer fires first the callback overran its budget. Read more
Source§

fn destroy(handle: Self::TimerHandle)

Cancel + free the timer. Idempotent on already-destroyed handles. Must drain in-flight callback invocations before returning so the user_data pointer is no longer accessed.
Source§

fn cancel(handle: &mut Self::TimerHandle) -> bool

Phase 110.E.b follow-up — cancel a previously-armed oneshot timer. Returns true when the cancellation prevented the callback from firing, false when the callback already fired (or the timer was already cancelled). Default is a no-op returning false.
Source§

impl PlatformUdp for CffiPlatform

Source§

fn create_endpoint(ep: *mut c_void, address: *const u8, port: *const u8) -> i8

Source§

fn free_endpoint(ep: *mut c_void)

Source§

fn open(sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32) -> i8

Source§

fn listen(sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32) -> i8

Open a UDP socket in listen (server) mode, bound to the given endpoint. Returns 0 on success, negative on failure. Read more
Source§

fn close(sock: *mut c_void)

Source§

fn read(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Source§

fn read_exact(sock: *const c_void, buf: *mut u8, len: usize) -> usize

Source§

fn send( sock: *const c_void, buf: *const u8, len: usize, endpoint: *const c_void, ) -> usize

Source§

fn set_recv_timeout(sock: *const c_void, timeout_ms: u32)

Set the receive timeout on a UDP socket (milliseconds). 0 means block indefinitely (no timeout).
Source§

fn readiness_handle(sock: *const c_void) -> i32

phase-521 W4 (RFC-0113 D4) — the OS handle that becomes readable when a datagram arrives: a file descriptor on POSIX and NuttX. Read more
Source§

fn set_rx_notify( sock: *const c_void, notify: Option<unsafe extern "C" fn(*mut c_void)>, ctx: *mut c_void, ) -> i8

phase-521 W4 (RFC-0113 D4) — install (Some) or remove (None) the socket’s receive notification, called from the stack’s own context each time a datagram is queued, so it must only signal. Read more
Source§

impl PlatformUdpMulticast for CffiPlatform

Source§

fn mcast_open( sock: *mut c_void, endpoint: *const c_void, lep: *mut c_void, timeout_ms: u32, iface: *const u8, ) -> i8

Source§

fn mcast_listen( sock: *mut c_void, endpoint: *const c_void, timeout_ms: u32, iface: *const u8, join: *const u8, ) -> i8

Source§

fn mcast_close( sockrecv: *mut c_void, socksend: *mut c_void, rep: *const c_void, lep: *const c_void, )

Source§

fn mcast_read( sock: *const c_void, buf: *mut u8, len: usize, lep: *const c_void, addr: *mut c_void, ) -> usize

Source§

fn mcast_read_exact( sock: *const c_void, buf: *mut u8, len: usize, lep: *const c_void, addr: *mut c_void, ) -> usize

Source§

fn mcast_send( sock: *const c_void, buf: *const u8, len: usize, endpoint: *const c_void, ) -> usize

Source§

impl PlatformYield for CffiPlatform

Source§

fn yield_now()

Relinquish the CPU long enough for another task / thread to run. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.