Skip to main content

Pit

Struct Pit 

Source
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

Source

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.

Source

pub fn set_interrupt_enable(&mut self, channel: Channel, enable: bool)

Enable (true) or disable (false) interrupt generation for a channel.

Source

pub fn is_interrupt_enabled(&self, channel: Channel) -> bool

Indicates if timeouts will (true) or will not (false) generate interrupts.

Source

pub fn current_timer_value(&self, channel: Channel) -> u32

Reads the current timer value, in clock ticks.

Returns 0 if the channel is disabled.

Source

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.

Source

pub fn load_timer_value(&self, channel: Channel) -> u32

Returns the load timer value for the next timer run, in clock ticks.

Source

pub fn enable(&mut self, channel: Channel)

Enable a timer channel.

Source

pub fn disable(&mut self, channel: Channel)

Disable a timer channel.

Source

pub fn is_enabled(&self, channel: Channel) -> bool

Returns true if the channel is enabled.

Source

pub fn is_elapsed(&self, channel: Channel) -> bool

Returns true if the timer has elapsed.

Source

pub fn clear_elapsed(&self, channel: Channel)

Clear the elapsed flag.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Pit

§

impl !Sync for Pit

§

impl !UnwindSafe for Pit

§

impl Freeze for Pit

§

impl Send for Pit

§

impl Unpin for Pit

§

impl UnsafeUnpin for Pit

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.