aboutsummaryrefslogtreecommitdiff
path: root/embassy-hal-internal/src/macros.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-10-12 00:34:47 +0200
committerDario Nieuwenhuis <[email protected]>2023-10-12 16:20:34 +0200
commit97ca0e77bf6e6f36aae18cb57fbfa8e583597327 (patch)
tree20f7a2f1e27e0d30e530047e819b6efeaf2bd9cc /embassy-hal-internal/src/macros.rs
parent66e399b5c61653f1f66cd3fd1592936e4085d6b5 (diff)
stm32: avoid creating many tiny critical sections in init.
Saves 292 bytes on stm32f0 bilnky with max optimizations (from 3132 to 2840).
Diffstat (limited to 'embassy-hal-internal/src/macros.rs')
-rw-r--r--embassy-hal-internal/src/macros.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/embassy-hal-internal/src/macros.rs b/embassy-hal-internal/src/macros.rs
index 0eea4b667..97df38954 100644
--- a/embassy-hal-internal/src/macros.rs
+++ b/embassy-hal-internal/src/macros.rs
@@ -48,17 +48,23 @@ macro_rules! peripherals_struct {
48 ///Returns all the peripherals *once* 48 ///Returns all the peripherals *once*
49 #[inline] 49 #[inline]
50 pub(crate) fn take() -> Self { 50 pub(crate) fn take() -> Self {
51 critical_section::with(Self::take_with_cs)
52 }
51 53
54 ///Returns all the peripherals *once*
55 #[inline]
56 pub(crate) fn take_with_cs(_cs: critical_section::CriticalSection) -> Self {
52 #[no_mangle] 57 #[no_mangle]
53 static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false; 58 static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false;
54 59
55 critical_section::with(|_| unsafe { 60 // safety: OK because we're inside a CS.
61 unsafe {
56 if _EMBASSY_DEVICE_PERIPHERALS { 62 if _EMBASSY_DEVICE_PERIPHERALS {
57 panic!("init called more than once!") 63 panic!("init called more than once!")
58 } 64 }
59 _EMBASSY_DEVICE_PERIPHERALS = true; 65 _EMBASSY_DEVICE_PERIPHERALS = true;
60 Self::steal() 66 Self::steal()
61 }) 67 }
62 } 68 }
63 } 69 }
64 70