esp-hal/examples/src/bin/watchdog.rs
Björn Quentin 256d7198f9
Timers runtime isr binding (#1348)
* Runtime ISR binding for TIMG/SYSTIMER

* CHANGELOG.md

* Implement `set_interrupt_handler` only for blocking

* Adapt HIL test
2024-04-03 08:14:27 +00:00

40 lines
921 B
Rust

//! This demos the watchdog timer.
//!
//! Basically the same as `hello_world` but if you remove the call to
//! `wdt.feed()` the watchdog will reset the system.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
peripherals::Peripherals,
prelude::*,
timer::TimerGroup,
};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let delay = Delay::new(&clocks);
let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks);
let mut wdt0 = timg0.wdt;
wdt0.enable();
wdt0.set_timeout(2u64.secs());
loop {
wdt0.feed();
println!("Hello world!");
delay.delay(1.secs());
}
}