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 systick_interrupt_for_nested(&self)

Interrupt handler for nested interrupts.

Call this instead of systick_handler from the interrupt handler, if you have nested interrupts enabled.

Source

pub fn now(&self) -> u64

Returns the current 64-bit tick count, scaled to the configured frequency tick_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.