diff options
| author | Dario Nieuwenhuis <[email protected]> | 2020-12-26 23:44:53 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2020-12-26 23:44:53 +0100 |
| commit | 692d8bb813f15f8add4783150768b9c4cae15182 (patch) | |
| tree | d01f0af03c129d6dbc4b6889d7095571a918def3 /examples | |
| parent | 8b7a42a4f9271c337d550be1f34e7d163f9eb905 (diff) | |
More efficient timer queue, integrated into Executor directly.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/src/bin/multiprio.rs | 20 | ||||
| -rw-r--r-- | examples/src/bin/rtc_async.rs | 8 |
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::*; | |||
| 64 | use cortex_m_rt::entry; | 64 | use cortex_m_rt::entry; |
| 65 | use nrf52840_hal::clocks; | 65 | use nrf52840_hal::clocks; |
| 66 | 66 | ||
| 67 | use embassy::executor::{task, TimerExecutor}; | 67 | use embassy::executor::{task, Executor}; |
| 68 | use embassy::time::{Duration, Instant, Timer}; | 68 | use embassy::time::{Duration, Instant, Timer}; |
| 69 | use embassy::util::Forever; | 69 | use embassy::util::Forever; |
| 70 | use embassy_nrf::{interrupt, pac, rtc}; | 70 | use embassy_nrf::{interrupt, pac, rtc}; |
| @@ -112,9 +112,12 @@ async fn run_low() { | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); | 114 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); |
| 115 | static EXECUTOR_LOW: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); | 115 | static ALARM_LOW: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); |
| 116 | static EXECUTOR_MED: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); | 116 | static EXECUTOR_LOW: Forever<Executor> = Forever::new(); |
| 117 | static EXECUTOR_HIGH: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); | 117 | static ALARM_MED: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); |
| 118 | static EXECUTOR_MED: Forever<Executor> = Forever::new(); | ||
| 119 | static ALARM_HIGH: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); | ||
| 120 | static EXECUTOR_HIGH: Forever<Executor> = Forever::new(); | ||
| 118 | 121 | ||
| 119 | #[entry] | 122 | #[entry] |
| 120 | fn main() -> ! { | 123 | fn 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; | |||
| 10 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| 11 | use nrf52840_hal::clocks; | 11 | use nrf52840_hal::clocks; |
| 12 | 12 | ||
| 13 | use embassy::executor::{task, TimerExecutor}; | 13 | use embassy::executor::{task, Executor}; |
| 14 | use embassy::time::{Clock, Duration, Timer}; | 14 | use embassy::time::{Clock, Duration, Timer}; |
| 15 | use embassy::util::Forever; | 15 | use embassy::util::Forever; |
| 16 | use embassy_nrf::pac; | 16 | use embassy_nrf::pac; |
| @@ -33,7 +33,8 @@ async fn run2() { | |||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); | 35 | static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new(); |
| 36 | static EXECUTOR: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new(); | 36 | static ALARM: Forever<rtc::Alarm<pac::RTC1>> = Forever::new(); |
| 37 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 37 | 38 | ||
| 38 | #[entry] | 39 | #[entry] |
| 39 | fn main() -> ! { | 40 | fn 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())); |
