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§
Sourceunsafe fn init(&mut self, config: &TimerConfig) -> Result<(), TimerError>
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.
Sourcefn start(&mut self) -> Result<(), TimerError>
fn start(&mut self) -> Result<(), TimerError>
Start the timer.
The timer will begin generating interrupts at the configured frequency.
Sourcefn stop(&mut self) -> Result<(), TimerError>
fn stop(&mut self) -> Result<(), TimerError>
Stop the timer.
This stops interrupt generation but preserves timer configuration.
Sourcefn current_count(&self) -> u64
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.
Sourcefn counts_to_nanos(&self, counts: u64) -> u64
fn counts_to_nanos(&self, counts: u64) -> u64
Convert timer counts to nanoseconds.
Sourcefn nanos_to_counts(&self, nanos: u64) -> u64
fn nanos_to_counts(&self, nanos: u64) -> u64
Convert nanoseconds to timer counts.
Sourcefn set_oneshot(&mut self, duration: Duration) -> Result<(), TimerError>
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.