From aea28c8aa0bc13251835c6e38f4e1fbcbd30f4db Mon Sep 17 00:00:00 2001 From: kalkyl Date: Tue, 13 Dec 2022 09:45:11 +0100 Subject: [PATCH] Add usage in to docs --- embassy-rp/src/multicore.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs index 09d40b2e..3703fe81 100644 --- a/embassy-rp/src/multicore.rs +++ b/embassy-rp/src/multicore.rs @@ -1,4 +1,4 @@ -//! MultiCore support +//! Multicore support //! //! This module handles setup of the 2nd cpu core on the rp2040, which we refer to as core1. //! It provides functionality for setting up the stack, and starting core1. @@ -7,6 +7,28 @@ //! //! Enable the `critical-section-impl` feature in embassy-rp when sharing data across cores using //! the `embassy-sync` primitives and `CriticalSectionRawMutex`. +//! +//! # Usage +//! ```no_run +//! static mut CORE1_STACK: Stack<4096> = Stack::new(); +//! static EXECUTOR0: StaticCell = StaticCell::new(); +//! static EXECUTOR1: StaticCell = StaticCell::new(); +//! +//! #[cortex_m_rt::entry] +//! fn main() -> ! { +//! let p = embassy_rp::init(Default::default()); +//! +//! let mut mc = MultiCore::new(); +//! let _ = mc.cores.1.spawn(unsafe { &mut CORE1_STACK.mem }, move || { +//! let executor1 = EXECUTOR1.init(Executor::new()); +//! executor1.run(|spawner| unwrap!(spawner.spawn(core1_task()))); +//! }); +//! +//! let executor0 = EXECUTOR0.init(Executor::new()); +//! executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); +//! } +//! ``` +//! use core::mem::ManuallyDrop; use core::sync::atomic::{compiler_fence, Ordering}; @@ -28,14 +50,6 @@ pub enum Error { Unresponsive, } -/// Core ID -#[derive(Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CoreId { - Core0, - Core1, -} - #[inline(always)] fn install_stack_guard(stack_bottom: *mut usize) { let core = unsafe { cortex_m::Peripherals::steal() };