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