From 3c0d5063fe59c6831fbcfeae04338606aec05d05 Mon Sep 17 00:00:00 2001 From: Adrian Wowk Date: Wed, 2 Jul 2025 12:31:38 -0500 Subject: rp: add current_core api --- embassy-rp/src/multicore.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs index d10b6837c..64065fcba 100644 --- a/embassy-rp/src/multicore.rs +++ b/embassy-rp/src/multicore.rs @@ -57,6 +57,26 @@ const PAUSE_TOKEN: u32 = 0xDEADBEEF; const RESUME_TOKEN: u32 = !0xDEADBEEF; static IS_CORE1_INIT: AtomicBool = AtomicBool::new(false); +/// Represents a partiticular CPU core (SIO_CPUID) +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[repr(u8)] +pub enum CoreId { + /// Core 0 + Core0 = 0x0, + /// Core 1 + Core1 = 0x1, +} + +/// Gets which core we are currently executing from +pub fn current_core() -> CoreId { + if pac::SIO.cpuid().read() == 0 { + CoreId::Core0 + } else { + CoreId::Core1 + } +} + #[inline(always)] unsafe fn core1_setup(stack_bottom: *mut usize) { if install_stack_guard(stack_bottom).is_err() { -- cgit