stm32ral/stm32mp/instances/
etzpc.rs

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