pub struct Pit<'a, const R: u16> { /* private fields */ }
Expand description
Timer based on 8253 “PIT” hardware
Although the PIT contains an internal counter, it is not a suitable source of ticks because it runs at a high, fixed frequency and wraps very quickly. So instead, we configure the PIT to generate periodic interrupts, and we increment an in-memory counter each time an interrupt fires.
Parameter R
is the reload value to use. This is loaded into a hardware register and determines
the interrupt frequency. Use reload_value
to compute a reload value for the desired
frequency.
Implementations§
Source§impl<const R: u16> Pit<'_, R>
impl<const R: u16> Pit<'_, R>
Sourcepub unsafe fn new() -> Self
pub unsafe fn new() -> Self
Creates a new PIT timer object.
§Safety
There must never be more than a single instance of Pit
alive at any given time.
Sourcepub fn handle_interrupt(&self)
pub fn handle_interrupt(&self)
Handler to call when a PIT interrupt occurs.
This will increment the internal in-memory timer and dispatch any alarms.
Trait Implementations§
Source§impl<'a, const R: u16> Alarm<'a> for Pit<'a, R>
impl<'a, const R: u16> Alarm<'a> for Pit<'a, R>
Source§fn set_alarm_client(&self, client: &'a dyn AlarmClient)
fn set_alarm_client(&self, client: &'a dyn AlarmClient)
Specify the callback for when the counter reaches the alarm
value. If there was a previously installed callback this call
replaces it.
Source§fn set_alarm(&self, reference: Self::Ticks, dt: Self::Ticks)
fn set_alarm(&self, reference: Self::Ticks, dt: Self::Ticks)
Specify when the callback should be called and enable it. The
callback will be enqueued when
Time::now() == reference + dt
. The
callback itself may not run exactly at this time, due to delays.
However, it it assured to execute after reference + dt
: it can
be delayed but will never fire early. The method takes reference
and dt
rather than a single value denoting the counter value so it
can distinguish between alarms which have very recently already
passed and those in the far far future (see #1651).Source§fn get_alarm(&self) -> Self::Ticks
fn get_alarm(&self) -> Self::Ticks
Return the current alarm value. This is undefined at boot and
otherwise returns
now + dt
from the last call to set_alarm
.Source§fn disarm(&self) -> Result<(), ErrorCode>
fn disarm(&self) -> Result<(), ErrorCode>
Disable the alarm and stop it from firing in the future.
Valid
Result<(), ErrorCode>
codes are: Read moreSource§fn is_armed(&self) -> bool
fn is_armed(&self) -> bool
Returns whether the alarm is currently armed. Note that this
does not reliably indicate whether there will be a future
callback: it is possible that the alarm has triggered (and
disarmed) and a callback is pending and has not been called yet.
In this case it possible for
is_armed
to return false yet to
receive a callback.Source§fn minimum_dt(&self) -> Self::Ticks
fn minimum_dt(&self) -> Self::Ticks
Return the minimum dt value that is supported. Any dt smaller than
this will automatically be increased to this minimum value.
Auto Trait Implementations§
impl<'a, const R: u16> !Freeze for Pit<'a, R>
impl<'a, const R: u16> !RefUnwindSafe for Pit<'a, R>
impl<'a, const R: u16> !Send for Pit<'a, R>
impl<'a, const R: u16> !Sync for Pit<'a, R>
impl<'a, const R: u16> Unpin for Pit<'a, R>
impl<'a, const R: u16> !UnwindSafe for Pit<'a, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more