diff --git a/macros/src/trans.rs b/macros/src/trans.rs index b50c73df29..20e3aa0a7c 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -181,6 +181,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut V &#_static, #ceiling, #device::NVIC_PRIO_BITS, + #device::CPU, t, f, ) @@ -196,6 +197,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut V &mut #_static, #ceiling, #device::NVIC_PRIO_BITS, + #device::CPU, t, f, ) @@ -499,6 +501,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec) { &#_static, #ceiling, #device::NVIC_PRIO_BITS, + #device::CPU, t, f, ) @@ -514,6 +517,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec) { &mut #_static, #ceiling, #device::NVIC_PRIO_BITS, + #device::CPU, t, f, ) diff --git a/src/lib.rs b/src/lib.rs index be670490e7..dfb2060623 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,6 +74,7 @@ //! [rtfm]: http://www.diva-portal.org/smash/get/diva2:1005680/FULLTEXT01.pdf #![deny(missing_docs)] #![deny(warnings)] +#![feature(asm)] #![feature(proc_macro)] #![no_std] @@ -119,6 +120,7 @@ pub unsafe fn claim( data: T, ceiling: u8, _nvic_prio_bits: u8, + _cpu: &str, t: &mut Threshold, f: F, ) -> R @@ -132,6 +134,7 @@ where #[cfg(not(armv6m))] () => { + let is_cm7 = _cpu == "CM7"; let max_priority = 1 << _nvic_prio_bits; if ceiling == max_priority { @@ -139,9 +142,21 @@ where } else { let old = basepri::read(); let hw = (max_priority - ceiling) << (8 - _nvic_prio_bits); - basepri::write(hw); + if is_cm7 { + asm!("cpsid i + msr BASEPRI, $0 + cpsie i" :: "r"(hw) : "memory" : "volatile"); + } else { + basepri::write(hw); + } let ret = f(data, &mut Threshold::new(ceiling)); - basepri::write(old); + if is_cm7 { + asm!("cpsid i + msr BASEPRI, $0 + cpsie i" :: "r"(old) : "memory" : "volatile"); + } else { + basepri::write(old); + } ret } }