diff options
| author | Siarhei B <[email protected]> | 2025-08-27 12:08:18 +0200 |
|---|---|---|
| committer | Siarhei B <[email protected]> | 2025-08-28 10:16:03 +0200 |
| commit | b618b6bfcdb42263639e8b348838b764a9ef7a04 (patch) | |
| tree | d61b2ee14924b4a395b94407b6fca832916f8877 /embassy-mspm0 | |
| parent | 2eb643bac66844dccddc11065c3debbaef468595 (diff) | |
mspm0-watchdog: remove template from watchdog struct
Diffstat (limited to 'embassy-mspm0')
| -rw-r--r-- | embassy-mspm0/src/wwdt.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/embassy-mspm0/src/wwdt.rs b/embassy-mspm0/src/wwdt.rs index 9864b3d94..38d76ed56 100644 --- a/embassy-mspm0/src/wwdt.rs +++ b/embassy-mspm0/src/wwdt.rs | |||
| @@ -4,8 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #![macro_use] | 5 | #![macro_use] |
| 6 | 6 | ||
| 7 | use core::marker::PhantomData; | ||
| 8 | |||
| 9 | use embassy_hal_internal::PeripheralType; | 7 | use embassy_hal_internal::PeripheralType; |
| 10 | 8 | ||
| 11 | use crate::pac::wwdt::{vals, Wwdt as Regs}; | 9 | use crate::pac::wwdt::{vals, Wwdt as Regs}; |
| @@ -262,22 +260,22 @@ impl Default for Config { | |||
| 262 | } | 260 | } |
| 263 | } | 261 | } |
| 264 | 262 | ||
| 265 | pub struct Watchdog<'d, T: Instance> { | 263 | pub struct Watchdog { |
| 266 | wdt: PhantomData<&'d mut T>, | 264 | regs: &'static Regs, |
| 267 | } | 265 | } |
| 268 | 266 | ||
| 269 | impl<'d, T: Instance> Watchdog<'d, T> { | 267 | impl Watchdog { |
| 270 | /// Watchdog initialization. | 268 | /// Watchdog initialization. |
| 271 | pub fn new(_instance: Peri<'d, T>, config: Config) -> Self { | 269 | pub fn new<T: Instance>(_instance: Peri<T>, config: Config) -> Self { |
| 272 | // Init power for watchdog | 270 | // Init power for watchdog |
| 273 | T::REGS.gprcm(0).rstctl().write(|w| { | 271 | T::regs().gprcm(0).rstctl().write(|w| { |
| 274 | w.set_resetstkyclr(true); | 272 | w.set_resetstkyclr(true); |
| 275 | w.set_resetassert(true); | 273 | w.set_resetassert(true); |
| 276 | w.set_key(vals::ResetKey::KEY); | 274 | w.set_key(vals::ResetKey::KEY); |
| 277 | }); | 275 | }); |
| 278 | 276 | ||
| 279 | // Enable power for watchdog | 277 | // Enable power for watchdog |
| 280 | T::REGS.gprcm(0).pwren().write(|w| { | 278 | T::regs().gprcm(0).pwren().write(|w| { |
| 281 | w.set_enable(true); | 279 | w.set_enable(true); |
| 282 | w.set_key(vals::PwrenKey::KEY); | 280 | w.set_key(vals::PwrenKey::KEY); |
| 283 | }); | 281 | }); |
| @@ -286,7 +284,7 @@ impl<'d, T: Instance> Watchdog<'d, T> { | |||
| 286 | cortex_m::asm::delay(16); | 284 | cortex_m::asm::delay(16); |
| 287 | 285 | ||
| 288 | //init watchdog | 286 | //init watchdog |
| 289 | T::REGS.wwdtctl0().write(|w| { | 287 | T::regs().wwdtctl0().write(|w| { |
| 290 | w.set_clkdiv(config.timeout.get_clkdiv()); | 288 | w.set_clkdiv(config.timeout.get_clkdiv()); |
| 291 | w.set_per(config.timeout.get_period()); | 289 | w.set_per(config.timeout.get_period()); |
| 292 | w.set_mode(vals::Mode::WINDOW); | 290 | w.set_mode(vals::Mode::WINDOW); |
| @@ -296,7 +294,7 @@ impl<'d, T: Instance> Watchdog<'d, T> { | |||
| 296 | }); | 294 | }); |
| 297 | 295 | ||
| 298 | // Set Window0 as active window | 296 | // Set Window0 as active window |
| 299 | T::REGS.wwdtctl1().write(|w| { | 297 | T::regs().wwdtctl1().write(|w| { |
| 300 | w.set_winsel(vals::Winsel::WIN0); | 298 | w.set_winsel(vals::Winsel::WIN0); |
| 301 | w.set_key(vals::Wwdtctl1Key::KEY); | 299 | w.set_key(vals::Wwdtctl1Key::KEY); |
| 302 | }); | 300 | }); |
| @@ -304,30 +302,30 @@ impl<'d, T: Instance> Watchdog<'d, T> { | |||
| 304 | critical_section::with(|_| { | 302 | critical_section::with(|_| { |
| 305 | // make sure watchdog triggers BOOTRST | 303 | // make sure watchdog triggers BOOTRST |
| 306 | pac::SYSCTL.systemcfg().write(|w| { | 304 | pac::SYSCTL.systemcfg().write(|w| { |
| 307 | if T::REGS == pac::WWDT0 { | 305 | if *T::regs() == pac::WWDT0 { |
| 308 | w.set_wwdtlp0rstdis(false); | 306 | w.set_wwdtlp0rstdis(false); |
| 309 | } | 307 | } |
| 310 | 308 | ||
| 311 | #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x))] | 309 | #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x))] |
| 312 | if T::REGS == pac::WWDT1 { | 310 | if *T::regs() == pac::WWDT1 { |
| 313 | w.set_wwdtlp1rstdis(false); | 311 | w.set_wwdtlp1rstdis(false); |
| 314 | } | 312 | } |
| 315 | }); | 313 | }); |
| 316 | }); | 314 | }); |
| 317 | 315 | ||
| 318 | Watchdog { wdt: PhantomData } | 316 | Self { regs: T::regs() } |
| 319 | } | 317 | } |
| 320 | 318 | ||
| 321 | /// Pet (reload, refresh) the watchdog. | 319 | /// Pet (reload, refresh) the watchdog. |
| 322 | pub fn pet(&mut self) { | 320 | pub fn pet(&mut self) { |
| 323 | T::REGS.wwdtcntrst().write(|w| { | 321 | self.regs.wwdtcntrst().write(|w| { |
| 324 | w.set_restart(vals::WwdtcntrstRestart::RESTART); | 322 | w.set_restart(vals::WwdtcntrstRestart::RESTART); |
| 325 | }); | 323 | }); |
| 326 | } | 324 | } |
| 327 | } | 325 | } |
| 328 | 326 | ||
| 329 | pub(crate) trait SealedInstance { | 327 | pub(crate) trait SealedInstance { |
| 330 | const REGS: Regs; | 328 | fn regs() -> &'static Regs; |
| 331 | } | 329 | } |
| 332 | 330 | ||
| 333 | /// WWDT instance trait | 331 | /// WWDT instance trait |
| @@ -337,7 +335,9 @@ pub trait Instance: SealedInstance + PeripheralType {} | |||
| 337 | macro_rules! impl_wwdt_instance { | 335 | macro_rules! impl_wwdt_instance { |
| 338 | ($instance: ident) => { | 336 | ($instance: ident) => { |
| 339 | impl crate::wwdt::SealedInstance for crate::peripherals::$instance { | 337 | impl crate::wwdt::SealedInstance for crate::peripherals::$instance { |
| 340 | const REGS: crate::pac::wwdt::Wwdt = crate::pac::$instance; | 338 | fn regs() -> &'static crate::pac::wwdt::Wwdt { |
| 339 | &crate::pac::$instance | ||
| 340 | } | ||
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | impl crate::wwdt::Instance for crate::peripherals::$instance {} | 343 | impl crate::wwdt::Instance for crate::peripherals::$instance {} |
