diff options
author | 2019-10-28 21:11:13 -0500 | |
---|---|---|
committer | 2019-10-28 21:11:13 -0500 | |
commit | a3783a6d3d90ab549766b13651ec8ff8013762c5 (patch) | |
tree | 29fc5a2ed50c73ebfeca65fd52ad241d9995677d /src | |
parent | f9b30a1ff87acd5f3c29a32369f0537e8e3d2bf1 (diff) | |
download | rtic-a3783a6d3d90ab549766b13651ec8ff8013762c5.tar.gz rtic-a3783a6d3d90ab549766b13651ec8ff8013762c5.tar.zst rtic-a3783a6d3d90ab549766b13651ec8ff8013762c5.zip |
WIP generators tasksgenerator-tasks
Diffstat (limited to 'src')
-rw-r--r-- | src/export.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/export.rs b/src/export.rs index 96c444bf..44eb5348 100644 --- a/src/export.rs +++ b/src/export.rs @@ -5,7 +5,7 @@ use core::{ pub use crate::tq::{NotReady, TimerQueue}; #[cfg(armv7m)] -pub use cortex_m::register::basepri; +pub use cortex_m::register::{basepri, basepri_max}; pub use cortex_m::{ asm::wfi, interrupt, @@ -145,6 +145,25 @@ pub unsafe fn lock<T, R>( } } +#[cfg(armv7m)] +#[inline(always)] +pub unsafe fn glock<T, R>( + ptr: *mut T, + ceiling: u8, + nvic_prio_bits: u8, + f: impl FnOnce(&mut T) -> R, +) -> R { + if ceiling == (1 << nvic_prio_bits) { + interrupt::free(|_| f(&mut *ptr)) + } else { + let current = basepri::read(); + basepri_max::write(logical2hw(ceiling, nvic_prio_bits)); + let r = f(&mut *ptr); + basepri::write(logical2hw(current, nvic_prio_bits)); + r + } +} + #[cfg(not(armv7m))] #[inline(always)] pub unsafe fn lock<T, R>( @@ -166,6 +185,8 @@ pub unsafe fn lock<T, R>( } } +// TODO glock for ARMv6-M + #[inline] pub fn logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 { ((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits) |