From 2540a960e5d97473253a56198bf9205f4f3f7980 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 7 Aug 2021 14:26:28 +0200 Subject: nrf: add WDT driver --- examples/nrf/src/bin/wdt.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/nrf/src/bin/wdt.rs (limited to 'examples') diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs new file mode 100644 index 000000000..53df7b0b7 --- /dev/null +++ b/examples/nrf/src/bin/wdt.rs @@ -0,0 +1,46 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] +#![allow(incomplete_features)] + +#[path = "../example_common.rs"] +mod example_common; + +use defmt::*; +use embassy::executor::Spawner; +use embassy_nrf::gpio::{Input, Pull}; +use embassy_nrf::gpiote::PortInput; +use embassy_nrf::wdt::{Config, Watchdog}; +use embassy_nrf::Peripherals; +use embassy_traits::gpio::{WaitForHigh, WaitForLow}; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + info!("Hello World!"); + + let mut config = Config::default(); + config.timeout_ticks = 32768 * 3; // 3 seconds + + // This is needed for `probe-run` to be able to catch the panic message + // 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) { + Ok(x) => x, + Err(_) => { + info!("Watchdog already active with wrong config, waiting for it to timeout..."); + loop {} + } + }; + + let mut button = PortInput::new(Input::new(p.P0_11, Pull::Up)); + + info!("Watchdog started, press button 1 to pet it or I'll reset in 3 seconds!"); + + loop { + button.wait_for_high().await; + button.wait_for_low().await; + info!("Button pressed, petting watchdog!"); + handle.pet(); + } +} -- cgit