mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-28 21:01:06 +00:00
Merge pull request #3697 from tones111/time_driver_example
fix embassy-time-driver example
This commit is contained in:
commit
dc9a83b9b3
@ -368,3 +368,7 @@ tick-hz-5_242_880_000 = []
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
document-features = "0.2.7"
|
document-features = "0.2.7"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
critical-section = "1"
|
||||||
|
embassy-time-queue-utils = { path = "../embassy-time-queue-utils" }
|
@ -49,15 +49,16 @@
|
|||||||
//! Note that if you are using multiple queues, you will need to ensure that a single timer
|
//! Note that if you are using multiple queues, you will need to ensure that a single timer
|
||||||
//! queue item is only ever enqueued into a single queue at a time.
|
//! queue item is only ever enqueued into a single queue at a time.
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```
|
||||||
//! use core::cell::RefCell;
|
//! use core::cell::RefCell;
|
||||||
//! use core::task::Waker;
|
//! use core::task::Waker;
|
||||||
//!
|
//!
|
||||||
|
//! use critical_section::{CriticalSection, Mutex};
|
||||||
//! use embassy_time_queue_utils::Queue;
|
//! use embassy_time_queue_utils::Queue;
|
||||||
//! use embassy_time_driver::Driver;
|
//! use embassy_time_driver::Driver;
|
||||||
//!
|
//!
|
||||||
//! struct MyDriver {
|
//! struct MyDriver {
|
||||||
//! timer_queue: critical_section::Mutex<RefCell<Queue>>,
|
//! queue: Mutex<RefCell<Queue>>,
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! impl MyDriver {
|
//! impl MyDriver {
|
||||||
@ -67,14 +68,14 @@
|
|||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! impl Driver for MyDriver {
|
//! impl Driver for MyDriver {
|
||||||
//! // fn now(&self) -> u64 { ... }
|
//! fn now(&self) -> u64 { todo!() }
|
||||||
//!
|
//!
|
||||||
//! fn schedule_wake(&self, at: u64, waker: &Waker) {
|
//! fn schedule_wake(&self, at: u64, waker: &Waker) {
|
||||||
//! critical_section::with(|cs| {
|
//! critical_section::with(|cs| {
|
||||||
//! let mut queue = self.queue.borrow(cs).borrow_mut();
|
//! let mut queue = self.queue.borrow(cs).borrow_mut();
|
||||||
//! if queue.schedule_wake(at, waker) {
|
//! if queue.schedule_wake(at, waker) {
|
||||||
//! let mut next = queue.next_expiration(self.now());
|
//! let mut next = queue.next_expiration(self.now());
|
||||||
//! while !self.set_alarm(cs, next) {
|
//! while !self.set_alarm(&cs, next) {
|
||||||
//! next = queue.next_expiration(self.now());
|
//! next = queue.next_expiration(self.now());
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user