diff --git a/embassy-rp/src/watchdog.rs b/embassy-rp/src/watchdog.rs index edd48e0e0..553936602 100644 --- a/embassy-rp/src/watchdog.rs +++ b/embassy-rp/src/watchdog.rs @@ -13,6 +13,15 @@ use embassy_time::Duration; use crate::pac; use crate::peripherals::WATCHDOG; +/// The reason for a system reset from the watchdog. +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum ResetReason { + /// The reset was forced. + Forced, + /// The watchdog was not fed in time. + TimedOut, +} + /// Watchdog peripheral pub struct Watchdog { phantom: PhantomData, @@ -140,4 +149,17 @@ impl Watchdog { _ => panic!("Invalid watchdog scratch index"), } } + + /// Get the reason for the last system reset, if it was caused by the watchdog. + pub fn reset_reason(&self) -> Option { + let watchdog = pac::WATCHDOG; + let reason = watchdog.reason().read(); + if reason.force() { + Some(ResetReason::Forced) + } else if reason.timer() { + Some(ResetReason::TimedOut) + } else { + None + } + } }