Struct Lptim1Rtc

Source
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

Source

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.

Source

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.

Source

pub fn get_time(&self) -> u32

Get the current time.

Source

pub fn set_alarm(&mut self, deadline: u32) -> Result<(), DeadlinePassed>

Set the alarm for some time on or after a specific deadline.

Source

pub fn clear_alarm(&mut self)

Clear the alarm, regardless of being set.

Source

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.

Source

pub fn get_fraction(&self) -> u32

Get a fraction from 0x0000 to 0xFFFF relative to time.

Trait Implementations§

Source§

impl Drop for Lptim1Rtc

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Timer for Lptim1Rtc

Source§

const DELTA: Self::Duration = {transmute(0x00000002): <impls::stm32l4x6_lptim1::Lptim1Rtc as Timer>::Duration}

A minimal time increment, i.e. the time it takes to execute a handful of instructions. Read more
Source§

type Instant = InstantU32

A moment in time. Read more
Source§

type Duration = DurationU32

A length of time. Read more
Source§

fn reset(&mut self)

Initialize the clock and start counting. Read more
Source§

fn interrupt_free<F: FnOnce(&CriticalSection) -> R, R>(f: F) -> R

Execute the function in an interrupt free critical section. Read more
Source§

fn now(&self) -> Self::Instant

Yield the current time.
Source§

fn disarm(&mut self)

Disarm the set alarm.
Source§

fn arm(&mut self, deadline: &Self::Instant)

Set the alarm for a given time.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.