Skip to content

Commit

Permalink
Fix time types in independent_watchdog
Browse files Browse the repository at this point in the history
  • Loading branch information
no111u3 committed Nov 28, 2023
1 parent 494ac00 commit 57931ca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/independent_watchdog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
//! - [IWDG Example](todo-insert-link-here)
//!
//! Originally from stm32h7-hal, adapted for stm32g4xx-hal
use fugit::ExtU32;
use crate::{
stm32::{iwdg::pr::PR_A, IWDG},
time::{MicroSecond, U32Ext},
time::{MicroSecond},
};

/// The implementation of the hardware IWDG
Expand Down Expand Up @@ -83,7 +84,7 @@ impl IndependentWatchdog {
// Set the prescaler
let (prescaler, _) = Self::MAX_MILLIS_FOR_PRESCALER
.iter()
.find(|(_, max_millis)| *max_millis >= max_window_time.0 / 1000)
.find(|(_, max_millis)| *max_millis >= max_window_time.to_millis())
.expect("IWDG max time is greater than is possible");
while self.iwdg.sr.read().pvu().bit_is_set() {
cortex_m::asm::nop();
Expand All @@ -99,9 +100,9 @@ impl IndependentWatchdog {
.write(|w| w.win().bits(Self::MAX_COUNTER_VALUE as u16));

// Calculate the counter values
let reload_value = (max_window_time.0 / 1000) * (Self::CLOCK_SPEED / 1000)
let reload_value = (max_window_time.ticks() / 1000) * (Self::CLOCK_SPEED / 1000)
/ Self::get_prescaler_divider(prescaler);
let window_value = (min_window_time.0 / 1000) * (Self::CLOCK_SPEED / 1000)
let window_value = (min_window_time.ticks() / 1000) * (Self::CLOCK_SPEED / 1000)
/ Self::get_prescaler_divider(prescaler);

// Set the reload value
Expand Down Expand Up @@ -132,7 +133,7 @@ impl IndependentWatchdog {

/// Start the watchdog with the given max time and no minimal time
pub fn start<T: Into<MicroSecond>>(&mut self, max_time: T) {
self.start_windowed(0_u32.ms(), max_time.into());
self.start_windowed(0_u32.millis(), max_time.into());
}

fn get_prescaler_divider(prescaler: &PR_A) -> u32 {
Expand Down

0 comments on commit 57931ca

Please sign in to comment.