mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 22:55:26 +00:00

* Unify the system peripheral Whilst the PCR, SYSTEM and DPORT peripherals are different, we currently use them all in the same way. This PR unifies the peripheral name in the hal to `SYSTEM`. The idea is that they all do the same sort of thing, so we can collect them under the same name, and later down the line we can being to expose differences under an extended API. The benifits to this are imo quite big, the examples now are all identical, which makes things easier for esp-wifi, and paves a path towards the multichip hal. Why not do this in the PAC? Imo the pac should be as close to the hardware as possible, and the HAL is where we should abstractions such as this. * changelog
66 lines
1.5 KiB
Rust
66 lines
1.5 KiB
Rust
//! This demos the RTC Watchdog Timer (RWDT).
|
|
//! The RWDT is initially configured to trigger an interrupt after a given
|
|
//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured
|
|
//! to reset both the main system and the RTC.
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use core::cell::RefCell;
|
|
|
|
use critical_section::Mutex;
|
|
use esp32h2_hal::{
|
|
clock::ClockControl,
|
|
interrupt,
|
|
peripherals::{self, Peripherals},
|
|
prelude::*,
|
|
riscv,
|
|
Rtc,
|
|
Rwdt,
|
|
};
|
|
use esp_backtrace as _;
|
|
|
|
static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None));
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let system = peripherals.SYSTEM.split();
|
|
let _clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let mut rtc = Rtc::new(peripherals.LP_CLKRST);
|
|
rtc.rwdt.start(2000u64.millis());
|
|
rtc.rwdt.listen();
|
|
|
|
interrupt::enable(
|
|
peripherals::Interrupt::LP_WDT,
|
|
interrupt::Priority::Priority1,
|
|
)
|
|
.unwrap();
|
|
|
|
critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt));
|
|
|
|
unsafe {
|
|
riscv::interrupt::enable();
|
|
}
|
|
|
|
loop {}
|
|
}
|
|
|
|
#[interrupt]
|
|
fn LP_WDT() {
|
|
critical_section::with(|cs| {
|
|
esp_println::println!("RWDT Interrupt");
|
|
|
|
let mut rwdt = RWDT.borrow_ref_mut(cs);
|
|
let rwdt = rwdt.as_mut().unwrap();
|
|
|
|
rwdt.clear_interrupt();
|
|
|
|
esp_println::println!("Restarting in 5 seconds...");
|
|
|
|
rwdt.start(5000u64.millis());
|
|
rwdt.unlisten();
|
|
});
|
|
}
|