fn start<T>(&mut self, period: T)
    where
        T: Into<Self::Time>,
    {
        let period_ms = period.into().0;
        let maximum =
            (4096 * 2u32.pow(7) * 64) / (self.pclk3_frequency.0 / 1000);
        assert!(period_ms <= maximum);

        // timeout = pclk * 4096 * 2^WDGTB[2:0] * (t[5:0] +1)
        let ratio = period_ms * (self.pclk3_frequency.0 / 1000) / 4096;

        // Prescaler
        let (tb_div, wdgtb) = match ratio / 64 {
            0 => (1, 0),
            1 => (2, 1),
            2..=3 => (4, 2),
            4..=7 => (8, 3),
            8..=15 => (16, 4),
            16..=31 => (32, 5),
            32..=63 => (64, 6),
            64..=127 => (128, 7),
            _ => (128, 7),
        };

        let t = ratio / tb_div;
        assert!(t < 64);

        self.down_counter = u8(t).unwrap() | (1 << 6);

        // write the config values, matching the set timeout the most
        // TODO: stm32h7 0.14.0 WDGTB is 3 bits (currently it's 2 and that's wrong), so let's set it directly
        const WDGTB_MASK: u32 = 0b111 << 11;
        self.wwdg.cfr.modify(|r, w| unsafe {
            w.bits((r.bits() & !WDGTB_MASK) | (wdgtb << 11))
        });
        self.wwdg.cfr.modify(|_, w| w.w().bits(self.down_counter));
        self.wwdg.cr.modify(|_, w| w.t().bits(self.down_counter));
        // For some reason, setting the t value makes the early wakeup pending.
        // That's bad behaviour, so lets turn it off again.
        self.unpend(Event::EarlyWakeup);
        // enable the watchdog
        self.wwdg.cr.modify(|_, w| w.wdga().set_bit());
    }
/// Starts the watchdog with a given timeout period, if this period is out of bounds the function
/// is going to panic
Starts the watchdog with a given timeout period, if this period is out of bounds the function
is going to panic
Starts the watchdog with a given timeout period if this period is out of bounds the function is going to panic
fn start<T>(&mut self, period: T)
    where
        T: Into<Self::Time>,
    {
        let period_ms = period.into().0;
        let maximum =
            (4096 * 2u32.pow(7) * 64) / (self.pclk3_frequency.0 / 1000);
        assert!(period_ms <= maximum);
        // timeout = pclk * 4096 * 2^WDGTB[2:0] * (t[5:0] +1)
        let ratio = period_ms * (self.pclk3_frequency.0 / 1000) / 4096;
        // Prescaler
        let (tb_div, wdgtb) = match ratio / 64 {
            0 => (1, 0),
            1 => (2, 1),
            2..=3 => (4, 2),
            4..=7 => (8, 3),
            8..=15 => (16, 4),
            16..=31 => (32, 5),
            32..=63 => (64, 6),
            64..=127 => (128, 7),
            _ => (128, 7),
        };
        let t = ratio / tb_div;
        assert!(t < 64);
        self.down_counter = u8(t).unwrap() | (1 << 6);
        // write the config values, matching the set timeout the most
        // TODO: stm32h7 0.14.0 WDGTB is 3 bits (currently it's 2 and that's wrong), so let's set it directly
        const WDGTB_MASK: u32 = 0b111 << 11;
        self.wwdg.cfr.modify(|r, w| unsafe {
            w.bits((r.bits() & !WDGTB_MASK) | (wdgtb << 11))
        });
        self.wwdg.cfr.modify(|_, w| w.w().bits(self.down_counter));
        self.wwdg.cr.modify(|_, w| w.t().bits(self.down_counter));
        // For some reason, setting the t value makes the early wakeup pending.
        // That's bad behaviour, so lets turn it off again.
        self.unpend(Event::EarlyWakeup);
        // enable the watchdog
        self.wwdg.cr.modify(|_, w| w.wdga().set_bit());
    }
fn start < T > ( & mut self , period : T ) where T : Into < Self :: Time > , { let period_ms = period . into ( ) . 0 ; let maximum = ( 4096 * 2u32 . pow ( 7 ) * 64 ) / ( self . pclk3_frequency . 0 / 1000 ) ; assert ! ( period_ms maximum ) ; // timeout = pclk * 4096 * 2^WDGTB[2:0] * (t[5:0] +1) let ratio = period_ms * ( self . pclk3_frequency . 0 / 1000 ) / 4096 ; // Prescaler let ( tb_div , wdgtb ) = match ratio / 64 { 0 => ( 1 , 0 ) , 1 => ( 2 , 1 ) , 2 ..= 3 => ( 4 , 2 ) , 4 ..= 7 => ( 8 , 3 ) , 8 ..= 15 => ( 16 , 4 ) , 16 ..= 31 => ( 32 , 5 ) , 32 ..= 63 => ( 64 , 6 ) , 64 ..= 127 => ( 128 , 7 ) , _ => ( 128 , 7 ) , } ; let t = ratio / tb_div ; assert ! ( t 64 ) ; self . down_counter = u8 ( t ) . unwrap ( ) | ( 1 << 6 ) ; // write the config values, matching the set timeout the most // TODO: stm32h7 0.14.0 WDGTB is 3 bits (currently it's 2 and that's wrong), so let's set it directly const WDGTB_MASK : u32 = 0b111 << 11 ; self . wwdg . cfr . modify ( | r , w | unsafe { w . bits ( ( r . bits ( ) & ! WDGTB_MASK ) | ( wdgtb << 11 ) ) } ) ; self . wwdg . cfr . modify ( | _ , w | w . w ( ) . bits ( self . down_counter ) ) ; self . wwdg . cr . modify ( | _ , w | w . t ( ) . bits ( self . down_counter ) ) ; // For some reason, setting the t value makes the early wakeup pending. // That's bad behaviour, so lets turn it off again. self . unpend ( Event :: EarlyWakeup ) ; // enable the watchdog self . wwdg . cr . modify ( | _ , w | w . wdga ( ) . set_bit ( ) ) ; }
Starts the watchdog with a given timeout period, if this period is out of bounds the function
is going to panic
Starts the watchdog with a given timeout period if this period is out of bounds the function is going to panic
&mut self
period
T
&mut self
period
T