Skip to content

Commit

Permalink
Adjust impl to latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Dec 8, 2024
1 parent c0a44b7 commit 1f73ebd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion esp-hal-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 }
Expand Down
31 changes: 29 additions & 2 deletions esp-hal-embassy/src/timer_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,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)
}
Expand Down

0 comments on commit 1f73ebd

Please sign in to comment.