Sergio Gasquez Arcos 3d0a1998fa
Allow configuring the watchdogs in the init config (#2180)
* feat: Allow configuring the watchdogs in the init config

* docs: Update changelog

* refactor: Remove unnecesary unsafe

* feat: Add a config module

* test: Add some init tests

* style: Rename all ocurrences to esp_hal::config::Config::default()

* style: Fix format

* fix: Doc errors

* revert: Move Config struct to lib.rs

* tests: Add default config test

* test: Add a test with CpuClock::max()

* test: Add timg1 test

* feat: Move Config struct to config module and reexport it in lib.rs

* fix: Fix init compilation for C2

* revert: Move Config struct to config module and reexport it in lib.rs

* fix: Use proper timergroup
2024-09-20 13:51:35 +00:00

111 lines
2.6 KiB
Rust

//! Initialization tests
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_hal::{
config::WatchdogStatus,
delay::Delay,
prelude::*,
rtc_cntl::Rtc,
timer::timg::TimerGroup,
Config,
};
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use super::*;
#[test]
#[timeout(3)]
fn test_feeding_timg0_wdt() {
let peripherals = esp_hal::init({
let mut config = Config::default();
config.watchdog.timg0 =
WatchdogStatus::Enabled(fugit::MicrosDurationU64::millis(500 as u64));
config
});
let timg0 = TimerGroup::new(peripherals.TIMG0);
let mut wdt0 = timg0.wdt;
let delay = Delay::new();
for _ in 0..4 {
wdt0.feed();
delay.delay(250.millis());
}
}
#[test]
#[timeout(3)]
#[cfg(timg1)]
fn test_feeding_timg1_wdt() {
let peripherals = esp_hal::init({
let mut config = Config::default();
config.watchdog.timg1 =
WatchdogStatus::Enabled(fugit::MicrosDurationU64::millis(500 as u64));
config
});
let timg1 = TimerGroup::new(peripherals.TIMG1);
let mut wdt1 = timg1.wdt;
let delay = Delay::new();
for _ in 0..4 {
wdt1.feed();
delay.delay(250.millis());
}
}
#[test]
#[timeout(3)]
fn test_feeding_timg0_wdt_max_clock() {
let peripherals = esp_hal::init({
let mut config = Config::default();
config.cpu_clock = CpuClock::max();
config.watchdog.timg0 =
WatchdogStatus::Enabled(fugit::MicrosDurationU64::millis(500 as u64));
config
});
let timg0 = TimerGroup::new(peripherals.TIMG0);
let mut wdt0 = timg0.wdt;
let delay = Delay::new();
for _ in 0..4 {
wdt0.feed();
delay.delay(250.millis());
}
}
#[test]
#[timeout(4)]
fn test_feeding_rtc_wdt() {
let peripherals = esp_hal::init({
let mut config = Config::default();
config.watchdog.rwdt =
WatchdogStatus::Enabled(fugit::MicrosDurationU64::millis(3000 as u64));
config
});
let mut rtc = Rtc::new(peripherals.LPWR);
let delay = Delay::new();
rtc.rwdt.feed();
delay.delay(2500.millis());
}
#[test]
#[timeout(3)]
fn test_default_config() {
esp_hal::init(Config::default());
let delay = Delay::new();
delay.delay(2000.millis());
}
}