mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
work around Cortex-M7 BASEPRI erratum
This commit is contained in:
parent
8a396c51f2
commit
ca395922e6
2 changed files with 21 additions and 2 deletions
|
@ -181,6 +181,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, 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<Tokens>, 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<Tokens>) {
|
|||
&#_static,
|
||||
#ceiling,
|
||||
#device::NVIC_PRIO_BITS,
|
||||
#device::CPU,
|
||||
t,
|
||||
f,
|
||||
)
|
||||
|
@ -514,6 +517,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
|||
&mut #_static,
|
||||
#ceiling,
|
||||
#device::NVIC_PRIO_BITS,
|
||||
#device::CPU,
|
||||
t,
|
||||
f,
|
||||
)
|
||||
|
|
15
src/lib.rs
15
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<T, R, F>(
|
|||
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);
|
||||
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));
|
||||
if is_cm7 {
|
||||
asm!("cpsid i
|
||||
msr BASEPRI, $0
|
||||
cpsie i" :: "r"(old) : "memory" : "volatile");
|
||||
} else {
|
||||
basepri::write(old);
|
||||
}
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue