aboutsummaryrefslogtreecommitdiff
path: root/src/interrupt.rs
diff options
context:
space:
mode:
authorGravatar Adam Greig <adam@adamgreig.com> 2022-02-21 19:57:18 +0000
committerGravatar Adam Greig <adam@adamgreig.com> 2022-02-24 01:44:11 +0000
commit894f2aabdbd65f85eecf25debc2326f0387863c7 (patch)
treef08ad0ca10df764c5b29549421e874c4c3512bec /src/interrupt.rs
parent9e8dd294b04510d727d50039a7f84292789aed0e (diff)
downloadcortex-m-894f2aabdbd65f85eecf25debc2326f0387863c7.tar.gz
cortex-m-894f2aabdbd65f85eecf25debc2326f0387863c7.tar.zst
cortex-m-894f2aabdbd65f85eecf25debc2326f0387863c7.zip
Remove outlined asm, replace with stable inline asm.
Diffstat (limited to 'src/interrupt.rs')
-rw-r--r--src/interrupt.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/interrupt.rs b/src/interrupt.rs
index 68719ec..06b91f1 100644
--- a/src/interrupt.rs
+++ b/src/interrupt.rs
@@ -1,6 +1,10 @@
//! Interrupts
pub use bare_metal::{CriticalSection, Mutex};
+#[cfg(cortex_m)]
+use core::arch::asm;
+#[cfg(cortex_m)]
+use core::sync::atomic::{compiler_fence, Ordering};
/// Trait for enums of external interrupt numbers.
///
@@ -24,9 +28,15 @@ pub unsafe trait InterruptNumber: Copy {
}
/// Disables all interrupts
+#[cfg(cortex_m)]
#[inline]
pub fn disable() {
- call_asm!(__cpsid());
+ unsafe {
+ asm!("cpsid i", options(nomem, nostack, preserves_flags));
+ }
+
+ // Ensure no subsequent memory accesses are reordered to before interrupts are disabled.
+ compiler_fence(Ordering::SeqCst);
}
/// Enables all the interrupts
@@ -34,14 +44,19 @@ pub fn disable() {
/// # Safety
///
/// - Do not call this function inside an `interrupt::free` critical section
+#[cfg(cortex_m)]
#[inline]
pub unsafe fn enable() {
- call_asm!(__cpsie());
+ // Ensure no preceeding memory accesses are reordered to after interrupts are enabled.
+ compiler_fence(Ordering::SeqCst);
+
+ asm!("cpsie i", options(nomem, nostack, preserves_flags));
}
/// Execute closure `f` in an interrupt-free context.
///
/// This as also known as a "critical section".
+#[cfg(cortex_m)]
#[inline]
pub fn free<F, R>(f: F) -> R
where