stm32ral/stm32mp/instances/
rng.rs

1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! RNG1
4//!
5//! Used by: stm32mp153, stm32mp157
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32mp::peripherals::rng::Instance;
9pub use crate::stm32mp::peripherals::rng::{RegisterBlock, ResetValues};
10pub use crate::stm32mp::peripherals::rng::{
11    RNG_CR, RNG_DR, RNG_HWCFGR, RNG_IPIDR, RNG_SIDR, RNG_SR, RNG_VERR,
12};
13
14/// Access functions for the RNG1 peripheral instance
15pub mod RNG1 {
16    use super::ResetValues;
17
18    #[cfg(not(feature = "nosync"))]
19    use super::Instance;
20
21    #[cfg(not(feature = "nosync"))]
22    const INSTANCE: Instance = Instance {
23        addr: 0x54003000,
24        _marker: ::core::marker::PhantomData,
25    };
26
27    /// Reset values for each field in RNG1
28    pub const reset: ResetValues = ResetValues {
29        RNG_CR: 0x00000000,
30        RNG_SR: 0x00000000,
31        RNG_DR: 0x00000000,
32        RNG_HWCFGR: 0x00000006,
33        RNG_VERR: 0x00000021,
34        RNG_IPIDR: 0x00170041,
35        RNG_SIDR: 0xA3C5DD01,
36    };
37
38    #[cfg(not(feature = "nosync"))]
39    #[allow(renamed_and_removed_lints)]
40    #[allow(private_no_mangle_statics)]
41    #[no_mangle]
42    static mut RNG1_TAKEN: bool = false;
43
44    /// Safe access to RNG1
45    ///
46    /// This function returns `Some(Instance)` if this instance is not
47    /// currently taken, and `None` if it is. This ensures that if you
48    /// do get `Some(Instance)`, you are ensured unique access to
49    /// the peripheral and there cannot be data races (unless other
50    /// code uses `unsafe`, of course). You can then pass the
51    /// `Instance` around to other functions as required. When you're
52    /// done with it, you can call `release(instance)` to return it.
53    ///
54    /// `Instance` itself dereferences to a `RegisterBlock`, which
55    /// provides access to the peripheral's registers.
56    #[cfg(not(feature = "nosync"))]
57    #[inline]
58    pub fn take() -> Option<Instance> {
59        external_cortex_m::interrupt::free(|_| unsafe {
60            if RNG1_TAKEN {
61                None
62            } else {
63                RNG1_TAKEN = true;
64                Some(INSTANCE)
65            }
66        })
67    }
68
69    /// Release exclusive access to RNG1
70    ///
71    /// This function allows you to return an `Instance` so that it
72    /// is available to `take()` again. This function will panic if
73    /// you return a different `Instance` or if this instance is not
74    /// already taken.
75    #[cfg(not(feature = "nosync"))]
76    #[inline]
77    pub fn release(inst: Instance) {
78        external_cortex_m::interrupt::free(|_| unsafe {
79            if RNG1_TAKEN && inst.addr == INSTANCE.addr {
80                RNG1_TAKEN = false;
81            } else {
82                panic!("Released a peripheral which was not taken");
83            }
84        });
85    }
86
87    /// Unsafely steal RNG1
88    ///
89    /// This function is similar to take() but forcibly takes the
90    /// Instance, marking it as taken irregardless of its previous
91    /// state.
92    #[cfg(not(feature = "nosync"))]
93    #[inline]
94    pub unsafe fn steal() -> Instance {
95        RNG1_TAKEN = true;
96        INSTANCE
97    }
98}
99
100/// Raw pointer to RNG1
101///
102/// Dereferencing this is unsafe because you are not ensured unique
103/// access to the peripheral, so you may encounter data races with
104/// other users of this peripheral. It is up to you to ensure you
105/// will not cause data races.
106///
107/// This constant is provided for ease of use in unsafe code: you can
108/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
109pub const RNG1: *const RegisterBlock = 0x54003000 as *const _;
110
111/// Access functions for the RNG2 peripheral instance
112pub mod RNG2 {
113    use super::ResetValues;
114
115    #[cfg(not(feature = "nosync"))]
116    use super::Instance;
117
118    #[cfg(not(feature = "nosync"))]
119    const INSTANCE: Instance = Instance {
120        addr: 0x4c003000,
121        _marker: ::core::marker::PhantomData,
122    };
123
124    /// Reset values for each field in RNG2
125    pub const reset: ResetValues = ResetValues {
126        RNG_CR: 0x00000000,
127        RNG_SR: 0x00000000,
128        RNG_DR: 0x00000000,
129        RNG_HWCFGR: 0x00000006,
130        RNG_VERR: 0x00000021,
131        RNG_IPIDR: 0x00170041,
132        RNG_SIDR: 0xA3C5DD01,
133    };
134
135    #[cfg(not(feature = "nosync"))]
136    #[allow(renamed_and_removed_lints)]
137    #[allow(private_no_mangle_statics)]
138    #[no_mangle]
139    static mut RNG2_TAKEN: bool = false;
140
141    /// Safe access to RNG2
142    ///
143    /// This function returns `Some(Instance)` if this instance is not
144    /// currently taken, and `None` if it is. This ensures that if you
145    /// do get `Some(Instance)`, you are ensured unique access to
146    /// the peripheral and there cannot be data races (unless other
147    /// code uses `unsafe`, of course). You can then pass the
148    /// `Instance` around to other functions as required. When you're
149    /// done with it, you can call `release(instance)` to return it.
150    ///
151    /// `Instance` itself dereferences to a `RegisterBlock`, which
152    /// provides access to the peripheral's registers.
153    #[cfg(not(feature = "nosync"))]
154    #[inline]
155    pub fn take() -> Option<Instance> {
156        external_cortex_m::interrupt::free(|_| unsafe {
157            if RNG2_TAKEN {
158                None
159            } else {
160                RNG2_TAKEN = true;
161                Some(INSTANCE)
162            }
163        })
164    }
165
166    /// Release exclusive access to RNG2
167    ///
168    /// This function allows you to return an `Instance` so that it
169    /// is available to `take()` again. This function will panic if
170    /// you return a different `Instance` or if this instance is not
171    /// already taken.
172    #[cfg(not(feature = "nosync"))]
173    #[inline]
174    pub fn release(inst: Instance) {
175        external_cortex_m::interrupt::free(|_| unsafe {
176            if RNG2_TAKEN && inst.addr == INSTANCE.addr {
177                RNG2_TAKEN = false;
178            } else {
179                panic!("Released a peripheral which was not taken");
180            }
181        });
182    }
183
184    /// Unsafely steal RNG2
185    ///
186    /// This function is similar to take() but forcibly takes the
187    /// Instance, marking it as taken irregardless of its previous
188    /// state.
189    #[cfg(not(feature = "nosync"))]
190    #[inline]
191    pub unsafe fn steal() -> Instance {
192        RNG2_TAKEN = true;
193        INSTANCE
194    }
195}
196
197/// Raw pointer to RNG2
198///
199/// Dereferencing this is unsafe because you are not ensured unique
200/// access to the peripheral, so you may encounter data races with
201/// other users of this peripheral. It is up to you to ensure you
202/// will not cause data races.
203///
204/// This constant is provided for ease of use in unsafe code: you can
205/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
206pub const RNG2: *const RegisterBlock = 0x4c003000 as *const _;