diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-04-07 23:13:35 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-07 23:13:35 +0000 |
| commit | a23e971d313e8098b8d3a13f3ddf7629aa79a98c (patch) | |
| tree | d45c6783176caa1131fcbb022e62433ed7f73674 /tests | |
| parent | db3179cfb4be8596adbc601b27056bce03781407 (diff) | |
| parent | 313328c09a52ba6f8f30105a3a9f98a76a5aef69 (diff) | |
Merge pull request #4017 from shilga/SpinlockMutex
embassy-rp: Spinlock mutex implementation
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/src/bin/spinlock_mutex_multicore.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/rp/src/bin/spinlock_mutex_multicore.rs b/tests/rp/src/bin/spinlock_mutex_multicore.rs new file mode 100644 index 000000000..ebcf1ca32 --- /dev/null +++ b/tests/rp/src/bin/spinlock_mutex_multicore.rs | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #[cfg(feature = "rp2040")] | ||
| 4 | teleprobe_meta::target!(b"rpi-pico"); | ||
| 5 | #[cfg(feature = "rp235xb")] | ||
| 6 | teleprobe_meta::target!(b"pimoroni-pico-plus-2"); | ||
| 7 | |||
| 8 | use defmt::{info, unwrap}; | ||
| 9 | use embassy_executor::Executor; | ||
| 10 | use embassy_rp::multicore::{spawn_core1, Stack}; | ||
| 11 | use embassy_rp::spinlock_mutex::SpinlockRawMutex; | ||
| 12 | use embassy_sync::channel::Channel; | ||
| 13 | use static_cell::StaticCell; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | |||
| 16 | static mut CORE1_STACK: Stack<1024> = Stack::new(); | ||
| 17 | static EXECUTOR0: StaticCell<Executor> = StaticCell::new(); | ||
| 18 | static EXECUTOR1: StaticCell<Executor> = StaticCell::new(); | ||
| 19 | static CHANNEL0: Channel<SpinlockRawMutex<0>, bool, 1> = Channel::new(); | ||
| 20 | static CHANNEL1: Channel<SpinlockRawMutex<1>, bool, 1> = Channel::new(); | ||
| 21 | |||
| 22 | #[cortex_m_rt::entry] | ||
| 23 | fn main() -> ! { | ||
| 24 | let p = embassy_rp::init(Default::default()); | ||
| 25 | spawn_core1( | ||
| 26 | p.CORE1, | ||
| 27 | unsafe { &mut *core::ptr::addr_of_mut!(CORE1_STACK) }, | ||
| 28 | move || { | ||
| 29 | let executor1 = EXECUTOR1.init(Executor::new()); | ||
| 30 | executor1.run(|spawner| unwrap!(spawner.spawn(core1_task()))); | ||
| 31 | }, | ||
| 32 | ); | ||
| 33 | let executor0 = EXECUTOR0.init(Executor::new()); | ||
| 34 | executor0.run(|spawner| unwrap!(spawner.spawn(core0_task()))); | ||
| 35 | } | ||
| 36 | |||
| 37 | #[embassy_executor::task] | ||
| 38 | async fn core0_task() { | ||
| 39 | info!("CORE0 is running"); | ||
| 40 | let ping = true; | ||
| 41 | CHANNEL0.send(ping).await; | ||
| 42 | let pong = CHANNEL1.receive().await; | ||
| 43 | assert_eq!(ping, pong); | ||
| 44 | |||
| 45 | info!("Test OK"); | ||
| 46 | cortex_m::asm::bkpt(); | ||
| 47 | } | ||
| 48 | |||
| 49 | #[embassy_executor::task] | ||
| 50 | async fn core1_task() { | ||
| 51 | info!("CORE1 is running"); | ||
| 52 | let ping = CHANNEL0.receive().await; | ||
| 53 | CHANNEL1.send(ping).await; | ||
| 54 | } | ||
