stm32ral/stm32f7/instances/
wwdg.rs

1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! Window watchdog
4//!
5//! Used by: stm32f730, stm32f745, stm32f750, stm32f765, stm32f7x2, stm32f7x3, stm32f7x6, stm32f7x7, stm32f7x9
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32f7::peripherals::wwdg::Instance;
9pub use crate::stm32f7::peripherals::wwdg::{RegisterBlock, ResetValues};
10pub use crate::stm32f7::peripherals::wwdg::{CFR, CR, SR};
11
12/// Access functions for the WWDG peripheral instance
13pub mod WWDG {
14    use super::ResetValues;
15
16    #[cfg(not(feature = "nosync"))]
17    use super::Instance;
18
19    #[cfg(not(feature = "nosync"))]
20    const INSTANCE: Instance = Instance {
21        addr: 0x40002c00,
22        _marker: ::core::marker::PhantomData,
23    };
24
25    /// Reset values for each field in WWDG
26    pub const reset: ResetValues = ResetValues {
27        CR: 0x0000007F,
28        CFR: 0x0000007F,
29        SR: 0x00000000,
30    };
31
32    #[cfg(not(feature = "nosync"))]
33    #[allow(renamed_and_removed_lints)]
34    #[allow(private_no_mangle_statics)]
35    #[no_mangle]
36    static mut WWDG_TAKEN: bool = false;
37
38    /// Safe access to WWDG
39    ///
40    /// This function returns `Some(Instance)` if this instance is not
41    /// currently taken, and `None` if it is. This ensures that if you
42    /// do get `Some(Instance)`, you are ensured unique access to
43    /// the peripheral and there cannot be data races (unless other
44    /// code uses `unsafe`, of course). You can then pass the
45    /// `Instance` around to other functions as required. When you're
46    /// done with it, you can call `release(instance)` to return it.
47    ///
48    /// `Instance` itself dereferences to a `RegisterBlock`, which
49    /// provides access to the peripheral's registers.
50    #[cfg(not(feature = "nosync"))]
51    #[inline]
52    pub fn take() -> Option<Instance> {
53        external_cortex_m::interrupt::free(|_| unsafe {
54            if WWDG_TAKEN {
55                None
56            } else {
57                WWDG_TAKEN = true;
58                Some(INSTANCE)
59            }
60        })
61    }
62
63    /// Release exclusive access to WWDG
64    ///
65    /// This function allows you to return an `Instance` so that it
66    /// is available to `take()` again. This function will panic if
67    /// you return a different `Instance` or if this instance is not
68    /// already taken.
69    #[cfg(not(feature = "nosync"))]
70    #[inline]
71    pub fn release(inst: Instance) {
72        external_cortex_m::interrupt::free(|_| unsafe {
73            if WWDG_TAKEN && inst.addr == INSTANCE.addr {
74                WWDG_TAKEN = false;
75            } else {
76                panic!("Released a peripheral which was not taken");
77            }
78        });
79    }
80
81    /// Unsafely steal WWDG
82    ///
83    /// This function is similar to take() but forcibly takes the
84    /// Instance, marking it as taken irregardless of its previous
85    /// state.
86    #[cfg(not(feature = "nosync"))]
87    #[inline]
88    pub unsafe fn steal() -> Instance {
89        WWDG_TAKEN = true;
90        INSTANCE
91    }
92}
93
94/// Raw pointer to WWDG
95///
96/// Dereferencing this is unsafe because you are not ensured unique
97/// access to the peripheral, so you may encounter data races with
98/// other users of this peripheral. It is up to you to ensure you
99/// will not cause data races.
100///
101/// This constant is provided for ease of use in unsafe code: you can
102/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
103pub const WWDG: *const RegisterBlock = 0x40002c00 as *const _;