aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-02-12 13:38:07 +0100
committerGitHub <[email protected]>2025-02-12 13:38:07 +0100
commit712143b81fd02cca2621f021438fdfd042563651 (patch)
tree1fcf3dc39c9f1531073a51212d7b7c5f7b29f5f1
parent05bbb99603e16dd58604bfd1b59871eb551c74a3 (diff)
parent787606b991e744aa79d6d899dd556a90e4bf9853 (diff)
Merge pull request #3877 from Abestanis/feature/watchdog_reason
Expose the watchdog reset reason
-rw-r--r--embassy-rp/src/watchdog.rs22
1 files changed, 22 insertions, 0 deletions
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;
13use crate::pac; 13use crate::pac;
14use crate::peripherals::WATCHDOG; 14use crate::peripherals::WATCHDOG;
15 15
16/// The reason for a system reset from the watchdog.
17#[derive(Debug, Copy, Clone, PartialEq, Eq)]
18pub enum ResetReason {
19 /// The reset was forced.
20 Forced,
21 /// The watchdog was not fed in time.
22 TimedOut,
23}
24
16/// Watchdog peripheral 25/// Watchdog peripheral
17pub struct Watchdog { 26pub struct Watchdog {
18 phantom: PhantomData<WATCHDOG>, 27 phantom: PhantomData<WATCHDOG>,
@@ -140,4 +149,17 @@ impl Watchdog {
140 _ => panic!("Invalid watchdog scratch index"), 149 _ => panic!("Invalid watchdog scratch index"),
141 } 150 }
142 } 151 }
152
153 /// Get the reason for the last system reset, if it was caused by the watchdog.
154 pub fn reset_reason(&self) -> Option<ResetReason> {
155 let watchdog = pac::WATCHDOG;
156 let reason = watchdog.reason().read();
157 if reason.force() {
158 Some(ResetReason::Forced)
159 } else if reason.timer() {
160 Some(ResetReason::TimedOut)
161 } else {
162 None
163 }
164 }
143} 165}