aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/watchdog.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/rp/src/bin/watchdog.rs b/examples/rp/src/bin/watchdog.rs
new file mode 100644
index 000000000..13af22a2d
--- /dev/null
+++ b/examples/rp/src/bin/watchdog.rs
@@ -0,0 +1,48 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::info;
6use embassy_executor::Spawner;
7use embassy_rp::gpio;
8use embassy_rp::watchdog::*;
9use embassy_time::{Duration, Timer};
10use gpio::{Level, Output};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let p = embassy_rp::init(Default::default());
16 info!("Hello world!");
17
18 let mut watchdog = Watchdog::new(p.WATCHDOG);
19 let mut led = Output::new(p.PIN_25, Level::Low);
20
21 // Set the LED high for 2 seconds so we know when we're about to start the watchdog
22 led.set_high();
23 Timer::after(Duration::from_secs(2)).await;
24
25 // Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it
26 watchdog.start(Duration::from_millis(1_050));
27 info!("Started the watchdog timer");
28
29 // Blink once a second for 5 seconds, refreshing the watchdog timer once a second to avoid a reset
30 for _ in 1..=5 {
31 led.set_low();
32 Timer::after(Duration::from_millis(500)).await;
33 led.set_high();
34 Timer::after(Duration::from_millis(500)).await;
35 info!("Feeding watchdog");
36 watchdog.feed();
37 }
38
39 info!("Stopped feeding, device will reset in 1.05 seconds");
40 // Blink 10 times per second, not feeding the watchdog.
41 // The processor should reset in 1.05 seconds, or 5 blinks time
42 loop {
43 led.set_low();
44 Timer::after(Duration::from_millis(100)).await;
45 led.set_high();
46 Timer::after(Duration::from_millis(100)).await;
47 }
48}