Timer¶
Overview¶
The Timer module is an event-based timer library for handling timeouts. It uses tick level time resolution and allows user to explicitly manage the expired timer events.
Key Features¶
Timer Event Management:
Support for one-shot and periodic timer events.
Timer events can be of an arbitrary type with the only requirement of being inherited from
struct am_timer_event.Expired events are iterated explicitly. It is up to users what to do with the expired event.
Tick-Based Operation:
Timers operate on a tick-based system, updated with
am_timer_tick_iterator_init()andam_timer_tick_iterator_next().Multiple tick rates can be applied to different instances of
`struct am_timer.
Thread Safety:
Critical sections managed using user-defined enter/exit callbacks.
Safe timer operations across concurrent tasks and/or ISRs.
Dynamic and Static Timer Allocation:
Timer events can be allocated in any suitable way - the timer library is fully agnostic of it as long as the memory content remains valid throughout the lifetime of the timer event.
Design Considerations¶
Timer Events:
Timer events
am_event_timerencapsulate the details of scheduled operations. Each timer event includes:Shot time: Number of ticks after which the event is fired.
Interval: Period between successive event firings (0 for one-shot events).
The extended timer events
am_event_timer_xinherit fromam_event_timerand add event specific context pointer.
Critical Section Management:
User-defined
crit_enterandcrit_exitcallbacks protect shared resources during timer updates and event handling.
Usage Examples¶
The usage examples can be seen in timer unit tests test.c file. The usage of the timer library in the application can be found in apps/examples/async/main.c.