embassy-rp

Crates

git

Versions

rp235xa

Flavors

AonTimer

Struct AonTimer 

Source
pub struct AonTimer<'d> { /* private fields */ }
Expand description

AON Timer driver

Implementations§

Source§

impl<'d> AonTimer<'d>

Source

pub fn new( _inner: Peri<'d, POWMAN>, _irq: impl Binding<POWMAN_IRQ_TIMER, InterruptHandler> + 'd, config: Config, ) -> Self

Create a new AON Timer instance

This configures the clock source, frequency, and alarm wake mode but does not start the timer. Call start() to begin counting.

The wake mode in config.alarm_wake_mode determines how alarms wake the CPU:

  • WfiOnly (default): Interrupt-based wake from WFI/WFE
  • DormantOnly: Hardware power-up wake from DORMANT (requires LPOSC + Secure mode)
  • Both: Both interrupt and hardware power-up wake
  • Disabled: No automatic wake (manual polling only)

For interrupt-based wake modes (WfiOnly or Both), you must bind the POWMAN_IRQ_TIMER interrupt:

bind_interrupts!(struct Irqs {
    POWMAN_IRQ_TIMER => aon_timer::InterruptHandler;
});
let timer = AonTimer::new(p.POWMAN, Irqs, config);
Source

pub fn start(&mut self)

Start the timer

The timer will begin counting from its current value.

Source

pub fn stop(&mut self)

Stop the timer

The timer will stop counting but retain its current value.

Source

pub fn is_running(&self) -> bool

Check if the timer is currently running

Source

pub fn now(&self) -> u64

Read the current counter value in milliseconds

This reads the 64-bit counter value with rollover protection. The value represents milliseconds since the counter was last set.

Source

pub fn set_counter(&mut self, value_ms: u64)

Set the counter value in milliseconds

This allows you to initialize the counter to any value (e.g., milliseconds since epoch, or 0 to start counting from boot).

Note: Timer must be stopped before calling this function.

Source

pub fn set_alarm(&mut self, alarm_ms: u64) -> Result<(), Error>

Set an alarm for a specific counter value (in milliseconds)

The alarm will fire when the counter reaches this value. Returns an error if the alarm time is in the past.

The wake behavior depends on the configured alarm_wake_mode:

  • WfiOnly: Alarm triggers interrupt wake from WFI/WFE
  • DormantOnly: Alarm triggers power-up from DORMANT mode
  • Both: Alarm triggers both interrupt and power-up wake
  • Disabled: Alarm flag is set but no wake occurs
Source

pub fn disable_alarm_interrupt(&mut self)

Disable the alarm interrupt (INTE.TIMER)

Source

pub fn alarm_fired(&self) -> bool

Check if the alarm has fired

Source

pub fn clear_alarm(&mut self)

Clear the alarm flag

Source

pub fn disable_alarm(&mut self)

Disable the alarm

Source

pub fn enable_alarm(&mut self)

Enable the alarm

Source

pub fn enable_dormant_wake(&mut self)

Enable DORMANT mode wake on alarm

Sets the TIMER.PWRUP_ON_ALARM bit to allow the alarm to wake the chip from DORMANT (deep sleep) mode. This is a hardware power-up event, distinct from interrupt-based WFI/WFE wake.

Security Note: The TIMER register is Secure-only per the RP2350 datasheet. This method may fail silently or have no effect when called from Non-secure contexts.

Clock Source: DORMANT wake requires LPOSC as the clock source, since XOSC is powered down in DORMANT mode.

Source

pub fn disable_dormant_wake(&mut self)

Disable DORMANT mode wake on alarm

Clears the TIMER.PWRUP_ON_ALARM bit. The alarm will no longer wake the chip from DORMANT mode, but can still wake from WFI/WFE via interrupts.

Security Note: The TIMER register is Secure-only per the RP2350 datasheet. This method may fail silently or have no effect when called from Non-secure contexts.

Source

pub fn set_wake_mode(&mut self, mode: AlarmWakeMode)

Set the alarm wake mode

Configures which low-power wake mechanisms are enabled for the alarm. This immediately updates the hardware configuration.

§Arguments
§Security Note

Setting modes that involve DORMANT wake (DormantOnly or Both) requires Secure privilege level. These modes may fail silently in Non-secure contexts.

Source

pub fn set_alarm_after(&mut self, duration: Duration) -> Result<(), Error>

Set an alarm to fire after a duration from now

This is a convenience method that sets the alarm to now() + duration.

Source

pub fn elapsed(&self) -> Duration

Get the current counter value as a Duration

This is useful for measuring time spans. The duration represents the time since the counter was last set to 0.

Source

pub fn set_datetime(&mut self, dt: DateTime) -> Result<(), DateTimeError>

Set the counter from a DateTime (Unix epoch)

§Errors

Returns error if DateTime is before 1970-01-01.

§Panics

Panics if timer is running.

Source

pub fn now_as_datetime(&self) -> Result<DateTime, DateTimeError>

Get the current counter value as a DateTime (Unix epoch)

§Errors

Returns error if counter value cannot be represented as valid DateTime.

Source

pub fn set_alarm_at_datetime(&mut self, dt: DateTime) -> Result<(), Error>

Set an alarm for a specific DateTime

§Errors

Returns error if DateTime conversion fails or alarm time is in the past.

Source

pub async fn wait_for_alarm(&mut self)

Wait asynchronously for the alarm to fire

This function will wait until the AON Timer alarm is triggered. If the alarm is already triggered, it will return immediately.

Wake Mode Behavior:

  • WfiOnly or Both: CPU enters WFI (Wait For Interrupt) low-power mode while waiting. The alarm interrupt will wake the CPU and this function will return.
  • DormantOnly or Disabled: This function will NOT automatically wake from DORMANT mode. For DORMANT wake, the hardware power-up event will restart the chip, not resume this async function.

This method is primarily intended for WfiOnly and Both wake modes where interrupt-based wake is available.

§Example
// Set alarm for 5 seconds from now
timer.set_alarm_after(Duration::from_secs(5)).unwrap();

// Wait for the alarm (CPU enters WFI low-power mode)
timer.wait_for_alarm().await;

Auto Trait Implementations§

§

impl<'d> Freeze for AonTimer<'d>

§

impl<'d> RefUnwindSafe for AonTimer<'d>

§

impl<'d> Send for AonTimer<'d>

§

impl<'d> Sync for AonTimer<'d>

§

impl<'d> Unpin for AonTimer<'d>

§

impl<'d> UnwindSafe for AonTimer<'d>

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.