pub trait PlatformTimer {
type TimerHandle: Send + Sync + 'static;
// Provided methods
fn create_periodic(
_period_us: u32,
_callback: extern "C" fn(*mut c_void),
_user_data: *mut c_void,
) -> Result<Self::TimerHandle, TimerError> { ... }
fn destroy(_handle: Self::TimerHandle) { ... }
fn create_oneshot(
_timeout_us: u32,
_callback: extern "C" fn(*mut c_void),
_user_data: *mut c_void,
) -> Result<Self::TimerHandle, TimerError> { ... }
fn cancel(_handle: &mut Self::TimerHandle) -> bool { ... }
}Expand description
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.
Default create_periodic returns TimerError::Unsupported so
platforms without a timer surface inherit safe behavior; destroy
is a no-op default for the same reason.
Required Associated Types§
Sourcetype TimerHandle: Send + Sync + 'static
type TimerHandle: Send + Sync + 'static
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.
Provided Methods§
Sourcefn create_periodic(
_period_us: u32,
_callback: extern "C" fn(*mut c_void),
_user_data: *mut c_void,
) -> Result<Self::TimerHandle, TimerError>
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.
§Safety
user_data must outlive the returned handle. The callback is
invoked from a platform-defined timer context (direct ISR on
Zephyr / bare-metal, deferred via xTimerPendFunctionCall on
FreeRTOS, signal handler on POSIX) — bodies should be
short and use atomic ops only.
Sourcefn destroy(_handle: Self::TimerHandle)
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.
Sourcefn create_oneshot(
_timeout_us: u32,
_callback: extern "C" fn(*mut c_void),
_user_data: *mut c_void,
) -> Result<Self::TimerHandle, TimerError>
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.
Default returns Unsupported so platforms without a oneshot
surface inherit safe behavior.
Sourcefn cancel(_handle: &mut Self::TimerHandle) -> bool
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.