diff options
| author | Dániel Buga <[email protected]> | 2024-12-15 19:24:49 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-12-15 19:24:49 +0100 |
| commit | 0492dba5368e7cb22ede2d41d26d4d0431ba2252 (patch) | |
| tree | 735ad32cd3f40acbc57248373ab2622c8a9a03e3 /embassy-time-queue-driver/src/lib.rs | |
| parent | e861344b179b3e955ac47f1985b7f97fdfb93892 (diff) | |
Update documentation and changelogs
Diffstat (limited to 'embassy-time-queue-driver/src/lib.rs')
| -rw-r--r-- | embassy-time-queue-driver/src/lib.rs | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/embassy-time-queue-driver/src/lib.rs b/embassy-time-queue-driver/src/lib.rs index 46dd646ca..d8b01df3b 100644 --- a/embassy-time-queue-driver/src/lib.rs +++ b/embassy-time-queue-driver/src/lib.rs | |||
| @@ -2,52 +2,13 @@ | |||
| 2 | #![doc = include_str!("../README.md")] | 2 | #![doc = include_str!("../README.md")] |
| 3 | #![warn(missing_docs)] | 3 | #![warn(missing_docs)] |
| 4 | 4 | ||
| 5 | //! ## Implementing a timer queue | 5 | //! This crate is an implementation detail of `embassy-time-driver`. |
| 6 | //! | 6 | //! |
| 7 | //! - Define a struct `MyTimerQueue` | 7 | //! As a HAL user, you should only depend on this crate if your application does not use |
| 8 | //! - Implement [`TimerQueue`] for it | 8 | //! `embassy-executor` and your HAL does not configure a generic queue by itself. |
| 9 | //! - Register it as the global timer queue with [`timer_queue_impl`]. | ||
| 10 | //! - Ensure that you process the timer queue when `schedule_wake` is due. This usually involves | ||
| 11 | //! waking expired tasks, finding the next expiration time and setting an alarm. | ||
| 12 | //! | 9 | //! |
| 13 | //! If a single global timer queue is sufficient for you, you can use the | 10 | //! As a HAL implementer, you need to depend on this crate if you want to implement a time driver, |
| 14 | //! [`GlobalTimerQueue`] type, which is a wrapper around a global timer queue | 11 | //! but how you should do so is documented in [`embassy_time_driver`]. |
| 15 | //! protected by a critical section. | ||
| 16 | //! | ||
| 17 | //! ``` | ||
| 18 | //! use embassy_time_queue_driver::GlobalTimerQueue; | ||
| 19 | //! embassy_time_queue_driver::timer_queue_impl!( | ||
| 20 | //! static TIMER_QUEUE_DRIVER: GlobalTimerQueue | ||
| 21 | //! = GlobalTimerQueue::new(|next_expiration| todo!("Set an alarm")) | ||
| 22 | //! ); | ||
| 23 | //! ``` | ||
| 24 | //! | ||
| 25 | //! You can also use the `queue_generic` or the `queue_integrated` modules to implement your own | ||
| 26 | //! timer queue. These modules contain queue implementations which you can wrap and tailor to | ||
| 27 | //! your needs. | ||
| 28 | //! | ||
| 29 | //! If you are providing an embassy-executor implementation besides a timer queue, you can choose to | ||
| 30 | //! expose the `integrated-timers` feature in your implementation. This feature stores timer items | ||
| 31 | //! in the tasks themselves, so you don't need a fixed-size queue or dynamic memory allocation. | ||
| 32 | //! | ||
| 33 | //! ## Example | ||
| 34 | //! | ||
| 35 | //! ``` | ||
| 36 | //! use core::task::Waker; | ||
| 37 | //! | ||
| 38 | //! use embassy_time::Instant; | ||
| 39 | //! use embassy_time::queue::TimerQueue; | ||
| 40 | //! | ||
| 41 | //! struct MyTimerQueue{}; // not public! | ||
| 42 | //! | ||
| 43 | //! impl TimerQueue for MyTimerQueue { | ||
| 44 | //! fn schedule_wake(&'static self, at: u64, waker: &Waker) { | ||
| 45 | //! todo!() | ||
| 46 | //! } | ||
| 47 | //! } | ||
| 48 | //! | ||
| 49 | //! embassy_time_queue_driver::timer_queue_impl!(static QUEUE: MyTimerQueue = MyTimerQueue{}); | ||
| 50 | //! ``` | ||
| 51 | 12 | ||
| 52 | use core::task::Waker; | 13 | use core::task::Waker; |
| 53 | 14 | ||
