Test buffer and queue

This commit is contained in:
~erin 2023-07-14 10:30:54 -04:00
parent 35084d00d3
commit 3633c0e698
Signed by: erin
GPG Key ID: 9A8E308CEFA37A47
3 changed files with 43 additions and 13 deletions

14
Cargo.lock generated
View File

@ -222,8 +222,10 @@ dependencies = [
"embassy-rp",
"embassy-sync",
"embassy-time",
"nanorand",
"panic-probe",
"static_cell",
"tinyvec",
]
[[package]]
@ -811,6 +813,12 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "nanorand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3"
[[package]]
name = "nb"
version = "0.1.3"
@ -1307,6 +1315,12 @@ dependencies = [
"crunchy",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
[[package]]
name = "typenum"
version = "1.16.0"

View File

@ -17,3 +17,5 @@ embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy
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"]}
nanorand = { version = "0.7.0", default-features = false, features = ["wyrand"] }
tinyvec = "1.6.0"

View File

@ -4,7 +4,6 @@
use defmt::*;
use embassy_executor::Executor;
use embassy_executor::Spawner;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::multicore::{spawn_core1, Stack};
use embassy_rp::peripherals::PIN_25;
@ -14,14 +13,19 @@ use embassy_time::{Duration, Timer};
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<Executor> = StaticCell::new();
static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
static CHANNEL: Channel<CriticalSectionRawMutex, LedState, 1> = Channel::new();
static CHANNEL: Channel<CriticalSectionRawMutex, Buffer, 1> = Channel::new();
enum LedState {
On,
Off,
#[derive(Clone)]
struct Buffer([f32; BUF_SIZE]);
impl Default for Buffer {
fn default() -> Self {
Buffer([0.0; BUF_SIZE])
}
}
#[cortex_m_rt::entry]
@ -40,22 +44,32 @@ fn main() -> ! {
#[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 {
CHANNEL.send(LedState::On).await;
Timer::after(Duration::from_millis(100)).await;
CHANNEL.send(LedState::Off).await;
Timer::after(Duration::from_millis(400)).await;
if count >= BUF_SIZE {
CHANNEL.send(buf.clone()).await;
count = 0;
} else {
buf.0[count] = rng.generate::<f32>();
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 {
match CHANNEL.recv().await {
LedState::On => led.set_high(),
LedState::Off => led.set_low(),
}
queue.push(CHANNEL.recv().await)
}
}