mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-27 12:20:37 +00:00
mspm0-watchdog: add watchdog examples for all chips
This commit is contained in:
parent
55eea8b029
commit
93ba2c9c95
54
examples/mspm0c1104/src/bin/wwdt.rs
Normal file
54
examples/mspm0c1104/src/bin/wwdt.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! Example of using window watchdog timer in the MSPM0C1104 chip.
|
||||
//!
|
||||
//! It tests the use case when watchdog timer is expired and when watchdog is pet too early.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
let mut conf = Config::default();
|
||||
conf.timeout = Timeout::Sec1;
|
||||
|
||||
// watchdog also resets the system if the pet comes too early,
|
||||
// less than 250 msec == 25% from 1 sec
|
||||
conf.closed_window = ClosedWindowPercentage::TwentyFive;
|
||||
let mut wdt = Watchdog::new(p.WWDT0, conf);
|
||||
info!("Started the watchdog timer");
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::High);
|
||||
led1.set_inversion(true);
|
||||
Timer::after_millis(900).await;
|
||||
|
||||
for _ in 1..=5 {
|
||||
info!("pet watchdog");
|
||||
led1.toggle();
|
||||
wdt.pet();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog timeout test
|
||||
info!("Stopped the pet command, device will reset in less than 1 second");
|
||||
loop {
|
||||
led1.toggle();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog "too early" test
|
||||
// info!("Device will reset when the pet comes too early");
|
||||
// loop {
|
||||
// led1.toggle();
|
||||
// wdt.pet();
|
||||
// Timer::after_millis(200).await;
|
||||
// }
|
||||
}
|
54
examples/mspm0g3507/src/bin/wwdt.rs
Normal file
54
examples/mspm0g3507/src/bin/wwdt.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! Example of using window watchdog timer in the MSPM0G3507 chip.
|
||||
//!
|
||||
//! It tests the use case when watchdog timer is expired and when watchdog is pet too early.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
let mut conf = Config::default();
|
||||
conf.timeout = Timeout::Sec1;
|
||||
|
||||
// watchdog also resets the system if the pet comes too early,
|
||||
// less than 250 msec == 25% from 1 sec
|
||||
conf.closed_window = ClosedWindowPercentage::TwentyFive;
|
||||
let mut wdt = Watchdog::new(p.WWDT0, conf);
|
||||
info!("Started the watchdog timer");
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::High);
|
||||
led1.set_inversion(true);
|
||||
Timer::after_millis(900).await;
|
||||
|
||||
for _ in 1..=5 {
|
||||
info!("pet watchdog");
|
||||
led1.toggle();
|
||||
wdt.pet();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog timeout test
|
||||
info!("Stopped the pet command, device will reset in less than 1 second");
|
||||
loop {
|
||||
led1.toggle();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog "too early" test
|
||||
// info!("Device will reset when the pet comes too early");
|
||||
// loop {
|
||||
// led1.toggle();
|
||||
// wdt.pet();
|
||||
// Timer::after_millis(200).await;
|
||||
// }
|
||||
}
|
54
examples/mspm0g3519/src/bin/wwdt.rs
Normal file
54
examples/mspm0g3519/src/bin/wwdt.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! Example of using window watchdog timer in the MSPM0G3519 chip.
|
||||
//!
|
||||
//! It tests the use case when watchdog timer is expired and when watchdog is pet too early.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
let mut conf = Config::default();
|
||||
conf.timeout = Timeout::Sec1;
|
||||
|
||||
// watchdog also resets the system if the pet comes too early,
|
||||
// less than 250 msec == 25% from 1 sec
|
||||
conf.closed_window = ClosedWindowPercentage::TwentyFive;
|
||||
let mut wdt = Watchdog::new(p.WWDT0, conf);
|
||||
info!("Started the watchdog timer");
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::High);
|
||||
led1.set_inversion(true);
|
||||
Timer::after_millis(900).await;
|
||||
|
||||
for _ in 1..=5 {
|
||||
info!("pet watchdog");
|
||||
led1.toggle();
|
||||
wdt.pet();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog timeout test
|
||||
info!("Stopped the pet command, device will reset in less than 1 second");
|
||||
loop {
|
||||
led1.toggle();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog "too early" test
|
||||
// info!("Device will reset when the pet comes too early");
|
||||
// loop {
|
||||
// led1.toggle();
|
||||
// wdt.pet();
|
||||
// Timer::after_millis(200).await;
|
||||
// }
|
||||
}
|
54
examples/mspm0l1306/src/bin/wwdt.rs
Normal file
54
examples/mspm0l1306/src/bin/wwdt.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! Example of using window watchdog timer in the MSPM0L1306 chip.
|
||||
//!
|
||||
//! It tests the use case when watchdog timer is expired and when watchdog is pet too early.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
let mut conf = Config::default();
|
||||
conf.timeout = Timeout::Sec1;
|
||||
|
||||
// watchdog also resets the system if the pet comes too early,
|
||||
// less than 250 msec == 25% from 1 sec
|
||||
conf.closed_window = ClosedWindowPercentage::TwentyFive;
|
||||
let mut wdt = Watchdog::new(p.WWDT0, conf);
|
||||
info!("Started the watchdog timer");
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::High);
|
||||
led1.set_inversion(true);
|
||||
Timer::after_millis(900).await;
|
||||
|
||||
for _ in 1..=5 {
|
||||
info!("pet watchdog");
|
||||
led1.toggle();
|
||||
wdt.pet();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog timeout test
|
||||
info!("Stopped the pet command, device will reset in less than 1 second");
|
||||
loop {
|
||||
led1.toggle();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog "too early" test
|
||||
// info!("Device will reset when the pet comes too early");
|
||||
// loop {
|
||||
// led1.toggle();
|
||||
// wdt.pet();
|
||||
// Timer::after_millis(200).await;
|
||||
// }
|
||||
}
|
54
examples/mspm0l2228/src/bin/wwdt.rs
Normal file
54
examples/mspm0l2228/src/bin/wwdt.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! Example of using window watchdog timer in the MSPM0L2228 chip.
|
||||
//!
|
||||
//! It tests the use case when watchdog timer is expired and when watchdog is pet too early.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_mspm0::gpio::{Level, Output};
|
||||
use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_halt as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
info!("Hello world!");
|
||||
|
||||
let p = embassy_mspm0::init(Default::default());
|
||||
let mut conf = Config::default();
|
||||
conf.timeout = Timeout::Sec1;
|
||||
|
||||
// watchdog also resets the system if the pet comes too early,
|
||||
// less than 250 msec == 25% from 1 sec
|
||||
conf.closed_window = ClosedWindowPercentage::TwentyFive;
|
||||
let mut wdt = Watchdog::new(p.WWDT0, conf);
|
||||
info!("Started the watchdog timer");
|
||||
|
||||
let mut led1 = Output::new(p.PA0, Level::High);
|
||||
led1.set_inversion(true);
|
||||
Timer::after_millis(900).await;
|
||||
|
||||
for _ in 1..=5 {
|
||||
info!("pet watchdog");
|
||||
led1.toggle();
|
||||
wdt.pet();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog timeout test
|
||||
info!("Stopped the pet command, device will reset in less than 1 second");
|
||||
loop {
|
||||
led1.toggle();
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
|
||||
// watchdog "too early" test
|
||||
// info!("Device will reset when the pet comes too early");
|
||||
// loop {
|
||||
// led1.toggle();
|
||||
// wdt.pet();
|
||||
// Timer::after_millis(200).await;
|
||||
// }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user