Expand description
Zephyr timers
This provides a relatively high-level and almost safe interface to Zephyr’s underlying
k_timer
.
Every timer starts as a StoppedTimer
, which has been allocated, but is not tracking any
time. These can either be created through StoppedTimer::new
, or by calling .init_once(())
on a
StaticStoppedTimer declared within the kobject_define!
macro, from object
.
The StoppedTimer
has two methods of interest here:
start_simple
: which starts the timer. This timer has methods for robustly getting counts of the number of times it has fired, as well as blocking the current thread for the timer to expire.start_callback
: which starts the timer, registering a callback handler. This timer will (unsafely) call the callback function, from IRQ context, every time the timer expires.
Both of these returned timer types SimpleTimer
and CallbackTimer
have a stop
method
that will stop the timer, and give back the original StoppedTimer
.
All of the types implement Drop
and can dynamic timers can be safely dropped. It is safe to
drop a timer allocated through the static object system, but it will then not be possible to
re-use that timer.
Structs§
- A timer callback. The function will be called in IRQ context being passed the given data. Note that this handler owns the data, but passes a reference to the handler. This will typically be a
SpinMutex
to allow for proper sharing with IRQ context. - A zephyr timer that calls a callback each time the timer expires.
- A simple timer.
- A Zephyr timer that is not running.
Type Aliases§
- A statically allocated
k_timer
(StoppedTimer).