Adjust impl to latest changes
This commit is contained in:
parent
8b6b1b9559
commit
4450f67565
@ -21,7 +21,7 @@ embassy-executor = { version = "0.6.3", optional = true }
|
||||
embassy-sync = { version = "0.6.1" }
|
||||
embassy-time = { version = "0.3.0" }
|
||||
embassy-time-driver = { version = "0.1.0", features = [ "tick-hz-1_000_000" ] }
|
||||
embassy-time-queue-driver = { version = "0.1.0", features = ["generic-queue-const-generic"] }
|
||||
embassy-time-queue-driver = { version = "0.1.0" }
|
||||
esp-config = { version = "0.2.0", path = "../esp-config" }
|
||||
esp-hal = { version = "0.22.0", path = "../esp-hal" }
|
||||
log = { version = "0.4.22", optional = true }
|
||||
@ -53,7 +53,7 @@ log = ["dep:log"]
|
||||
executors = ["dep:embassy-executor", "esp-hal/__esp_hal_embassy"]
|
||||
## Use the executor-integrated `embassy-time` timer queue. If not set, the crate provides a generic
|
||||
## timer queue that can be used with any executor.
|
||||
integrated-timers = ["embassy-executor?/integrated-timers", "executors"]
|
||||
integrated-timers = ["embassy-time-queue-driver/integrated-timers", "executors"]
|
||||
## Use a single, global timer queue. This option only needs a single alarm, no matter how many
|
||||
## executors are used. Ignored if `integrated-timers` is not set.
|
||||
single-queue = []
|
||||
|
||||
@ -88,17 +88,46 @@ impl embassy_time_queue_driver::TimerQueue for crate::time_driver::TimerQueueDri
|
||||
|
||||
#[cfg(integrated_timers)]
|
||||
mod adapter {
|
||||
use core::cell::RefCell;
|
||||
|
||||
use embassy_executor::raw;
|
||||
|
||||
pub(super) type RawQueue = raw::timer_queue::TimerQueue;
|
||||
type Q = embassy_time_queue_driver::queue_integrated::TimerQueue;
|
||||
|
||||
/// A simple wrapper around a `Queue` to provide interior mutability.
|
||||
pub struct RefCellQueue {
|
||||
inner: RefCell<Q>,
|
||||
}
|
||||
|
||||
impl RefCellQueue {
|
||||
/// Creates a new timer queue.
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
inner: RefCell::new(Q::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Schedules a task to run at a specific time, and returns whether any
|
||||
/// changes were made.
|
||||
pub fn schedule_wake(&self, at: u64, waker: raw::TaskRef) -> bool {
|
||||
self.inner.borrow_mut().schedule_wake(at, waker)
|
||||
}
|
||||
|
||||
/// Dequeues expired timers and returns the next alarm time.
|
||||
pub fn next_expiration(&self, now: u64) -> u64 {
|
||||
self.inner.borrow_mut().next_expiration(now)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) type RawQueue = RefCellQueue;
|
||||
|
||||
pub(super) fn dequeue(q: &RawQueue, now: u64) -> u64 {
|
||||
unsafe { q.next_expiration(now, raw::wake_task) }
|
||||
q.next_expiration(now)
|
||||
}
|
||||
|
||||
impl super::TimerQueue {
|
||||
pub fn schedule_wake(&self, at: u64, task: raw::TaskRef) {
|
||||
if unsafe { self.inner.lock(|q| q.schedule_wake(at, task)) } {
|
||||
if self.inner.lock(|q| q.schedule_wake(at, task)) {
|
||||
self.dispatch();
|
||||
}
|
||||
}
|
||||
@ -107,12 +136,39 @@ mod adapter {
|
||||
|
||||
#[cfg(generic_timers)]
|
||||
mod adapter {
|
||||
use core::task::Waker;
|
||||
use core::{cell::RefCell, task::Waker};
|
||||
|
||||
pub(super) type RawQueue = embassy_time_queue_driver::queue_generic::RefCellQueue<
|
||||
type Q = embassy_time_queue_driver::queue_generic::ConstGenericQueue<
|
||||
{ esp_config::esp_config_int!(usize, "ESP_HAL_EMBASSY_GENERIC_QUEUE_SIZE") },
|
||||
>;
|
||||
|
||||
/// A simple wrapper around a `Queue` to provide interior mutability.
|
||||
pub struct RefCellQueue {
|
||||
inner: RefCell<Q>,
|
||||
}
|
||||
|
||||
impl RefCellQueue {
|
||||
/// Creates a new timer queue.
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
inner: RefCell::new(Q::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Schedules a task to run at a specific time, and returns whether any
|
||||
/// changes were made.
|
||||
pub fn schedule_wake(&self, at: u64, waker: &core::task::Waker) -> bool {
|
||||
self.inner.borrow_mut().schedule_wake(at, waker)
|
||||
}
|
||||
|
||||
/// Dequeues expired timers and returns the next alarm time.
|
||||
pub fn next_expiration(&self, now: u64) -> u64 {
|
||||
self.inner.borrow_mut().next_expiration(now)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) type RawQueue = RefCellQueue;
|
||||
|
||||
pub(super) fn dequeue(q: &RawQueue, now: u64) -> u64 {
|
||||
q.next_expiration(now)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user