pub struct AonTimer<'d> { /* private fields */ }Expand description
AON Timer driver
Implementations§
Source§impl<'d> AonTimer<'d>
impl<'d> AonTimer<'d>
Sourcepub fn new(
_inner: Peri<'d, POWMAN>,
_irq: impl Binding<POWMAN_IRQ_TIMER, InterruptHandler> + 'd,
config: Config,
) -> Self
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/WFEDormantOnly: Hardware power-up wake from DORMANT (requires LPOSC + Secure mode)Both: Both interrupt and hardware power-up wakeDisabled: 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);Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Stop the timer
The timer will stop counting but retain its current value.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the timer is currently running
Sourcepub fn now(&self) -> u64
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.
Sourcepub fn set_counter(&mut self, value_ms: u64)
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.
Sourcepub fn set_alarm(&mut self, alarm_ms: u64) -> Result<(), Error>
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/WFEDormantOnly: Alarm triggers power-up from DORMANT modeBoth: Alarm triggers both interrupt and power-up wakeDisabled: Alarm flag is set but no wake occurs
Sourcepub fn disable_alarm_interrupt(&mut self)
pub fn disable_alarm_interrupt(&mut self)
Disable the alarm interrupt (INTE.TIMER)
Sourcepub fn alarm_fired(&self) -> bool
pub fn alarm_fired(&self) -> bool
Check if the alarm has fired
Sourcepub fn clear_alarm(&mut self)
pub fn clear_alarm(&mut self)
Clear the alarm flag
Sourcepub fn disable_alarm(&mut self)
pub fn disable_alarm(&mut self)
Disable the alarm
Sourcepub fn enable_alarm(&mut self)
pub fn enable_alarm(&mut self)
Enable the alarm
Sourcepub fn enable_dormant_wake(&mut self)
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.
Sourcepub fn disable_dormant_wake(&mut self)
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.
Sourcepub fn set_wake_mode(&mut self, mode: AlarmWakeMode)
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
mode- The desired wake mode (seeAlarmWakeMode)
§Security Note
Setting modes that involve DORMANT wake (DormantOnly or Both) requires Secure privilege level. These modes may fail silently in Non-secure contexts.
Sourcepub fn set_alarm_after(&mut self, duration: Duration) -> Result<(), Error>
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.
Sourcepub fn elapsed(&self) -> Duration
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.
Sourcepub fn set_datetime(&mut self, dt: DateTime) -> Result<(), DateTimeError>
pub fn set_datetime(&mut self, dt: DateTime) -> Result<(), DateTimeError>
Sourcepub fn now_as_datetime(&self) -> Result<DateTime, DateTimeError>
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.
Sourcepub fn set_alarm_at_datetime(&mut self, dt: DateTime) -> Result<(), Error>
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.
Sourcepub async fn wait_for_alarm(&mut self)
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:
WfiOnlyorBoth: CPU enters WFI (Wait For Interrupt) low-power mode while waiting. The alarm interrupt will wake the CPU and this function will return.DormantOnlyorDisabled: 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;