diff options
| author | xoviat <[email protected]> | 2025-11-03 13:02:08 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-03 13:02:08 -0600 |
| commit | d25b5ce3bec44f4a023403a8b479e034d8386275 (patch) | |
| tree | 6e2b523d4ce32f72c09d1dd60ab0cf357349f10c /embassy-stm32/src/time_driver.rs | |
| parent | 500181ac28039858d032d10932462c1e432c0452 (diff) | |
low_power: update api to allow reconfig
Diffstat (limited to 'embassy-stm32/src/time_driver.rs')
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 74b10a183..7fd5751b3 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -213,7 +213,7 @@ pub(crate) struct RtcDriver { | |||
| 213 | period: AtomicU32, | 213 | period: AtomicU32, |
| 214 | alarm: Mutex<CriticalSectionRawMutex, AlarmState>, | 214 | alarm: Mutex<CriticalSectionRawMutex, AlarmState>, |
| 215 | #[cfg(feature = "low-power")] | 215 | #[cfg(feature = "low-power")] |
| 216 | rtc: Mutex<CriticalSectionRawMutex, Cell<Option<&'static Rtc>>>, | 216 | rtc: Mutex<CriticalSectionRawMutex, RefCell<Option<Rtc>>>, |
| 217 | queue: Mutex<CriticalSectionRawMutex, RefCell<Queue>>, | 217 | queue: Mutex<CriticalSectionRawMutex, RefCell<Queue>>, |
| 218 | } | 218 | } |
| 219 | 219 | ||
| @@ -221,7 +221,7 @@ embassy_time_driver::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { | |||
| 221 | period: AtomicU32::new(0), | 221 | period: AtomicU32::new(0), |
| 222 | alarm: Mutex::const_new(CriticalSectionRawMutex::new(), AlarmState::new()), | 222 | alarm: Mutex::const_new(CriticalSectionRawMutex::new(), AlarmState::new()), |
| 223 | #[cfg(feature = "low-power")] | 223 | #[cfg(feature = "low-power")] |
| 224 | rtc: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)), | 224 | rtc: Mutex::const_new(CriticalSectionRawMutex::new(), RefCell::new(None)), |
| 225 | queue: Mutex::new(RefCell::new(Queue::new())) | 225 | queue: Mutex::new(RefCell::new(Queue::new())) |
| 226 | }); | 226 | }); |
| 227 | 227 | ||
| @@ -379,7 +379,7 @@ impl RtcDriver { | |||
| 379 | #[cfg(feature = "low-power")] | 379 | #[cfg(feature = "low-power")] |
| 380 | /// Stop the wakeup alarm, if enabled, and add the appropriate offset | 380 | /// Stop the wakeup alarm, if enabled, and add the appropriate offset |
| 381 | fn stop_wakeup_alarm(&self, cs: CriticalSection) { | 381 | fn stop_wakeup_alarm(&self, cs: CriticalSection) { |
| 382 | if let Some(offset) = self.rtc.borrow(cs).get().unwrap().stop_wakeup_alarm(cs) { | 382 | if let Some(offset) = self.rtc.borrow(cs).borrow_mut().as_mut().unwrap().stop_wakeup_alarm(cs) { |
| 383 | self.add_time(offset, cs); | 383 | self.add_time(offset, cs); |
| 384 | } | 384 | } |
| 385 | } | 385 | } |
| @@ -389,7 +389,7 @@ impl RtcDriver { | |||
| 389 | */ | 389 | */ |
| 390 | #[cfg(feature = "low-power")] | 390 | #[cfg(feature = "low-power")] |
| 391 | /// Set the rtc but panic if it's already been set | 391 | /// Set the rtc but panic if it's already been set |
| 392 | pub(crate) fn set_rtc(&self, rtc: &'static Rtc) { | 392 | pub(crate) fn set_rtc(&self, mut rtc: Rtc) { |
| 393 | critical_section::with(|cs| { | 393 | critical_section::with(|cs| { |
| 394 | rtc.stop_wakeup_alarm(cs); | 394 | rtc.stop_wakeup_alarm(cs); |
| 395 | 395 | ||
| @@ -398,6 +398,12 @@ impl RtcDriver { | |||
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | #[cfg(feature = "low-power")] | 400 | #[cfg(feature = "low-power")] |
| 401 | /// Set the rtc but panic if it's already been set | ||
| 402 | pub(crate) fn reconfigure_rtc(&self, f: impl FnOnce(&mut Rtc)) { | ||
| 403 | critical_section::with(|cs| f(self.rtc.borrow(cs).borrow_mut().as_mut().unwrap())); | ||
| 404 | } | ||
| 405 | |||
| 406 | #[cfg(feature = "low-power")] | ||
| 401 | /// The minimum pause time beyond which the executor will enter a low-power state. | 407 | /// The minimum pause time beyond which the executor will enter a low-power state. |
| 402 | pub(crate) const MIN_STOP_PAUSE: embassy_time::Duration = embassy_time::Duration::from_millis(250); | 408 | pub(crate) const MIN_STOP_PAUSE: embassy_time::Duration = embassy_time::Duration::from_millis(250); |
| 403 | 409 | ||
| @@ -418,7 +424,8 @@ impl RtcDriver { | |||
| 418 | } else { | 424 | } else { |
| 419 | self.rtc | 425 | self.rtc |
| 420 | .borrow(cs) | 426 | .borrow(cs) |
| 421 | .get() | 427 | .borrow_mut() |
| 428 | .as_mut() | ||
| 422 | .unwrap() | 429 | .unwrap() |
| 423 | .start_wakeup_alarm(time_until_next_alarm, cs); | 430 | .start_wakeup_alarm(time_until_next_alarm, cs); |
| 424 | 431 | ||
