pub struct Timer { /* private fields */ }Expand description
A handle to an OSAL timer.
This is a wrapper around an osal_id_t that will automatically call
OS_TimerDelete when it goes out of scope, preventing resource leaks.
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn new(name: &str, callback: TimerCallback) -> Result<(Self, u32)>
pub fn new(name: &str, callback: TimerCallback) -> Result<(Self, u32)>
Creates a new OSAL timer and associates it with a callback function.
This also creates a dedicated hidden time base object (consuming a resource slot) that is deleted when the timer is dropped.
On success, returns the Timer instance and the clock
accuracy in microseconds. The timer does not start until
set is called.
Must not be called from the context of a timer callback.
§Arguments
name: A unique string to identify the timer.callback: The function to be executed when the timer expires.
Sourcepub fn set(&self, start_time_usecs: u32, interval_time_usecs: u32) -> Result<()>
pub fn set(&self, start_time_usecs: u32, interval_time_usecs: u32) -> Result<()>
Programs the timer for a one-shot or periodic execution.
Both start_time_usecs and interval_time_usecs being zero
is an error. Values below the clock accuracy are rounded up
to the timer’s resolution.
Must not be called from the context of a timer callback.
§Arguments
start_time_usecs: Time in microseconds until the first expiration.interval_time_usecs: Time in microseconds between subsequent expirations. If set to 0, the timer is a one-shot timer and will only fire once.
Sourcepub fn get_id_by_name(name: &str) -> Result<u32>
pub fn get_id_by_name(name: &str) -> Result<u32>
Finds an existing timer ID by its name.
Must not be called from the context of a timer callback.
Sourcepub fn add(
name: &str,
timebase_id: TimeBaseId,
callback: TimerArgCallback,
callback_arg: *mut c_void,
) -> Result<Self>
pub fn add( name: &str, timebase_id: TimeBaseId, callback: TimerArgCallback, callback_arg: *mut c_void, ) -> Result<Self>
Creates a new OSAL timer and attaches it to an existing time base.
This allows multiple timers to share a single underlying timing source.