Skip to main content

Timer

Struct Timer 

Source
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

Source

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

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

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.

Source

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.

Source

pub fn info(&self) -> Result<TimerProp>

Retrieves information about this timer.

Must not be called from the context of a timer callback.

Trait Implementations§

Source§

impl Debug for Timer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Timer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Timer

§

impl RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnsafeUnpin 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.