#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum CoreId {
#[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
Core0 = 0x3,
#[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
Core1 = 0x1,
#[cfg(not(any(stm32h745, stm32h747, stm32h755, stm32h757)))]
Core0 = 0x4,
#[cfg(any(stm32wb, stm32wl))]
Core1 = 0x8,
}
impl CoreId {
pub fn current() -> Self {
let cpuid = unsafe { cortex_m::peripheral::CPUID::PTR.read_volatile().base.read() };
match (cpuid & 0x000000F0) >> 4 {
#[cfg(any(stm32wb, stm32wl))]
0x0 => CoreId::Core1,
#[cfg(not(any(stm32h745, stm32h747, stm32h755, stm32h757)))]
0x4 => CoreId::Core0,
#[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
0x4 => CoreId::Core1,
#[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
0x7 => CoreId::Core0,
_ => panic!("Unknown Cortex-M core"),
}
}
#[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757, stm32wb, stm32wl))]
pub const fn other(&self) -> Self {
match &self {
Self::Core0 => Self::Core1,
Self::Core1 => Self::Core0,
}
}
pub const fn to_index(&self) -> usize {
match &self {
CoreId::Core0 => 0,
#[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757, stm32wb, stm32wl))]
CoreId::Core1 => 1,
}
}
}