aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2020-09-25 23:42:49 +0200
committerDario Nieuwenhuis <[email protected]>2020-09-25 23:42:49 +0200
commitf88f233e39f1edef04a51b888a47b9e231fc228f (patch)
treeccac7bf5f4934053ab37c9e70f14879405bf950c
parent19a89b5c143205cc2a2d05b07cc4bffd15246e98 (diff)
Remove executor model (it's not a nice enough abstraction).
-rw-r--r--embassy/src/executor.rs37
-rw-r--r--examples/src/bin/rtc_async.rs11
2 files changed, 13 insertions, 35 deletions
diff --git a/embassy/src/executor.rs b/embassy/src/executor.rs
index 2c7cc5786..d42a19b9a 100644
--- a/embassy/src/executor.rs
+++ b/embassy/src/executor.rs
@@ -6,33 +6,19 @@ use crate::time::Alarm;
6 6
7pub use se::{task, SpawnError, SpawnToken}; 7pub use se::{task, SpawnError, SpawnToken};
8 8
9pub trait Model { 9pub struct Executor<A: Alarm> {
10 fn signal();
11}
12
13pub struct WfeModel;
14
15impl Model for WfeModel {
16 fn signal() {
17 cortex_m::asm::sev()
18 }
19}
20
21pub struct Executor<M, A: Alarm> {
22 inner: se::Executor, 10 inner: se::Executor,
23 alarm: A, 11 alarm: A,
24 timer: time::TimerService, 12 timer: time::TimerService,
25 _phantom: PhantomData<M>,
26} 13}
27 14
28impl<M: Model, A: Alarm> Executor<M, A> { 15impl<A: Alarm> Executor<A> {
29 pub fn new(alarm: A) -> Self { 16 pub fn new(alarm: A, signal_fn: fn()) -> Self {
30 alarm.set_callback(M::signal); 17 alarm.set_callback(signal_fn);
31 Self { 18 Self {
32 inner: se::Executor::new(M::signal), 19 inner: se::Executor::new(signal_fn),
33 alarm, 20 alarm,
34 timer: time::TimerService::new(time::IntrusiveClock), 21 timer: time::TimerService::new(time::IntrusiveClock),
35 _phantom: PhantomData,
36 } 22 }
37 } 23 }
38 24
@@ -46,7 +32,7 @@ impl<M: Model, A: Alarm> Executor<M, A> {
46 /// Runs the executor until the queue is empty. 32 /// Runs the executor until the queue is empty.
47 /// 33 ///
48 /// safety: can only be called from the executor thread 34 /// safety: can only be called from the executor thread
49 pub unsafe fn run_once(&'static self) { 35 pub unsafe fn run(&'static self) {
50 time::with_timer_service(&self.timer, || { 36 time::with_timer_service(&self.timer, || {
51 self.timer.check_expirations(); 37 self.timer.check_expirations();
52 self.inner.run(); 38 self.inner.run();
@@ -60,14 +46,3 @@ impl<M: Model, A: Alarm> Executor<M, A> {
60 }) 46 })
61 } 47 }
62} 48}
63
64impl<A: Alarm> Executor<WfeModel, A> {
65 /// Runs the executor forever
66 /// safety: can only be called from the executor thread
67 pub unsafe fn run(&'static self) -> ! {
68 loop {
69 self.run_once();
70 cortex_m::asm::wfe()
71 }
72 }
73}
diff --git a/examples/src/bin/rtc_async.rs b/examples/src/bin/rtc_async.rs
index a4149ef1e..30b181a93 100644
--- a/examples/src/bin/rtc_async.rs
+++ b/examples/src/bin/rtc_async.rs
@@ -8,7 +8,7 @@ use example_common::*;
8 8
9use core::mem::MaybeUninit; 9use core::mem::MaybeUninit;
10use cortex_m_rt::entry; 10use cortex_m_rt::entry;
11use embassy::executor::{task, Executor, WfeModel}; 11use embassy::executor::{task, Executor};
12use embassy::time::{Clock, Duration, Timer}; 12use embassy::time::{Clock, Duration, Timer};
13use embassy_nrf::pac; 13use embassy_nrf::pac;
14use embassy_nrf::rtc; 14use embassy_nrf::rtc;
@@ -31,7 +31,7 @@ async fn run2() {
31} 31}
32 32
33static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit(); 33static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit();
34static mut EXECUTOR: MaybeUninit<Executor<WfeModel, rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit(); 34static mut EXECUTOR: MaybeUninit<Executor<rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit();
35 35
36#[entry] 36#[entry]
37fn main() -> ! { 37fn main() -> ! {
@@ -55,7 +55,7 @@ fn main() -> ! {
55 55
56 let executor: &'static _ = unsafe { 56 let executor: &'static _ = unsafe {
57 let ptr = EXECUTOR.as_mut_ptr(); 57 let ptr = EXECUTOR.as_mut_ptr();
58 ptr.write(Executor::new(rtc.alarm0())); 58 ptr.write(Executor::new(rtc.alarm0(), cortex_m::asm::sev));
59 &*ptr 59 &*ptr
60 }; 60 };
61 61
@@ -63,6 +63,9 @@ fn main() -> ! {
63 executor.spawn(run1()).dewrap(); 63 executor.spawn(run1()).dewrap();
64 executor.spawn(run2()).dewrap(); 64 executor.spawn(run2()).dewrap();
65 65
66 executor.run() 66 loop {
67 executor.run();
68 cortex_m::asm::wfe();
69 }
67 } 70 }
68} 71}