nrf/wdt: add handle steal

This commit is contained in:
Dario Nieuwenhuis 2021-08-20 14:23:24 +02:00
parent 0be6e4a384
commit 17659e2e44
2 changed files with 9 additions and 1 deletions

View File

@ -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 }
}
}

View File

@ -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...");