11//! Interrupts
22
3+ use core:: arch:: asm;
4+ use core:: sync:: atomic:: { Ordering , compiler_fence} ;
5+
36pub use bare_metal:: { CriticalSection , Mutex , Nr } ;
47
58/// Trait for enums of external interrupt numbers.
@@ -35,7 +38,10 @@ unsafe impl<T: Nr + Copy> InterruptNumber for T {
3538/// Disables all interrupts
3639#[ inline]
3740pub fn disable ( ) {
38- unsafe { crate :: asm:: inner:: __cpsid ( ) } ;
41+ unsafe { asm ! ( "cpsid i" , options( nomem, nostack, preserves_flags) ) } ;
42+
43+ // Ensure no subsequent memory accesses are reordered to before interrupts are disabled.
44+ compiler_fence ( Ordering :: SeqCst ) ;
3945}
4046
4147/// Enables all the interrupts
@@ -44,8 +50,12 @@ pub fn disable() {
4450///
4551/// - Do not call this function inside an `interrupt::free` critical section
4652#[ inline]
53+ #[ cortex_m_macros:: asm_wrapper( any( armv6m, armv7m, armv7em, armv8m) ) ]
4754pub unsafe fn enable ( ) {
48- unsafe { crate :: asm:: inner:: __cpsie ( ) } ;
55+ // Ensure no preceeding memory accesses are reordered to after interrupts are enabled.
56+ compiler_fence ( Ordering :: SeqCst ) ;
57+
58+ unsafe { asm ! ( "cpsie i" , options( nomem, nostack, preserves_flags) ) } ;
4959}
5060
5161/// Execute closure `f` in an interrupt-free context.
0 commit comments