aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpennae <[email protected]>2023-05-02 08:39:05 +0200
committerpennae <[email protected]>2023-05-02 14:28:27 +0200
commit849011b8261194629830b4b85d062394e8eb3c58 (patch)
treeb66b95d3a970a27c89efa42839ef1e44e20fe0eb /tests
parent8fc92fdf6285190a1ba5ddf356958d49ed4225a3 (diff)
rp/gpio: set up gpio interrupts only once
doing this setup work repeatedly, on every wait, is unnecessary. with nothing ever disabling the interrupt it is sufficient to enable it once during device init and never touch it again.
Diffstat (limited to 'tests')
-rw-r--r--tests/rp/src/bin/gpio_multicore.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/rp/src/bin/gpio_multicore.rs b/tests/rp/src/bin/gpio_multicore.rs
new file mode 100644
index 000000000..6c13ccaae
--- /dev/null
+++ b/tests/rp/src/bin/gpio_multicore.rs
@@ -0,0 +1,63 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{info, unwrap};
6use embassy_executor::Executor;
7use embassy_executor::_export::StaticCell;
8use embassy_rp::gpio::{Input, Level, Output, Pull};
9use embassy_rp::multicore::{spawn_core1, Stack};
10use embassy_rp::peripherals::{PIN_0, PIN_1};
11use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
12use embassy_sync::channel::Channel;
13use {defmt_rtt as _, panic_probe as _};
14
15static mut CORE1_STACK: Stack<1024> = Stack::new();
16static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
17static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
18static CHANNEL0: Channel<CriticalSectionRawMutex, (), 1> = Channel::new();
19static CHANNEL1: Channel<CriticalSectionRawMutex, (), 1> = Channel::new();
20
21#[cortex_m_rt::entry]
22fn main() -> ! {
23 let p = embassy_rp::init(Default::default());
24 spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || {
25 let executor1 = EXECUTOR1.init(Executor::new());
26 executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(p.PIN_1))));
27 });
28 let executor0 = EXECUTOR0.init(Executor::new());
29 executor0.run(|spawner| unwrap!(spawner.spawn(core0_task(p.PIN_0))));
30}
31
32#[embassy_executor::task]
33async fn core0_task(p: PIN_0) {
34 info!("CORE0 is running");
35
36 let mut pin = Output::new(p, Level::Low);
37
38 CHANNEL0.send(()).await;
39 CHANNEL1.recv().await;
40
41 pin.set_high();
42
43 CHANNEL1.recv().await;
44
45 info!("Test OK");
46 cortex_m::asm::bkpt();
47}
48
49#[embassy_executor::task]
50async fn core1_task(p: PIN_1) {
51 info!("CORE1 is running");
52
53 CHANNEL0.recv().await;
54
55 let mut pin = Input::new(p, Pull::Down);
56 let wait = pin.wait_for_rising_edge();
57
58 CHANNEL1.send(()).await;
59
60 wait.await;
61
62 CHANNEL1.send(()).await;
63}