diff options
Diffstat (limited to 'embassy-time/src/queue.rs')
| -rw-r--r-- | embassy-time/src/queue.rs | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/embassy-time/src/queue.rs b/embassy-time/src/queue.rs deleted file mode 100644 index c6f8b440a..000000000 --- a/embassy-time/src/queue.rs +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | //! Timer queue implementation | ||
| 2 | //! | ||
| 3 | //! This module defines the interface a timer queue needs to implement to power the `embassy_time` module. | ||
| 4 | //! | ||
| 5 | //! # Implementing a timer queue | ||
| 6 | //! | ||
| 7 | //! - Define a struct `MyTimerQueue` | ||
| 8 | //! - Implement [`TimerQueue`] for it | ||
| 9 | //! - Register it as the global timer queue with [`timer_queue_impl`](crate::timer_queue_impl). | ||
| 10 | //! | ||
| 11 | //! # Linkage details | ||
| 12 | //! | ||
| 13 | //! Check the documentation of the [`driver`](crate::driver) module for more information. | ||
| 14 | //! | ||
| 15 | //! Similarly to driver, if there is none or multiple timer queues in the crate tree, linking will fail. | ||
| 16 | //! | ||
| 17 | //! # Example | ||
| 18 | //! | ||
| 19 | //! ``` | ||
| 20 | //! use core::task::Waker; | ||
| 21 | //! | ||
| 22 | //! use embassy_time::Instant; | ||
| 23 | //! use embassy_time::queue::{TimerQueue}; | ||
| 24 | //! | ||
| 25 | //! struct MyTimerQueue{}; // not public! | ||
| 26 | //! embassy_time::timer_queue_impl!(static QUEUE: MyTimerQueue = MyTimerQueue{}); | ||
| 27 | //! | ||
| 28 | //! impl TimerQueue for MyTimerQueue { | ||
| 29 | //! fn schedule_wake(&'static self, at: Instant, waker: &Waker) { | ||
| 30 | //! todo!() | ||
| 31 | //! } | ||
| 32 | //! } | ||
| 33 | //! ``` | ||
| 34 | use core::task::Waker; | ||
| 35 | |||
| 36 | use crate::Instant; | ||
| 37 | |||
| 38 | /// Timer queue | ||
| 39 | pub trait TimerQueue { | ||
| 40 | /// Schedules a waker in the queue to be awoken at moment `at`. | ||
| 41 | /// If this moment is in the past, the waker might be awoken immediately. | ||
| 42 | fn schedule_wake(&'static self, at: Instant, waker: &Waker); | ||
| 43 | } | ||
| 44 | |||
| 45 | /// Set the TimerQueue implementation. | ||
| 46 | /// | ||
| 47 | /// See the module documentation for an example. | ||
| 48 | #[macro_export] | ||
| 49 | macro_rules! timer_queue_impl { | ||
| 50 | (static $name:ident: $t: ty = $val:expr) => { | ||
| 51 | static $name: $t = $val; | ||
| 52 | |||
| 53 | #[no_mangle] | ||
| 54 | fn _embassy_time_schedule_wake(at: $crate::Instant, waker: &core::task::Waker) { | ||
| 55 | <$t as $crate::queue::TimerQueue>::schedule_wake(&$name, at, waker); | ||
| 56 | } | ||
| 57 | }; | ||
| 58 | } | ||
