pub struct Pit { /* private fields */ }Expand description
A periodic interrupt timer (PIT) driver.
The PIT has four independent timer channels that share a single
interrupt. Use the Channel enum to select which channel to operate on.
Implementations§
Source§impl Pit
impl Pit
Sourcepub fn new<const N: u8>(pit: Instance<N>) -> Self
pub fn new<const N: u8>(pit: Instance<N>) -> Self
Create a new PIT driver from the RAL’s PIT instance.
When new returns, all channels are disabled and reset.
The FRZ bit in MCR is not modified.
Sourcepub fn set_interrupt_enable(&mut self, channel: Channel, enable: bool)
pub fn set_interrupt_enable(&mut self, channel: Channel, enable: bool)
Enable (true) or disable (false) interrupt generation for a channel.
Sourcepub fn is_interrupt_enabled(&self, channel: Channel) -> bool
pub fn is_interrupt_enabled(&self, channel: Channel) -> bool
Indicates if timeouts will (true) or will not (false) generate interrupts.
Sourcepub fn current_timer_value(&self, channel: Channel) -> u32
pub fn current_timer_value(&self, channel: Channel) -> u32
Reads the current timer value, in clock ticks.
Returns 0 if the channel is disabled.
Sourcepub fn set_load_timer_value(&self, channel: Channel, ticks: u32)
pub fn set_load_timer_value(&self, channel: Channel, ticks: u32)
Loads the timer value for the next timer run.
ticks is in clock ticks.
Sourcepub fn load_timer_value(&self, channel: Channel) -> u32
pub fn load_timer_value(&self, channel: Channel) -> u32
Returns the load timer value for the next timer run, in clock ticks.
Sourcepub fn is_enabled(&self, channel: Channel) -> bool
pub fn is_enabled(&self, channel: Channel) -> bool
Returns true if the channel is enabled.
Sourcepub fn is_elapsed(&self, channel: Channel) -> bool
pub fn is_elapsed(&self, channel: Channel) -> bool
Returns true if the timer has elapsed.
Sourcepub fn clear_elapsed(&self, channel: Channel)
pub fn clear_elapsed(&self, channel: Channel)
Clear the elapsed flag.
Sourcepub fn enable_chaining(
&mut self,
channel: Channel,
) -> Result<(), CannotChainError>
pub fn enable_chaining( &mut self, channel: Channel, ) -> Result<(), CannotChainError>
Chain adjacent channels together, forming a larger timer.
A chained timer will decrement by one each time the previous channel expires. The previous channel is the channel with a lower number.
For example, to chain Chan2 to Chan1, supply Chan2 as an argument.
Then, every time Chan1 expires, Chan2 decrements by one.
You may chain multiple channels together, forming 96-bit and 128-bit timers. When reading the timer values, take care to handle overflows.
If you’re generating interrupts from a chained timer, the channel with the larger number should generate that interrupt.
When querying for the time tracked by chained timers, make sure you
account for rollover in software. Keep in mind that the lifetime timer
will handle rollover automatically; see lifetime_value
for more information.
§Errors
Returns CannotChainError if channel is Chan0, since there is
no previous channel to chain to.
Sourcepub fn disable_chaining(
&mut self,
channel: Channel,
) -> Result<(), CannotChainError>
pub fn disable_chaining( &mut self, channel: Channel, ) -> Result<(), CannotChainError>
Disable chaining for a channel.
See enable_chaining for more information.
§Errors
Returns CannotChainError if channel is Chan0, since Chan0
cannot be chained.
Sourcepub fn is_chained(&self, channel: Channel) -> bool
pub fn is_chained(&self, channel: Channel) -> bool
Returns true if a channel is chained to the previous channel.
See enable_chaining for more information.
Always returns false for Chan0.
Sourcepub fn lifetime_value(&self) -> u64
pub fn lifetime_value(&self) -> u64
Read the lifetime register value.
The lifetime register is a 64-bit register that combines channels 0 and 1. It is only valid when channel 1 is chained to channel 0.
The method assumes that channel 1 is chained to channel 0. See
enable_chaining for more information. Additionally,
the method assumes both channels 0 and 1 are enabled.
Given the hardware support, this call does not require a loop to account for rollover.
This method implements the recommended fix for errata ERR050130.