Timer

Struct Timer 

Source
pub struct Timer { /* private fields */ }
Expand description

A 64-bit timer based on SysTick.

Stores wraparounds in 2 32-bit atomics. Scales the systick counts to arbitrary frequency.

Implementations§

Source§

impl Timer

Source

pub fn systick_handler(&self)

SysTick handler.

Call this from the SysTick interrupt handler.

Source

pub fn now(&self) -> u64

Robust now() (VAL-jump tie-breaker, no COUNTFLAG dependency).

§Design: One-Wrap Compensation via PendST Detection

This implementation is designed to handle exactly one missed SysTick wrap.

How it works:

  1. Uses PendST bit to detect when the SysTick ISR is pending (hardware wrapped but ISR hasn’t run)
  2. If PendST is set, adds +1 to the wrap count to compensate for the missed wrap
  3. This allows monotonic time even when the ISR is delayed by up to one full wrap period

Design limit: If the SysTick ISR is starved for MORE than one complete wrap period, this compensation becomes insufficient and monotonic violations occur. The ISR starvation detection logic in diagnose_timing_violation() identifies these as catastrophic “N+1 missed wraps”.

Source

pub fn get_syst(&self) -> u32

Returns the current SysTick counter value.

Source

pub const fn reload_value(&self) -> u32

Returns the SysTick reload value configured for this timer.

Source

pub const fn tick_hz(&self) -> u64

Returns the output tick frequency in Hz.

Source

pub const fn new(tick_hz: u64, reload_value: u32, systick_freq: u64) -> Self

Creates a new timer that converts SysTick cycles to ticks at a specified frequency.

§Arguments
  • tick_hz - The desired output frequency in Hz (e.g., 1000 for millisecond ticks)
  • reload_value - The SysTick reload value. Must be between 1 and 2^24-1. This determines how many cycles occur between interrupts.
  • systick_freq - The frequency of the SysTick counter in Hz (typically CPU frequency)
§Panics
  • If reload_value is 0 or greater than 2^24-1 (16,777,215)
  • If systick_freq is 0
§Examples
// Create a millisecond-resolution timer on a 48MHz CPU with reload value of 47,999
let timer = Timer::new(1000, 47_999, 48_000_000);
Source

pub fn start(&self, syst: &mut SYST)

Call this if you haven’t already started the timer.

Auto Trait Implementations§

§

impl !Freeze for Timer

§

impl RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnwindSafe for Timer

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, 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.