[][src]Trait kernel::hil::time::Timer

pub trait Timer<'a>: Time {
    pub fn set_timer_client(&'a self, client: &'a dyn TimerClient);
pub fn oneshot(&'a self, interval: Self::Ticks) -> Self::Ticks;
pub fn repeating(&'a self, interval: Self::Ticks) -> Self::Ticks;
pub fn interval(&self) -> Option<Self::Ticks>;
pub fn is_oneshot(&self) -> bool;
pub fn is_repeating(&self) -> bool;
pub fn time_remaining(&self) -> Option<Self::Ticks>;
pub fn is_enabled(&self) -> bool;
pub fn cancel(&self) -> ReturnCode; }

Interface for controlling callbacks when an interval has passed. This interface is intended for software that requires repeated and/or one-shot timers and is willing to experience some jitter or imprecision in return for a simpler API that doesn't require actual calculation of counter values. Software that requires more precisely timed callbacks should use the Alarm trait instead.

Required methods

pub fn set_timer_client(&'a self, client: &'a dyn TimerClient)[src]

Specify the callback to invoke when the timer interval expires. If there was a previously installed callback this call replaces it.

pub fn oneshot(&'a self, interval: Self::Ticks) -> Self::Ticks[src]

Start a one-shot timer that will invoke the callback at least interval ticks in the future. If there is a timer currently pending, calling this cancels that previous timer. After a callback is invoked for a one shot timer, the timer MUST NOT invoke the callback again unless a new timer is started (either with repeating or one shot). Returns the actual interval for the timer that was registered. This MUST NOT be smaller than interval but MAY be larger.

pub fn repeating(&'a self, interval: Self::Ticks) -> Self::Ticks[src]

Start a repeating timer that will invoke the callback every interval ticks in the future. If there is a timer currently pending, calling this cancels that previous timer. Returns the actual interval for the timer that was registered. This MUST NOT be smaller than interval but MAY be larger.

pub fn interval(&self) -> Option<Self::Ticks>[src]

Return the interval of the last requested timer.

pub fn is_oneshot(&self) -> bool[src]

Return if the last requested timer is a one-shot timer.

pub fn is_repeating(&self) -> bool[src]

Return if the last requested timer is a repeating timer.

pub fn time_remaining(&self) -> Option<Self::Ticks>[src]

Return how many ticks are remaining until the next callback, or None if the timer is disabled. This call is useful because there may be non-neglible delays between when a timer was requested and it was actually scheduled. Therefore, since a timer's start might be delayed slightly, the time remaining might be slightly higher than one would expect if one calculated it right before the call to start the timer.

pub fn is_enabled(&self) -> bool[src]

Returns whether there is currently a timer enabled and so a callback will be expected in the future. If is_enabled returns false then the implementation MUST NOT invoke a callback until a call to oneshot or repeating restarts the timer.

pub fn cancel(&self) -> ReturnCode[src]

Cancel the current timer, if any. Value ReturnCode values are:

  • ReturnCode::SUCCESS: no callback will be invoked in the future.
  • ReturnCode::FAIL: the timer could not be cancelled and a callback will be invoked in the future.
Loading content...

Implementors

Loading content...