From 17659e2e4473575c32fc8cad95fd859947fc493f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 20 Aug 2021 14:23:24 +0200 Subject: [PATCH] nrf/wdt: add handle steal --- embassy-nrf/src/wdt.rs | 8 ++++++++ examples/nrf/src/bin/wdt.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs index 0c6f2b3f..cd62d0d6 100644 --- a/embassy-nrf/src/wdt.rs +++ b/embassy-nrf/src/wdt.rs @@ -150,4 +150,12 @@ impl WatchdogHandle { let idx = self.index as usize; ((rd >> idx) & 0x1) == 0 } + + /// Steal a watchdog handle by index. + /// + /// Safety: watchdog must be initialized, index must be between 0 and N-1 where + /// N is the handle count when initializing. + pub unsafe fn steal(index: u8) -> Self { + Self { index } + } } diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs index 53df7b0b..eaa0b5ee 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) { // in the WDT interrupt. The core resets 2 ticks after firing the interrupt. config.run_during_debug_halt = false; - let (_wdt, [mut handle]) = match Watchdog::try_new::<1>(p.WDT, config) { + let (_wdt, [mut handle]) = match Watchdog::try_new(p.WDT, config) { Ok(x) => x, Err(_) => { info!("Watchdog already active with wrong config, waiting for it to timeout...");