diff options
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/rtc/mod.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs index 7289e46af..8e6aa66c9 100644 --- a/embassy-rp/src/rtc/mod.rs +++ b/embassy-rp/src/rtc/mod.rs | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | mod filter; | 2 | mod filter; |
| 3 | 3 | ||
| 4 | use core::future::poll_fn; | 4 | use core::future::poll_fn; |
| 5 | use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; | 5 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 6 | use core::task::Poll; | 6 | use core::task::Poll; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{Peri, PeripheralType}; | 8 | use embassy_hal_internal::{Peri, PeripheralType}; |
| @@ -21,8 +21,6 @@ use crate::interrupt::{self, InterruptExt}; | |||
| 21 | 21 | ||
| 22 | // Static waker for the interrupt handler | 22 | // Static waker for the interrupt handler |
| 23 | static WAKER: AtomicWaker = AtomicWaker::new(); | 23 | static WAKER: AtomicWaker = AtomicWaker::new(); |
| 24 | // Static flag to indicate if an alarm has occurred | ||
| 25 | static ALARM_OCCURRED: AtomicBool = AtomicBool::new(false); | ||
| 26 | 24 | ||
| 27 | /// A reference to the real time clock of the system | 25 | /// A reference to the real time clock of the system |
| 28 | pub struct Rtc<'d, T: Instance> { | 26 | pub struct Rtc<'d, T: Instance> { |
| @@ -259,19 +257,15 @@ impl<'d, T: Instance> Rtc<'d, T> { | |||
| 259 | poll_fn(|cx| { | 257 | poll_fn(|cx| { |
| 260 | WAKER.register(cx.waker()); | 258 | WAKER.register(cx.waker()); |
| 261 | 259 | ||
| 262 | // If the alarm has occured, we will clear the interrupt and return ready | 260 | // Check hardware interrupt status directly |
| 263 | if ALARM_OCCURRED.load(Ordering::SeqCst) { | 261 | if self.inner.regs().ints().read().rtc() { |
| 264 | // Clear the alarm occurred flag | 262 | // Clear the interrupt status and disable the alarm |
| 265 | ALARM_OCCURRED.store(false, Ordering::SeqCst); | 263 | self.inner.regs().ints().write(|w| w.set_rtc(true)); |
| 266 | |||
| 267 | // Clear the interrupt and disable the alarm | ||
| 268 | self.clear_interrupt(); | 264 | self.clear_interrupt(); |
| 269 | 265 | ||
| 270 | // Return ready | ||
| 271 | compiler_fence(Ordering::SeqCst); | 266 | compiler_fence(Ordering::SeqCst); |
| 272 | return Poll::Ready(()); | 267 | return Poll::Ready(()); |
| 273 | } else { | 268 | } else { |
| 274 | // If the alarm has not occurred, we will return pending | ||
| 275 | return Poll::Pending; | 269 | return Poll::Pending; |
| 276 | } | 270 | } |
| 277 | }) | 271 | }) |
| @@ -290,8 +284,7 @@ impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::RTC_IRQ> | |||
| 290 | let rtc = crate::pac::RTC; | 284 | let rtc = crate::pac::RTC; |
| 291 | rtc.irq_setup_0().modify(|w| w.set_match_ena(false)); | 285 | rtc.irq_setup_0().modify(|w| w.set_match_ena(false)); |
| 292 | 286 | ||
| 293 | // Set the alarm occurred flag and wake the waker | 287 | // Wake the waker - interrupt status will be checked directly by polling future |
| 294 | ALARM_OCCURRED.store(true, Ordering::SeqCst); | ||
| 295 | WAKER.wake(); | 288 | WAKER.wake(); |
| 296 | } | 289 | } |
| 297 | } | 290 | } |
