aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2020-12-26 23:44:53 +0100
committerDario Nieuwenhuis <[email protected]>2020-12-26 23:44:53 +0100
commit692d8bb813f15f8add4783150768b9c4cae15182 (patch)
treed01f0af03c129d6dbc4b6889d7095571a918def3 /examples
parent8b7a42a4f9271c337d550be1f34e7d163f9eb905 (diff)
More efficient timer queue, integrated into Executor directly.
Diffstat (limited to 'examples')
-rw-r--r--examples/src/bin/multiprio.rs20
-rw-r--r--examples/src/bin/rtc_async.rs8
2 files changed, 18 insertions, 10 deletions
diff --git a/examples/src/bin/multiprio.rs b/examples/src/bin/multiprio.rs
index e73747ac6..be7e91a9d 100644
--- a/examples/src/bin/multiprio.rs
+++ b/examples/src/bin/multiprio.rs
@@ -64,7 +64,7 @@ use example_common::*;
64use cortex_m_rt::entry; 64use cortex_m_rt::entry;
65use nrf52840_hal::clocks; 65use nrf52840_hal::clocks;
66 66
67use embassy::executor::{task, TimerExecutor}; 67use embassy::executor::{task, Executor};
68use embassy::time::{Duration, Instant, Timer}; 68use embassy::time::{Duration, Instant, Timer};
69use embassy::util::Forever; 69use embassy::util::Forever;
70use embassy_nrf::{interrupt, pac, rtc}; 70use embassy_nrf::{interrupt, pac, rtc};
@@ -112,9 +112,12 @@ async fn run_low() {
112} 112}
113 113
114static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); 114static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
115static EXECUTOR_LOW: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); 115static ALARM_LOW: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
116static EXECUTOR_MED: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); 116static EXECUTOR_LOW: Forever<Executor> = Forever::new();
117static EXECUTOR_HIGH: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); 117static ALARM_MED: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
118static EXECUTOR_MED: Forever<Executor> = Forever::new();
119static ALARM_HIGH: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
120static EXECUTOR_HIGH: Forever<Executor> = Forever::new();
118 121
119#[entry] 122#[entry]
120fn main() -> ! { 123fn main() -> ! {
@@ -131,11 +134,14 @@ fn main() -> ! {
131 rtc.start(); 134 rtc.start();
132 unsafe { embassy::time::set_clock(rtc) }; 135 unsafe { embassy::time::set_clock(rtc) };
133 136
134 let executor_low = EXECUTOR_LOW.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev)); 137 let alarm_low = ALARM_LOW.put(rtc.alarm0());
135 let executor_med = EXECUTOR_MED.put(TimerExecutor::new(rtc.alarm1(), || { 138 let executor_low = EXECUTOR_LOW.put(Executor::new_with_alarm(alarm_low, cortex_m::asm::sev));
139 let alarm_med = ALARM_MED.put(rtc.alarm1());
140 let executor_med = EXECUTOR_MED.put(Executor::new_with_alarm(alarm_med, || {
136 interrupt::pend(interrupt::SWI0_EGU0) 141 interrupt::pend(interrupt::SWI0_EGU0)
137 })); 142 }));
138 let executor_high = EXECUTOR_HIGH.put(TimerExecutor::new(rtc.alarm2(), || { 143 let alarm_high = ALARM_HIGH.put(rtc.alarm2());
144 let executor_high = EXECUTOR_HIGH.put(Executor::new_with_alarm(alarm_high, || {
139 interrupt::pend(interrupt::SWI1_EGU1) 145 interrupt::pend(interrupt::SWI1_EGU1)
140 })); 146 }));
141 147
diff --git a/examples/src/bin/rtc_async.rs b/examples/src/bin/rtc_async.rs
index b4ee736b7..aec70a072 100644
--- a/examples/src/bin/rtc_async.rs
+++ b/examples/src/bin/rtc_async.rs
@@ -10,7 +10,7 @@ use core::mem::MaybeUninit;
10use cortex_m_rt::entry; 10use cortex_m_rt::entry;
11use nrf52840_hal::clocks; 11use nrf52840_hal::clocks;
12 12
13use embassy::executor::{task, TimerExecutor}; 13use embassy::executor::{task, Executor};
14use embassy::time::{Clock, Duration, Timer}; 14use embassy::time::{Clock, Duration, Timer};
15use embassy::util::Forever; 15use embassy::util::Forever;
16use embassy_nrf::pac; 16use embassy_nrf::pac;
@@ -33,7 +33,8 @@ async fn run2() {
33} 33}
34 34
35static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); 35static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
36static EXECUTOR: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); 36static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new();
37static EXECUTOR: Forever<Executor> = Forever::new();
37 38
38#[entry] 39#[entry]
39fn main() -> ! { 40fn main() -> ! {
@@ -51,7 +52,8 @@ fn main() -> ! {
51 52
52 unsafe { embassy::time::set_clock(rtc) }; 53 unsafe { embassy::time::set_clock(rtc) };
53 54
54 let executor = EXECUTOR.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev)); 55 let alarm = ALARM.put(rtc.alarm0());
56 let executor = EXECUTOR.put(Executor::new_with_alarm(alarm, cortex_m::asm::sev));
55 57
56 unwrap!(executor.spawn(run1())); 58 unwrap!(executor.spawn(run1()));
57 unwrap!(executor.spawn(run2())); 59 unwrap!(executor.spawn(run2()));