#![no_std] #![no_main] #![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Executor; 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 static_cell::StaticCell; use {defmt_rtt as _, panic_probe as _}; const BUF_SIZE: usize = 64; static mut CORE1_STACK: Stack<4096> = Stack::new(); static EXECUTOR0: StaticCell = StaticCell::new(); static EXECUTOR1: StaticCell = StaticCell::new(); static CHANNEL: Channel = Channel::new(); #[derive(Clone)] struct Buffer([f32; BUF_SIZE]); impl Default for Buffer { fn default() -> Self { Buffer([0.0; BUF_SIZE]) } } #[cortex_m_rt::entry] fn main() -> ! { let p = embassy_rp::init(Default::default()); let 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)))); }); let executor0 = EXECUTOR0.init(Executor::new()); executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); } #[embassy_executor::task] async fn core0_task() { use nanorand::{Rng, WyRand}; let mut rng = WyRand::new(); let mut buf = Buffer([0.0; BUF_SIZE]); let mut count = 0; info!("Hello from core 0"); // Sample EEG data loop { if count >= BUF_SIZE { CHANNEL.send(buf.clone()).await; count = 0; } else { buf.0[count] = rng.generate::(); count += 1; } } } #[embassy_executor::task] async fn core1_task(mut led: Output<'static, PIN_25>) { use tinyvec::ArrayVec; let mut queue = ArrayVec::<[Buffer; 64]>::new(); info!("Hello from core 1"); loop { queue.push(CHANNEL.recv().await); process_data(&queue[0]).await; queue.remove(1); } } async fn process_data(buf: &Buffer) { // Low-pass filter // FFT (w/ hanning window) info!("todo"); }