diff options
Diffstat (limited to 'embassy-executor/src/raw/mod.rs')
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index b16a1c7c3..d9ea5c005 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -30,9 +30,7 @@ use core::ptr::NonNull; | |||
| 30 | use core::task::{Context, Poll}; | 30 | use core::task::{Context, Poll}; |
| 31 | 31 | ||
| 32 | #[cfg(feature = "integrated-timers")] | 32 | #[cfg(feature = "integrated-timers")] |
| 33 | use embassy_time::driver::{self, AlarmHandle}; | 33 | use embassy_time_driver::AlarmHandle; |
| 34 | #[cfg(feature = "integrated-timers")] | ||
| 35 | use embassy_time::Instant; | ||
| 36 | #[cfg(feature = "rtos-trace")] | 34 | #[cfg(feature = "rtos-trace")] |
| 37 | use rtos_trace::trace; | 35 | use rtos_trace::trace; |
| 38 | 36 | ||
| @@ -50,7 +48,7 @@ pub(crate) struct TaskHeader { | |||
| 50 | poll_fn: SyncUnsafeCell<Option<unsafe fn(TaskRef)>>, | 48 | poll_fn: SyncUnsafeCell<Option<unsafe fn(TaskRef)>>, |
| 51 | 49 | ||
| 52 | #[cfg(feature = "integrated-timers")] | 50 | #[cfg(feature = "integrated-timers")] |
| 53 | pub(crate) expires_at: SyncUnsafeCell<Instant>, | 51 | pub(crate) expires_at: SyncUnsafeCell<u64>, |
| 54 | #[cfg(feature = "integrated-timers")] | 52 | #[cfg(feature = "integrated-timers")] |
| 55 | pub(crate) timer_queue_item: timer_queue::TimerQueueItem, | 53 | pub(crate) timer_queue_item: timer_queue::TimerQueueItem, |
| 56 | } | 54 | } |
| @@ -123,7 +121,7 @@ impl<F: Future + 'static> TaskStorage<F> { | |||
| 123 | poll_fn: SyncUnsafeCell::new(None), | 121 | poll_fn: SyncUnsafeCell::new(None), |
| 124 | 122 | ||
| 125 | #[cfg(feature = "integrated-timers")] | 123 | #[cfg(feature = "integrated-timers")] |
| 126 | expires_at: SyncUnsafeCell::new(Instant::from_ticks(0)), | 124 | expires_at: SyncUnsafeCell::new(0), |
| 127 | #[cfg(feature = "integrated-timers")] | 125 | #[cfg(feature = "integrated-timers")] |
| 128 | timer_queue_item: timer_queue::TimerQueueItem::new(), | 126 | timer_queue_item: timer_queue::TimerQueueItem::new(), |
| 129 | }, | 127 | }, |
| @@ -164,7 +162,7 @@ impl<F: Future + 'static> TaskStorage<F> { | |||
| 164 | this.raw.state.despawn(); | 162 | this.raw.state.despawn(); |
| 165 | 163 | ||
| 166 | #[cfg(feature = "integrated-timers")] | 164 | #[cfg(feature = "integrated-timers")] |
| 167 | this.raw.expires_at.set(Instant::MAX); | 165 | this.raw.expires_at.set(u64::MAX); |
| 168 | } | 166 | } |
| 169 | Poll::Pending => {} | 167 | Poll::Pending => {} |
| 170 | } | 168 | } |
| @@ -328,7 +326,7 @@ pub(crate) struct SyncExecutor { | |||
| 328 | impl SyncExecutor { | 326 | impl SyncExecutor { |
| 329 | pub(crate) fn new(pender: Pender) -> Self { | 327 | pub(crate) fn new(pender: Pender) -> Self { |
| 330 | #[cfg(feature = "integrated-timers")] | 328 | #[cfg(feature = "integrated-timers")] |
| 331 | let alarm = unsafe { unwrap!(driver::allocate_alarm()) }; | 329 | let alarm = unsafe { unwrap!(embassy_time_driver::allocate_alarm()) }; |
| 332 | 330 | ||
| 333 | Self { | 331 | Self { |
| 334 | run_queue: RunQueue::new(), | 332 | run_queue: RunQueue::new(), |
| @@ -377,18 +375,19 @@ impl SyncExecutor { | |||
| 377 | /// Same as [`Executor::poll`], plus you must only call this on the thread this executor was created. | 375 | /// Same as [`Executor::poll`], plus you must only call this on the thread this executor was created. |
| 378 | pub(crate) unsafe fn poll(&'static self) { | 376 | pub(crate) unsafe fn poll(&'static self) { |
| 379 | #[cfg(feature = "integrated-timers")] | 377 | #[cfg(feature = "integrated-timers")] |
| 380 | driver::set_alarm_callback(self.alarm, Self::alarm_callback, self as *const _ as *mut ()); | 378 | embassy_time_driver::set_alarm_callback(self.alarm, Self::alarm_callback, self as *const _ as *mut ()); |
| 381 | 379 | ||
| 382 | #[allow(clippy::never_loop)] | 380 | #[allow(clippy::never_loop)] |
| 383 | loop { | 381 | loop { |
| 384 | #[cfg(feature = "integrated-timers")] | 382 | #[cfg(feature = "integrated-timers")] |
| 385 | self.timer_queue.dequeue_expired(Instant::now(), wake_task_no_pend); | 383 | self.timer_queue |
| 384 | .dequeue_expired(embassy_time_driver::now(), wake_task_no_pend); | ||
| 386 | 385 | ||
| 387 | self.run_queue.dequeue_all(|p| { | 386 | self.run_queue.dequeue_all(|p| { |
| 388 | let task = p.header(); | 387 | let task = p.header(); |
| 389 | 388 | ||
| 390 | #[cfg(feature = "integrated-timers")] | 389 | #[cfg(feature = "integrated-timers")] |
| 391 | task.expires_at.set(Instant::MAX); | 390 | task.expires_at.set(u64::MAX); |
| 392 | 391 | ||
| 393 | if !task.state.run_dequeue() { | 392 | if !task.state.run_dequeue() { |
| 394 | // If task is not running, ignore it. This can happen in the following scenario: | 393 | // If task is not running, ignore it. This can happen in the following scenario: |
| @@ -418,7 +417,7 @@ impl SyncExecutor { | |||
| 418 | // If this is already in the past, set_alarm might return false | 417 | // If this is already in the past, set_alarm might return false |
| 419 | // In that case do another poll loop iteration. | 418 | // In that case do another poll loop iteration. |
| 420 | let next_expiration = self.timer_queue.next_expiration(); | 419 | let next_expiration = self.timer_queue.next_expiration(); |
| 421 | if driver::set_alarm(self.alarm, next_expiration.as_ticks()) { | 420 | if embassy_time_driver::set_alarm(self.alarm, next_expiration) { |
| 422 | break; | 421 | break; |
| 423 | } | 422 | } |
| 424 | } | 423 | } |
| @@ -568,8 +567,8 @@ pub fn wake_task_no_pend(task: TaskRef) { | |||
| 568 | struct TimerQueue; | 567 | struct TimerQueue; |
| 569 | 568 | ||
| 570 | #[cfg(feature = "integrated-timers")] | 569 | #[cfg(feature = "integrated-timers")] |
| 571 | impl embassy_time::queue::TimerQueue for TimerQueue { | 570 | impl embassy_time_queue_driver::TimerQueue for TimerQueue { |
| 572 | fn schedule_wake(&'static self, at: Instant, waker: &core::task::Waker) { | 571 | fn schedule_wake(&'static self, at: u64, waker: &core::task::Waker) { |
| 573 | let task = waker::task_from_waker(waker); | 572 | let task = waker::task_from_waker(waker); |
| 574 | let task = task.header(); | 573 | let task = task.header(); |
| 575 | unsafe { | 574 | unsafe { |
| @@ -580,7 +579,16 @@ impl embassy_time::queue::TimerQueue for TimerQueue { | |||
| 580 | } | 579 | } |
| 581 | 580 | ||
| 582 | #[cfg(feature = "integrated-timers")] | 581 | #[cfg(feature = "integrated-timers")] |
| 583 | embassy_time::timer_queue_impl!(static TIMER_QUEUE: TimerQueue = TimerQueue); | 582 | embassy_time_queue_driver::timer_queue_impl!(static TIMER_QUEUE: TimerQueue = TimerQueue); |
| 583 | |||
| 584 | #[cfg(all(feature = "rtos-trace", feature = "integrated-timers"))] | ||
| 585 | const fn gcd(a: u64, b: u64) -> u64 { | ||
| 586 | if b == 0 { | ||
| 587 | a | ||
| 588 | } else { | ||
| 589 | gcd(b, a % b) | ||
| 590 | } | ||
| 591 | } | ||
| 584 | 592 | ||
| 585 | #[cfg(feature = "rtos-trace")] | 593 | #[cfg(feature = "rtos-trace")] |
| 586 | impl rtos_trace::RtosTraceOSCallbacks for Executor { | 594 | impl rtos_trace::RtosTraceOSCallbacks for Executor { |
| @@ -589,7 +597,8 @@ impl rtos_trace::RtosTraceOSCallbacks for Executor { | |||
| 589 | } | 597 | } |
| 590 | #[cfg(feature = "integrated-timers")] | 598 | #[cfg(feature = "integrated-timers")] |
| 591 | fn time() -> u64 { | 599 | fn time() -> u64 { |
| 592 | Instant::now().as_micros() | 600 | const GCD_1M: u64 = gcd(embassy_time_driver::TICK_HZ, 1_000_000); |
| 601 | embassy_time_driver::now() * (1_000_000 / GCD_1M) / (embassy_time_driver::TICK_HZ / GCD_1M) | ||
| 593 | } | 602 | } |
| 594 | #[cfg(not(feature = "integrated-timers"))] | 603 | #[cfg(not(feature = "integrated-timers"))] |
| 595 | fn time() -> u64 { | 604 | fn time() -> u64 { |
