diff options
| author | Oleksandr Babak <alexanderbabak@proton.me> | 2025-05-15 16:49:20 +0200 |
|---|---|---|
| committer | Emil Fresk <emil.fresk@gmail.com> | 2025-06-18 18:49:41 +0000 |
| commit | d16ad16bd7ff56fa4dcfb1a0832f556c7931d000 (patch) | |
| tree | 68d6e0480b31fb97eecbc44bb81c679b0c2ef06e | |
| parent | e8428f7c2c2ae0823c9406bbad9fe8d73e2aa383 (diff) | |
export: cortex_source_mask update
| -rw-r--r-- | rtic/src/export/cortex_source_mask.rs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/rtic/src/export/cortex_source_mask.rs b/rtic/src/export/cortex_source_mask.rs index 9dec5c7..4fb62a4 100644 --- a/rtic/src/export/cortex_source_mask.rs +++ b/rtic/src/export/cortex_source_mask.rs @@ -127,25 +127,27 @@ pub unsafe fn lock<T, R, const M: usize>( masks: &[Mask<M>; 3], f: impl FnOnce(&mut T) -> R, ) -> R { - if ceiling >= 4 { - // safe to manipulate outside critical section - // execute closure under protection of raised system ceiling - - // safe to manipulate outside critical section - critical_section::with(|_| f(&mut *ptr)) - } else { - // safe to manipulate outside critical section - let mask = compute_mask(0, ceiling, masks); - let old_mask = read_mask(mask); - clear_enable_mask(mask); - - // execute closure under protection of raised system ceiling - let r = f(&mut *ptr); - - set_enable_mask(mask, old_mask); - - // safe to manipulate outside critical section - r + unsafe { + if ceiling >= 4 { + // safe to manipulate outside critical section + // execute closure under protection of raised system ceiling + + // safe to manipulate outside critical section + critical_section::with(|_| f(&mut *ptr)) + } else { + // safe to manipulate outside critical section + let mask = compute_mask(0, ceiling, masks); + let old_mask = read_mask(mask); + clear_enable_mask(mask); + + // execute closure under protection of raised system ceiling + let r = f(&mut *ptr); + + set_enable_mask(mask, old_mask); + + // safe to manipulate outside critical section + r + } } } @@ -187,7 +189,7 @@ unsafe fn read_mask<const M: usize>(mask: Mask<M>) -> Mask<M> { for i in 0..M { // This check should involve compile time constants and be optimized out. if mask.0[i] != 0 { - out.0[i] = (*NVIC::PTR).iser[i].read(); + out.0[i] = unsafe { (*NVIC::PTR).iser[i].read() }; } } @@ -200,7 +202,9 @@ unsafe fn set_enable_mask<const M: usize>(mask: Mask<M>, old_mask: Mask<M>) { for i in 0..M { // This check should involve compile time constants and be optimized out. if mask.0[i] != 0 { - (*NVIC::PTR).iser[i].write(old_mask.0[i]); + unsafe { + (*NVIC::PTR).iser[i].write(old_mask.0[i]); + } } } } @@ -211,7 +215,9 @@ unsafe fn clear_enable_mask<const M: usize>(mask: Mask<M>) { for i in 0..M { // This check should involve compile time constants and be optimized out. if mask.0[i] != 0 { - (*NVIC::PTR).icer[i].write(mask.0[i]); + unsafe { + (*NVIC::PTR).icer[i].write(mask.0[i]); + } } } } |
