2020-12-31 04:14:56 +01:00
|
|
|
use core::sync::atomic::{compiler_fence, Ordering};
|
|
|
|
|
|
|
|
use crate::pac::NVIC_PRIO_BITS;
|
|
|
|
|
|
|
|
// Re-exports
|
|
|
|
pub use cortex_m::interrupt::{CriticalSection, Mutex};
|
2021-02-26 01:55:27 +01:00
|
|
|
pub use embassy::interrupt::{declare, take, Interrupt};
|
2020-12-31 04:14:56 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
|
#[repr(u8)]
|
|
|
|
pub enum Priority {
|
|
|
|
Level0 = 0,
|
|
|
|
Level1 = 1,
|
|
|
|
Level2 = 2,
|
|
|
|
Level3 = 3,
|
|
|
|
Level4 = 4,
|
|
|
|
Level5 = 5,
|
|
|
|
Level6 = 6,
|
|
|
|
Level7 = 7,
|
2021-01-06 00:18:24 +01:00
|
|
|
Level8 = 8,
|
|
|
|
Level9 = 9,
|
|
|
|
Level10 = 10,
|
|
|
|
Level11 = 11,
|
|
|
|
Level12 = 12,
|
|
|
|
Level13 = 13,
|
|
|
|
Level14 = 14,
|
2021-01-06 00:24:27 +01:00
|
|
|
Level15 = 15,
|
2020-12-31 04:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<u8> for Priority {
|
|
|
|
fn from(priority: u8) -> Self {
|
|
|
|
match priority >> (8 - NVIC_PRIO_BITS) {
|
|
|
|
0 => Self::Level0,
|
|
|
|
1 => Self::Level1,
|
|
|
|
2 => Self::Level2,
|
|
|
|
3 => Self::Level3,
|
|
|
|
4 => Self::Level4,
|
|
|
|
5 => Self::Level5,
|
|
|
|
6 => Self::Level6,
|
|
|
|
7 => Self::Level7,
|
2021-01-06 00:38:46 +01:00
|
|
|
8 => Self::Level8,
|
|
|
|
9 => Self::Level9,
|
|
|
|
10 => Self::Level10,
|
|
|
|
11 => Self::Level11,
|
|
|
|
12 => Self::Level12,
|
|
|
|
13 => Self::Level13,
|
|
|
|
14 => Self::Level14,
|
|
|
|
15 => Self::Level15,
|
2020-12-31 04:14:56 +01:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Priority> for u8 {
|
|
|
|
fn from(p: Priority) -> Self {
|
|
|
|
(p as u8) << (8 - NVIC_PRIO_BITS)
|
|
|
|
}
|
|
|
|
}
|