diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-12-24 02:23:57 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-24 02:23:57 +0000 |
| commit | d1dd66cfcacd9a519188d7799d9c045673fff738 (patch) | |
| tree | 706ba64221eab7f8bdc8332281fb3098ef4fd1ed /examples/rp/src | |
| parent | 67a6e5accfce0963060a20418bab04495c5bf50d (diff) | |
| parent | e090ab19151fbea6736d5eac0e1497ef9c36626b (diff) | |
Merge #1126
1126: embassy-rp: Add Watchdog r=kalkyl a=kalkyl
Co-authored-by: kalkyl <[email protected]>
Diffstat (limited to 'examples/rp/src')
| -rw-r--r-- | examples/rp/src/bin/watchdog.rs | 48 |
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..ece5cfe38 --- /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 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::gpio; | ||
| 8 | use embassy_rp::watchdog::*; | ||
| 9 | use embassy_time::{Duration, Timer}; | ||
| 10 | use gpio::{Level, Output}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async 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 fed 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, feed 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. | ||
| 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 | } | ||
