pub struct Lptim1Rtc { /* private fields */ }
Expand description
A low-level Real Time Clock with alarms implemented with the LPTIM1 peripheral.
Note: call handle_interrupt
in the LPTIM1 interrupt.
Uses the LSI to yield a 32Khz operating speed. Uses 16 bit time segments to create 32 bit time at 32Khz, yielding a total operating time of 1.5 days. The time will wrap around when saturated, but care must be taken to properly wrap around deadlines as well. Currently wrapped around deadlines will trigger immediately. During the lifetime of this timer 3 interrupts will be triggered:
- ARR, once the 16 bit internal counter wraps around.
- CMP, to handle deadlines.
- CMPOK, when new deadlines have been uploaded to the timer.
You can extend the 1.5 days operating time by either making time an U64, or by adjusting the prescaler or source clock to a lower operating frequency.
Operates fine with the STOP2 sleep mode.
Implementations§
Source§impl Lptim1Rtc
impl Lptim1Rtc
Sourcepub fn new(timer: LPTIM1, rcc: &RCC) -> Self
pub fn new(timer: LPTIM1, rcc: &RCC) -> Self
Set up the heartbeat timer and interrupt.
Wakes the CPU at least every 2 seconds to update the time, and more often when necessary. Enables casually running sleep or stop2 whilst using async delays.
Sourcepub fn start_timer(&mut self)
pub fn start_timer(&mut self)
Start the timer, starting with fraction count
.
We will expect a CMPOK interrupt soon after this call. Hence make sure that the handle_interrupt is already callable
from the interrupt when calling start_timer
.
Sourcepub fn set_alarm(&mut self, deadline: u32) -> Result<(), DeadlinePassed>
pub fn set_alarm(&mut self, deadline: u32) -> Result<(), DeadlinePassed>
Set the alarm for some time on or after a specific deadline.
Sourcepub fn clear_alarm(&mut self)
pub fn clear_alarm(&mut self)
Clear the alarm, regardless of being set.
Sourcepub fn handle_interrupt(&mut self) -> bool
pub fn handle_interrupt(&mut self) -> bool
Handle LPTIM1 interrupt, both to update time and a signal a possible alarm.
Returns whether an alarm was triggered. Needs to be run in interrupt-free context.
Sourcepub fn get_fraction(&self) -> u32
pub fn get_fraction(&self) -> u32
Get a fraction from 0x0000 to 0xFFFF relative to time.