2021-08-07 14:26:28 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::*;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2021-08-07 14:26:28 +02:00
|
|
|
use embassy_nrf::gpio::{Input, Pull};
|
|
|
|
use embassy_nrf::wdt::{Config, Watchdog};
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-02 04:35:06 +02:00
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 18:49:55 +02:00
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
2021-08-07 14:26:28 +02:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let mut config = Config::default();
|
|
|
|
config.timeout_ticks = 32768 * 3; // 3 seconds
|
|
|
|
|
2023-06-29 02:39:28 +02:00
|
|
|
// This is needed for `probe-rs run` to be able to catch the panic message
|
2021-08-07 14:26:28 +02:00
|
|
|
// in the WDT interrupt. The core resets 2 ticks after firing the interrupt.
|
|
|
|
config.run_during_debug_halt = false;
|
|
|
|
|
2021-08-20 14:23:24 +02:00
|
|
|
let (_wdt, [mut handle]) = match Watchdog::try_new(p.WDT, config) {
|
2021-08-07 14:26:28 +02:00
|
|
|
Ok(x) => x,
|
|
|
|
Err(_) => {
|
|
|
|
info!("Watchdog already active with wrong config, waiting for it to timeout...");
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-14 13:23:40 +01:00
|
|
|
let mut button = Input::new(p.P0_11, Pull::Up);
|
2021-08-07 14:26:28 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|