Skip to main content

Module timer

Module timer 

Source
Expand description

Fixed-size timer queue backing crate::time::Sleep.

A task calling Sleep::<MICROS>::new().await registers a deadline here instead of busy-polling — the arch timer ISR (riscv::timer_tick / cortex_m::systick_handler) calls poll_timers on every tick, which wakes any task whose deadline has passed. This is what makes port::arch::idle() (WFI) a real power-saving wait instead of a spin loop: between ticks, no task is marked ready, so the executor actually sleeps.

Slots are u64-deadline UnsafeCells guarded by crate::critical rather than atomics, since RV32 has no native 64-bit atomic ops (even with the A extension, which is 32-bit/pointer-width only).

Structs§

TimerHandle
Handle to a registered timer slot; carries the slot index and the registered deadline so a stale [cancel_deadline] (after the slot was already freed and reused) is a harmless no-op (plan.md [B7]).
TimerQueueFull
Queue-full error returned by timer registration APIs (plan.md §4.3).

Constants§

MAX_TIMERS
Maximum number of outstanding timers (RIVET_MAX_TIMERS; one per task blocked in Sleep, so this should be >= MAX_TASKS if every task might sleep concurrently).

Functions§

poll_timers
Scan for expired timers and wake their tasks. Call from the platform timer ISR on every tick.
slots_in_use
Count of timer slots currently in use. Used by host-test reset/ inspection helpers and by [crate::report].