From 787606b991e744aa79d6d899dd556a90e4bf9853 Mon Sep 17 00:00:00 2001 From: Sebastian Scholz Date: Wed, 12 Feb 2025 13:22:43 +0100 Subject: [PATCH] Expose the watchdog reset reason --- embassy-rp/src/watchdog.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 + } + } }