|
1 |
| -use crate::interrupt; |
2 |
| -use crate::register::primask::{self, Primask}; |
| 1 | +#[cfg(all(cortex_m, feature = "single-core-critical-section"))] |
| 2 | +mod single_core_critical_section { |
| 3 | + use crate::interrupt; |
| 4 | + use crate::register::primask::{self, Primask}; |
3 | 5 |
|
4 |
| -struct CriticalSection; |
5 |
| -critical_section::custom_impl!(CriticalSection); |
| 6 | + struct CriticalSection; |
| 7 | + critical_section::custom_impl!(CriticalSection); |
6 | 8 |
|
7 |
| -const TOKEN_IGNORE: u8 = 0; |
8 |
| -const TOKEN_REENABLE: u8 = 1; |
| 9 | + const TOKEN_IGNORE: u8 = 0; |
| 10 | + const TOKEN_REENABLE: u8 = 1; |
9 | 11 |
|
10 |
| -unsafe impl critical_section::Impl for CriticalSection { |
11 |
| - unsafe fn acquire() -> u8 { |
12 |
| - match primask::read() { |
13 |
| - Primask::Active => { |
14 |
| - interrupt::disable(); |
15 |
| - TOKEN_REENABLE |
| 12 | + unsafe impl critical_section::Impl for CriticalSection { |
| 13 | + unsafe fn acquire() -> u8 { |
| 14 | + match primask::read() { |
| 15 | + Primask::Active => { |
| 16 | + interrupt::disable(); |
| 17 | + TOKEN_REENABLE |
| 18 | + } |
| 19 | + Primask::Inactive => TOKEN_IGNORE, |
16 | 20 | }
|
17 |
| - Primask::Inactive => TOKEN_IGNORE, |
18 | 21 | }
|
19 |
| - } |
20 | 22 |
|
21 |
| - unsafe fn release(token: u8) { |
22 |
| - // Only re-enable interrupts if they were enabled before the critical section. |
23 |
| - if token == TOKEN_REENABLE { |
24 |
| - interrupt::enable() |
| 23 | + unsafe fn release(token: u8) { |
| 24 | + // Only re-enable interrupts if they were enabled before the critical section. |
| 25 | + if token == TOKEN_REENABLE { |
| 26 | + interrupt::enable() |
| 27 | + } |
25 | 28 | }
|
26 | 29 | }
|
27 | 30 | }
|
| 31 | + |
| 32 | +pub use critical_section::with; |
0 commit comments