aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-08-23 20:18:34 -0500
committerxoviat <[email protected]>2023-08-23 20:18:34 -0500
commit83f224e14094488244792dc1bc6d7425d8dcd68f (patch)
tree5efe86ecb85733a04e35f26be095d7e83917dca4 /embassy-stm32/src
parente987259716c56f9854cc4730620d7b5a8be9962d (diff)
stm32/lp: add refcount
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/rcc/mod.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index ac9ae9c6a..3c75923e5 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -26,6 +26,8 @@ use crate::time::Hertz;
26#[cfg_attr(any(rcc_h5, rcc_h50), path = "h5.rs")] 26#[cfg_attr(any(rcc_h5, rcc_h50), path = "h5.rs")]
27mod _version; 27mod _version;
28pub use _version::*; 28pub use _version::*;
29#[cfg(feature = "low-power")]
30use atomic_polyfill::{AtomicU32, Ordering};
29 31
30#[derive(Clone, Copy, Debug)] 32#[derive(Clone, Copy, Debug)]
31#[cfg_attr(feature = "defmt", derive(defmt::Format))] 33#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -79,6 +81,25 @@ pub struct Clocks {
79 pub rtc: Option<Hertz>, 81 pub rtc: Option<Hertz>,
80} 82}
81 83
84#[cfg(feature = "low-power")]
85static CLOCK_REFCOUNT: AtomicU32 = AtomicU32::new(0);
86
87#[cfg(feature = "low-power")]
88pub fn low_power_ready() -> bool {
89 CLOCK_REFCOUNT.load(Ordering::SeqCst) == 0
90}
91
92#[cfg(feature = "low-power")]
93pub(crate) fn clock_refcount_add() {
94 // We don't check for overflow because constructing more than u32 peripherals is unlikely
95 CLOCK_REFCOUNT.fetch_add(1, Ordering::Relaxed);
96}
97
98#[cfg(feature = "low-power")]
99pub(crate) fn clock_refcount_sub() {
100 assert!(CLOCK_REFCOUNT.fetch_sub(1, Ordering::Relaxed) != 0);
101}
102
82/// Frozen clock frequencies 103/// Frozen clock frequencies
83/// 104///
84/// The existence of this value indicates that the clock configuration can no longer be changed 105/// The existence of this value indicates that the clock configuration can no longer be changed