code/src/main.rs

62 lines
1.7 KiB
Rust
Raw Normal View History

2023-07-06 21:55:56 +00:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
2023-07-14 13:21:19 +00:00
use embassy_executor::Executor;
2023-07-06 21:55:56 +00:00
use embassy_executor::Spawner;
2023-07-14 13:21:19 +00:00
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;
2023-07-06 21:55:56 +00:00
use embassy_time::{Duration, Timer};
2023-07-14 13:21:19 +00:00
use static_cell::StaticCell;
2023-07-06 21:55:56 +00:00
use {defmt_rtt as _, panic_probe as _};
2023-07-14 13:21:19 +00:00
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();
2023-07-06 21:55:56 +00:00
2023-07-14 13:21:19 +00:00
enum LedState {
On,
Off,
}
2023-07-06 21:55:56 +00:00
2023-07-14 13:21:19 +00:00
#[cortex_m_rt::entry]
fn main() -> ! {
let p = embassy_rp::init(Default::default());
let led = Output::new(p.PIN_25, Level::Low);
2023-07-06 21:55:56 +00:00
2023-07-14 13:21:19 +00:00
spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || {
let executor1 = EXECUTOR1.init(Executor::new());
executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(led))));
});
2023-07-06 21:55:56 +00:00
2023-07-14 13:21:19 +00:00
let executor0 = EXECUTOR0.init(Executor::new());
executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
}
2023-07-06 21:55:56 +00:00
2023-07-14 13:21:19 +00:00
#[embassy_executor::task]
async fn core0_task() {
info!("Hello from core 0");
loop {
CHANNEL.send(LedState::On).await;
2023-07-06 21:55:56 +00:00
Timer::after(Duration::from_millis(100)).await;
2023-07-14 13:21:19 +00:00
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(),
}
2023-07-06 21:55:56 +00:00
}
}