@@ -380,13 +380,15 @@ impl RtcDriver {
380380 #[ cfg( feature = "low-power" ) ]
381381 /// Stop the wakeup alarm, if enabled, and add the appropriate offset
382382 fn stop_wakeup_alarm ( & self , cs : CriticalSection ) {
383- if let Some ( offset) = self . rtc . borrow ( cs) . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . stop_wakeup_alarm ( cs) {
383+ if !regs_gp16 ( ) . cr1 ( ) . read ( ) . cen ( )
384+ && let Some ( offset) = self . rtc . borrow ( cs) . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . stop_wakeup_alarm ( cs)
385+ {
384386 self . add_time ( offset, cs) ;
385387 }
386388 }
387389
388390 /*
389- Low-power public functions: all create or require a critical section
391+ Low-power public functions: all require a critical section
390392 */
391393 #[ cfg( feature = "low-power" ) ]
392394 pub ( crate ) fn set_min_stop_pause ( & self , cs : CriticalSection , min_stop_pause : embassy_time:: Duration ) {
@@ -403,49 +405,36 @@ impl RtcDriver {
403405
404406 #[ cfg( feature = "low-power" ) ]
405407 /// Pause the timer if ready; return err if not
406- pub ( crate ) fn pause_time ( & self ) -> Result < ( ) , ( ) > {
407- critical_section:: with ( |cs| {
408- /*
409- If the wakeup timer is currently running, then we need to stop it and
410- add the elapsed time to the current time, as this will impact the result
411- of `time_until_next_alarm`.
412- */
413- self . stop_wakeup_alarm ( cs) ;
414-
415- let time_until_next_alarm = self . time_until_next_alarm ( cs) ;
416- if time_until_next_alarm < self . min_stop_pause . borrow ( cs) . get ( ) {
417- trace ! (
418- "time_until_next_alarm < self.min_stop_pause ({})" ,
419- time_until_next_alarm
420- ) ;
421- Err ( ( ) )
422- } else {
423- self . rtc
424- . borrow ( cs)
425- . borrow_mut ( )
426- . as_mut ( )
427- . unwrap ( )
428- . start_wakeup_alarm ( time_until_next_alarm, cs) ;
429-
430- regs_gp16 ( ) . cr1 ( ) . modify ( |w| w. set_cen ( false ) ) ;
431- // save the count for the timer as its lost in STOP2 for stm32wlex
432- #[ cfg( stm32wlex) ]
433- self . saved_count
434- . store ( regs_gp16 ( ) . cnt ( ) . read ( ) . cnt ( ) as u16 , Ordering :: SeqCst ) ;
435- Ok ( ( ) )
436- }
437- } )
408+ pub ( crate ) fn pause_time ( & self , cs : CriticalSection ) -> Result < ( ) , ( ) > {
409+ self . stop_wakeup_alarm ( cs) ;
410+
411+ let time_until_next_alarm = self . time_until_next_alarm ( cs) ;
412+ if time_until_next_alarm < self . min_stop_pause . borrow ( cs) . get ( ) {
413+ trace ! (
414+ "time_until_next_alarm < self.min_stop_pause ({})" ,
415+ time_until_next_alarm
416+ ) ;
417+ Err ( ( ) )
418+ } else {
419+ self . rtc
420+ . borrow ( cs)
421+ . borrow_mut ( )
422+ . as_mut ( )
423+ . unwrap ( )
424+ . start_wakeup_alarm ( time_until_next_alarm, cs) ;
425+
426+ regs_gp16 ( ) . cr1 ( ) . modify ( |w| w. set_cen ( false ) ) ;
427+ // save the count for the timer as its lost in STOP2 for stm32wlex
428+ #[ cfg( stm32wlex) ]
429+ self . saved_count
430+ . store ( regs_gp16 ( ) . cnt ( ) . read ( ) . cnt ( ) as u16 , Ordering :: SeqCst ) ;
431+ Ok ( ( ) )
432+ }
438433 }
439434
440435 #[ cfg( feature = "low-power" ) ]
441436 /// Resume the timer with the given offset
442437 pub ( crate ) fn resume_time ( & self , cs : CriticalSection ) {
443- if regs_gp16 ( ) . cr1 ( ) . read ( ) . cen ( ) {
444- // Time isn't currently stopped
445-
446- return ;
447- }
448-
449438 self . stop_wakeup_alarm ( cs) ;
450439
451440 regs_gp16 ( ) . cr1 ( ) . modify ( |w| w. set_cen ( true ) ) ;
0 commit comments