aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-05-02 12:56:51 +0000
committerGitHub <[email protected]>2023-05-02 12:56:51 +0000
commitb2047c435133c6bd11918e89af81cab75c3354f1 (patch)
treeed8f4ca275045aab286298ea7a808928ea1da6c5 /tests
parent5f99ccf54c1e2eebcd121a4281084fa54ee03fad (diff)
parent849011b8261194629830b4b85d062394e8eb3c58 (diff)
Merge #1423
1423: rp: fix gpio InputFuture and inefficiencies r=pennae a=pennae InputFuture could not wait for edges without breaking due to a broken From impl, but even if the impl had been correct it would not have worked correctly because raw edge interrupts are sticky and must be cleared from software. also replace critical sections with atomic accesses, and do nvic setup only once. Co-authored-by: pennae <[email protected]>
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}