Timer

Trait Timer 

Source
pub trait Timer {
    // Required methods
    unsafe fn init(&mut self, config: &TimerConfig) -> Result<(), TimerError>;
    fn start(&mut self) -> Result<(), TimerError>;
    fn stop(&mut self) -> Result<(), TimerError>;
    fn current_count(&self) -> u64;
    fn counts_to_nanos(&self, counts: u64) -> u64;
    fn nanos_to_counts(&self, nanos: u64) -> u64;
    fn set_oneshot(&mut self, duration: Duration) -> Result<(), TimerError>;
}
Expand description

Timer abstraction for different hardware timers.

Required Methods§

Source

unsafe fn init(&mut self, config: &TimerConfig) -> Result<(), TimerError>

Initialize the timer with the given configuration.

§Safety

This function configures hardware timers and interrupt vectors. It must only be called once during system initialization with interrupts disabled.

Source

fn start(&mut self) -> Result<(), TimerError>

Start the timer.

The timer will begin generating interrupts at the configured frequency.

Source

fn stop(&mut self) -> Result<(), TimerError>

Stop the timer.

This stops interrupt generation but preserves timer configuration.

Source

fn current_count(&self) -> u64

Get the current timer count.

This provides access to the hardware timer’s current count value for high-precision timing measurements.

Source

fn counts_to_nanos(&self, counts: u64) -> u64

Convert timer counts to nanoseconds.

Source

fn nanos_to_counts(&self, nanos: u64) -> u64

Convert nanoseconds to timer counts.

Source

fn set_oneshot(&mut self, duration: Duration) -> Result<(), TimerError>

Set up a one-shot timer for the given duration.

This is used for implementing sleep and timeout functionality.

Implementors§