Multicore support

This commit is contained in:
~erin 2023-07-14 09:21:19 -04:00
parent 9a82a0b2c8
commit 35084d00d3
Signed by: erin
GPG Key ID: 9A8E308CEFA37A47
3 changed files with 799 additions and 98 deletions

824
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,8 @@ defmt = "0.3"
defmt-rtt = "0.3"
panic-probe = { version = "0.3", features = ["print-defmt"] }
embassy-executor = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "integrated-timers"] }
embassy-executor = { version = "0.2.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "integrated-timers", "nightly", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] }
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver"] }
embassy-sync = { version = "0.2.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt"] }
static_cell = { version = "1.1", features = ["nightly"]}

View File

@ -3,38 +3,59 @@
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Executor;
use embassy_executor::Spawner;
use embassy_rp::gpio;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::multicore::{spawn_core1, Stack};
use embassy_rp::peripherals::PIN_25;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::Channel;
use embassy_time::{Duration, Timer};
use gpio::{Level, Output};
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
// Initialise Peripherals
static mut CORE1_STACK: Stack<4096> = Stack::new();
static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
static CHANNEL: Channel<CriticalSectionRawMutex, LedState, 1> = Channel::new();
enum LedState {
On,
Off,
}
#[cortex_m_rt::entry]
fn main() -> ! {
let p = embassy_rp::init(Default::default());
let led = Output::new(p.PIN_25, Level::Low);
// Create LED
let mut led = Output::new(p.PIN_25, Level::Low);
spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || {
let executor1 = EXECUTOR1.init(Executor::new());
executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(led))));
});
// Loop
let executor0 = EXECUTOR0.init(Executor::new());
executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
}
#[embassy_executor::task]
async fn core0_task() {
info!("Hello from core 0");
loop {
// Log
info!("LED On!");
// Turn LED On
led.set_high();
// Wait 100ms
Timer::after(Duration::from_millis(100)).await;
// Log
info!("LED Off!");
// Turn Led Off
led.set_low();
// Wait 100ms
CHANNEL.send(LedState::On).await;
Timer::after(Duration::from_millis(100)).await;
CHANNEL.send(LedState::Off).await;
Timer::after(Duration::from_millis(400)).await;
}
}
#[embassy_executor::task]
async fn core1_task(mut led: Output<'static, PIN_25>) {
info!("Hello from core 1");
loop {
match CHANNEL.recv().await {
LedState::On => led.set_high(),
LedState::Off => led.set_low(),
}
}
}