rtic_time/timer_queue/backend.rs
1use super::{TimerQueue, TimerQueueTicks};
2
3/// A backend definition for a monotonic clock/counter.
4pub trait TimerQueueBackend: 'static + Sized {
5 /// The type for ticks.
6 type Ticks: TimerQueueTicks;
7
8 /// Get the current time.
9 fn now() -> Self::Ticks;
10
11 /// Set the compare value of the timer interrupt.
12 ///
13 /// **Note:** This method does not need to handle race conditions of the monotonic, the timer
14 /// queue in RTIC checks this.
15 fn set_compare(instant: Self::Ticks);
16
17 /// Clear the compare interrupt flag.
18 fn clear_compare_flag();
19
20 /// Pend the timer's interrupt.
21 fn pend_interrupt();
22
23 /// Optional. Runs on interrupt before any timer queue handling.
24 fn on_interrupt() {}
25
26 /// Optional. This is used to save power, this is called when the timer queue is not empty.
27 ///
28 /// Enabling and disabling the monotonic needs to propagate to `now` so that an instant
29 /// based of `now()` is still valid.
30 ///
31 /// NOTE: This may be called more than once.
32 fn enable_timer() {}
33
34 /// Optional. This is used to save power, this is called when the timer queue is empty.
35 ///
36 /// Enabling and disabling the monotonic needs to propagate to `now` so that an instant
37 /// based of `now()` is still valid.
38 ///
39 /// NOTE: This may be called more than once.
40 fn disable_timer() {}
41
42 /// Returns a reference to the underlying timer queue.
43 fn timer_queue() -> &'static TimerQueue<Self>;
44}