aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-08-20 14:23:24 +0200
committerDario Nieuwenhuis <[email protected]>2021-08-20 14:23:24 +0200
commit17659e2e4473575c32fc8cad95fd859947fc493f (patch)
tree077906c4ffea4a2dfc6ebac07a7758c719c39d3d
parent0be6e4a384b3c2fee34f6f6db5f86ecbf9cea5e5 (diff)
nrf/wdt: add handle steal
-rw-r--r--embassy-nrf/src/wdt.rs8
-rw-r--r--examples/nrf/src/bin/wdt.rs2
2 files changed, 9 insertions, 1 deletions
diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs
index 0c6f2b3fb..cd62d0d60 100644
--- a/embassy-nrf/src/wdt.rs
+++ b/embassy-nrf/src/wdt.rs
@@ -150,4 +150,12 @@ impl WatchdogHandle {
150 let idx = self.index as usize; 150 let idx = self.index as usize;
151 ((rd >> idx) & 0x1) == 0 151 ((rd >> idx) & 0x1) == 0
152 } 152 }
153
154 /// Steal a watchdog handle by index.
155 ///
156 /// Safety: watchdog must be initialized, index must be between 0 and N-1 where
157 /// N is the handle count when initializing.
158 pub unsafe fn steal(index: u8) -> Self {
159 Self { index }
160 }
153} 161}
diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs
index 53df7b0b7..eaa0b5ee1 100644
--- a/examples/nrf/src/bin/wdt.rs
+++ b/examples/nrf/src/bin/wdt.rs
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
25 // in the WDT interrupt. The core resets 2 ticks after firing the interrupt. 25 // in the WDT interrupt. The core resets 2 ticks after firing the interrupt.
26 config.run_during_debug_halt = false; 26 config.run_during_debug_halt = false;
27 27
28 let (_wdt, [mut handle]) = match Watchdog::try_new::<1>(p.WDT, config) { 28 let (_wdt, [mut handle]) = match Watchdog::try_new(p.WDT, config) {
29 Ok(x) => x, 29 Ok(x) => x,
30 Err(_) => { 30 Err(_) => {
31 info!("Watchdog already active with wrong config, waiting for it to timeout..."); 31 info!("Watchdog already active with wrong config, waiting for it to timeout...");