stm32ral/stm32f7/instances/
rtc_f730_f7x2_f7x3.rs

1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! Real-time clock
4//!
5//! Used by: stm32f730, stm32f7x2, stm32f7x3
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32f7::peripherals::rtc_v1::Instance;
9pub use crate::stm32f7::peripherals::rtc_v1::{RegisterBlock, ResetValues};
10pub use crate::stm32f7::peripherals::rtc_v1::{
11    ALRMAR, ALRMASSR, ALRMBR, ALRMBSSR, BKP0R, BKP10R, BKP11R, BKP12R, BKP13R, BKP14R, BKP15R,
12    BKP16R, BKP17R, BKP18R, BKP19R, BKP1R, BKP20R, BKP21R, BKP22R, BKP23R, BKP24R, BKP25R, BKP26R,
13    BKP27R, BKP28R, BKP29R, BKP2R, BKP30R, BKP31R, BKP3R, BKP4R, BKP5R, BKP6R, BKP7R, BKP8R, BKP9R,
14    CALR, CR, DR, ISR, OR, PRER, SHIFTR, SSR, TAMPCR, TR, TSDR, TSSSR, TSTR, WPR, WUTR,
15};
16
17/// Access functions for the RTC peripheral instance
18pub mod RTC {
19    use super::ResetValues;
20
21    #[cfg(not(feature = "nosync"))]
22    use super::Instance;
23
24    #[cfg(not(feature = "nosync"))]
25    const INSTANCE: Instance = Instance {
26        addr: 0x40002800,
27        _marker: ::core::marker::PhantomData,
28    };
29
30    /// Reset values for each field in RTC
31    pub const reset: ResetValues = ResetValues {
32        TR: 0x00000000,
33        DR: 0x00002101,
34        CR: 0x00000000,
35        ISR: 0x00000007,
36        PRER: 0x007F00FF,
37        WUTR: 0x0000FFFF,
38        ALRMAR: 0x00000000,
39        ALRMBR: 0x00000000,
40        WPR: 0x00000000,
41        SSR: 0x00000000,
42        SHIFTR: 0x00000000,
43        TSTR: 0x00000000,
44        TSDR: 0x00000000,
45        TSSSR: 0x00000000,
46        CALR: 0x00000000,
47        TAMPCR: 0x00000000,
48        ALRMASSR: 0x00000000,
49        ALRMBSSR: 0x00000000,
50        OR: 0x00000000,
51        BKP0R: 0x00000000,
52        BKP1R: 0x00000000,
53        BKP2R: 0x00000000,
54        BKP3R: 0x00000000,
55        BKP4R: 0x00000000,
56        BKP5R: 0x00000000,
57        BKP6R: 0x00000000,
58        BKP7R: 0x00000000,
59        BKP8R: 0x00000000,
60        BKP9R: 0x00000000,
61        BKP10R: 0x00000000,
62        BKP11R: 0x00000000,
63        BKP12R: 0x00000000,
64        BKP13R: 0x00000000,
65        BKP14R: 0x00000000,
66        BKP15R: 0x00000000,
67        BKP16R: 0x00000000,
68        BKP17R: 0x00000000,
69        BKP18R: 0x00000000,
70        BKP19R: 0x00000000,
71        BKP20R: 0x00000000,
72        BKP21R: 0x00000000,
73        BKP22R: 0x00000000,
74        BKP23R: 0x00000000,
75        BKP24R: 0x00000000,
76        BKP25R: 0x00000000,
77        BKP26R: 0x00000000,
78        BKP27R: 0x00000000,
79        BKP28R: 0x00000000,
80        BKP29R: 0x00000000,
81        BKP30R: 0x00000000,
82        BKP31R: 0x00000000,
83    };
84
85    #[cfg(not(feature = "nosync"))]
86    #[allow(renamed_and_removed_lints)]
87    #[allow(private_no_mangle_statics)]
88    #[no_mangle]
89    static mut RTC_TAKEN: bool = false;
90
91    /// Safe access to RTC
92    ///
93    /// This function returns `Some(Instance)` if this instance is not
94    /// currently taken, and `None` if it is. This ensures that if you
95    /// do get `Some(Instance)`, you are ensured unique access to
96    /// the peripheral and there cannot be data races (unless other
97    /// code uses `unsafe`, of course). You can then pass the
98    /// `Instance` around to other functions as required. When you're
99    /// done with it, you can call `release(instance)` to return it.
100    ///
101    /// `Instance` itself dereferences to a `RegisterBlock`, which
102    /// provides access to the peripheral's registers.
103    #[cfg(not(feature = "nosync"))]
104    #[inline]
105    pub fn take() -> Option<Instance> {
106        external_cortex_m::interrupt::free(|_| unsafe {
107            if RTC_TAKEN {
108                None
109            } else {
110                RTC_TAKEN = true;
111                Some(INSTANCE)
112            }
113        })
114    }
115
116    /// Release exclusive access to RTC
117    ///
118    /// This function allows you to return an `Instance` so that it
119    /// is available to `take()` again. This function will panic if
120    /// you return a different `Instance` or if this instance is not
121    /// already taken.
122    #[cfg(not(feature = "nosync"))]
123    #[inline]
124    pub fn release(inst: Instance) {
125        external_cortex_m::interrupt::free(|_| unsafe {
126            if RTC_TAKEN && inst.addr == INSTANCE.addr {
127                RTC_TAKEN = false;
128            } else {
129                panic!("Released a peripheral which was not taken");
130            }
131        });
132    }
133
134    /// Unsafely steal RTC
135    ///
136    /// This function is similar to take() but forcibly takes the
137    /// Instance, marking it as taken irregardless of its previous
138    /// state.
139    #[cfg(not(feature = "nosync"))]
140    #[inline]
141    pub unsafe fn steal() -> Instance {
142        RTC_TAKEN = true;
143        INSTANCE
144    }
145}
146
147/// Raw pointer to RTC
148///
149/// Dereferencing this is unsafe because you are not ensured unique
150/// access to the peripheral, so you may encounter data races with
151/// other users of this peripheral. It is up to you to ensure you
152/// will not cause data races.
153///
154/// This constant is provided for ease of use in unsafe code: you can
155/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
156pub const RTC: *const RegisterBlock = 0x40002800 as *const _;