diff options
| -rw-r--r-- | embassy-rp/src/watchdog.rs | 14 | ||||
| -rw-r--r-- | examples/rp/src/bin/watchdog.rs | 6 |
2 files changed, 10 insertions, 10 deletions
diff --git a/embassy-rp/src/watchdog.rs b/embassy-rp/src/watchdog.rs index 01509ff4e..f4f165b29 100644 --- a/embassy-rp/src/watchdog.rs +++ b/embassy-rp/src/watchdog.rs | |||
| @@ -14,12 +14,12 @@ use crate::pac; | |||
| 14 | use crate::peripherals::WATCHDOG; | 14 | use crate::peripherals::WATCHDOG; |
| 15 | 15 | ||
| 16 | /// Watchdog peripheral | 16 | /// Watchdog peripheral |
| 17 | pub struct Watchdog<'d> { | 17 | pub struct Watchdog { |
| 18 | phantom: PhantomData<&'d WATCHDOG>, | 18 | phantom: PhantomData<WATCHDOG>, |
| 19 | load_value: u32, // decremented by 2 per tick (µs) | 19 | load_value: u32, // decremented by 2 per tick (µs) |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | impl<'d> Watchdog<'d> { | 22 | impl Watchdog { |
| 23 | /// Create a new `Watchdog` | 23 | /// Create a new `Watchdog` |
| 24 | pub fn new(_watchdog: WATCHDOG) -> Self { | 24 | pub fn new(_watchdog: WATCHDOG) -> Self { |
| 25 | Self { | 25 | Self { |
| @@ -35,12 +35,12 @@ impl<'d> Watchdog<'d> { | |||
| 35 | /// * `cycles` - Total number of tick cycles before the next tick is generated. | 35 | /// * `cycles` - Total number of tick cycles before the next tick is generated. |
| 36 | /// It is expected to be the frequency in MHz of clk_ref. | 36 | /// It is expected to be the frequency in MHz of clk_ref. |
| 37 | pub fn enable_tick_generation(&mut self, cycles: u8) { | 37 | pub fn enable_tick_generation(&mut self, cycles: u8) { |
| 38 | const WATCHDOG_TICK_ENABLE_BITS: u32 = 0x200; | ||
| 39 | unsafe { | 38 | unsafe { |
| 40 | let watchdog = pac::WATCHDOG; | 39 | let watchdog = pac::WATCHDOG; |
| 41 | watchdog | 40 | watchdog.tick().write(|w| { |
| 42 | .tick() | 41 | w.set_enable(true); |
| 43 | .write_value(pac::watchdog::regs::Tick(WATCHDOG_TICK_ENABLE_BITS | cycles as u32)) | 42 | w.set_cycles(cycles.into()) |
| 43 | }); | ||
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
diff --git a/examples/rp/src/bin/watchdog.rs b/examples/rp/src/bin/watchdog.rs index 13af22a2d..ece5cfe38 100644 --- a/examples/rp/src/bin/watchdog.rs +++ b/examples/rp/src/bin/watchdog.rs | |||
| @@ -22,11 +22,11 @@ async fn main(_spawner: Spawner) { | |||
| 22 | led.set_high(); | 22 | led.set_high(); |
| 23 | Timer::after(Duration::from_secs(2)).await; | 23 | Timer::after(Duration::from_secs(2)).await; |
| 24 | 24 | ||
| 25 | // Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it | 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)); | 26 | watchdog.start(Duration::from_millis(1_050)); |
| 27 | info!("Started the watchdog timer"); | 27 | info!("Started the watchdog timer"); |
| 28 | 28 | ||
| 29 | // Blink once a second for 5 seconds, refreshing the watchdog timer once a second to avoid a reset | 29 | // Blink once a second for 5 seconds, feed the watchdog timer once a second to avoid a reset |
| 30 | for _ in 1..=5 { | 30 | for _ in 1..=5 { |
| 31 | led.set_low(); | 31 | led.set_low(); |
| 32 | Timer::after(Duration::from_millis(500)).await; | 32 | Timer::after(Duration::from_millis(500)).await; |
| @@ -38,7 +38,7 @@ async fn main(_spawner: Spawner) { | |||
| 38 | 38 | ||
| 39 | info!("Stopped feeding, device will reset in 1.05 seconds"); | 39 | info!("Stopped feeding, device will reset in 1.05 seconds"); |
| 40 | // Blink 10 times per second, not feeding the watchdog. | 40 | // Blink 10 times per second, not feeding the watchdog. |
| 41 | // The processor should reset in 1.05 seconds, or 5 blinks time | 41 | // The processor should reset in 1.05 seconds. |
| 42 | loop { | 42 | loop { |
| 43 | led.set_low(); | 43 | led.set_low(); |
| 44 | Timer::after(Duration::from_millis(100)).await; | 44 | Timer::after(Duration::from_millis(100)).await; |
