aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/multicore.rs
diff options
context:
space:
mode:
authorkalkyl <[email protected]>2022-12-13 09:45:11 +0100
committerkalkyl <[email protected]>2022-12-13 09:45:11 +0100
commitaea28c8aa0bc13251835c6e38f4e1fbcbd30f4db (patch)
tree0f23bacf225f54eb6b05fcc3552992c84bd963a6 /embassy-rp/src/multicore.rs
parenteb1d2e1295cfd2f0580355d69c93387898eaabd4 (diff)
Add usage in to docs
Diffstat (limited to 'embassy-rp/src/multicore.rs')
-rw-r--r--embassy-rp/src/multicore.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs
index 09d40b2ef..3703fe819 100644
--- a/embassy-rp/src/multicore.rs
+++ b/embassy-rp/src/multicore.rs
@@ -1,4 +1,4 @@
1//! MultiCore support 1//! Multicore support
2//! 2//!
3//! This module handles setup of the 2nd cpu core on the rp2040, which we refer to as core1. 3//! This module handles setup of the 2nd cpu core on the rp2040, which we refer to as core1.
4//! It provides functionality for setting up the stack, and starting core1. 4//! It provides functionality for setting up the stack, and starting core1.
@@ -7,6 +7,28 @@
7//! 7//!
8//! Enable the `critical-section-impl` feature in embassy-rp when sharing data across cores using 8//! Enable the `critical-section-impl` feature in embassy-rp when sharing data across cores using
9//! the `embassy-sync` primitives and `CriticalSectionRawMutex`. 9//! the `embassy-sync` primitives and `CriticalSectionRawMutex`.
10//!
11//! # Usage
12//! ```no_run
13//! static mut CORE1_STACK: Stack<4096> = Stack::new();
14//! static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
15//! static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
16//!
17//! #[cortex_m_rt::entry]
18//! fn main() -> ! {
19//! let p = embassy_rp::init(Default::default());
20//!
21//! let mut mc = MultiCore::new();
22//! let _ = mc.cores.1.spawn(unsafe { &mut CORE1_STACK.mem }, move || {
23//! let executor1 = EXECUTOR1.init(Executor::new());
24//! executor1.run(|spawner| unwrap!(spawner.spawn(core1_task())));
25//! });
26//!
27//! let executor0 = EXECUTOR0.init(Executor::new());
28//! executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
29//! }
30//! ```
31//!
10 32
11use core::mem::ManuallyDrop; 33use core::mem::ManuallyDrop;
12use core::sync::atomic::{compiler_fence, Ordering}; 34use core::sync::atomic::{compiler_fence, Ordering};
@@ -28,14 +50,6 @@ pub enum Error {
28 Unresponsive, 50 Unresponsive,
29} 51}
30 52
31/// Core ID
32#[derive(Debug)]
33#[cfg_attr(feature = "defmt", derive(defmt::Format))]
34pub enum CoreId {
35 Core0,
36 Core1,
37}
38
39#[inline(always)] 53#[inline(always)]
40fn install_stack_guard(stack_bottom: *mut usize) { 54fn install_stack_guard(stack_bottom: *mut usize) {
41 let core = unsafe { cortex_m::Peripherals::steal() }; 55 let core = unsafe { cortex_m::Peripherals::steal() };