mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 16:23:10 +00:00
Remove executor model (it's not a nice enough abstraction).
This commit is contained in:
parent
19a89b5c14
commit
f88f233e39
@ -6,33 +6,19 @@ use crate::time::Alarm;
|
||||
|
||||
pub use se::{task, SpawnError, SpawnToken};
|
||||
|
||||
pub trait Model {
|
||||
fn signal();
|
||||
}
|
||||
|
||||
pub struct WfeModel;
|
||||
|
||||
impl Model for WfeModel {
|
||||
fn signal() {
|
||||
cortex_m::asm::sev()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Executor<M, A: Alarm> {
|
||||
pub struct Executor<A: Alarm> {
|
||||
inner: se::Executor,
|
||||
alarm: A,
|
||||
timer: time::TimerService,
|
||||
_phantom: PhantomData<M>,
|
||||
}
|
||||
|
||||
impl<M: Model, A: Alarm> Executor<M, A> {
|
||||
pub fn new(alarm: A) -> Self {
|
||||
alarm.set_callback(M::signal);
|
||||
impl<A: Alarm> Executor<A> {
|
||||
pub fn new(alarm: A, signal_fn: fn()) -> Self {
|
||||
alarm.set_callback(signal_fn);
|
||||
Self {
|
||||
inner: se::Executor::new(M::signal),
|
||||
inner: se::Executor::new(signal_fn),
|
||||
alarm,
|
||||
timer: time::TimerService::new(time::IntrusiveClock),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +32,7 @@ impl<M: Model, A: Alarm> Executor<M, A> {
|
||||
/// Runs the executor until the queue is empty.
|
||||
///
|
||||
/// safety: can only be called from the executor thread
|
||||
pub unsafe fn run_once(&'static self) {
|
||||
pub unsafe fn run(&'static self) {
|
||||
time::with_timer_service(&self.timer, || {
|
||||
self.timer.check_expirations();
|
||||
self.inner.run();
|
||||
@ -60,14 +46,3 @@ impl<M: Model, A: Alarm> Executor<M, A> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Alarm> Executor<WfeModel, A> {
|
||||
/// Runs the executor forever
|
||||
/// safety: can only be called from the executor thread
|
||||
pub unsafe fn run(&'static self) -> ! {
|
||||
loop {
|
||||
self.run_once();
|
||||
cortex_m::asm::wfe()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use example_common::*;
|
||||
|
||||
use core::mem::MaybeUninit;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy::executor::{task, Executor, WfeModel};
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::time::{Clock, Duration, Timer};
|
||||
use embassy_nrf::pac;
|
||||
use embassy_nrf::rtc;
|
||||
@ -31,7 +31,7 @@ async fn run2() {
|
||||
}
|
||||
|
||||
static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit();
|
||||
static mut EXECUTOR: MaybeUninit<Executor<WfeModel, rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit();
|
||||
static mut EXECUTOR: MaybeUninit<Executor<rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -55,7 +55,7 @@ fn main() -> ! {
|
||||
|
||||
let executor: &'static _ = unsafe {
|
||||
let ptr = EXECUTOR.as_mut_ptr();
|
||||
ptr.write(Executor::new(rtc.alarm0()));
|
||||
ptr.write(Executor::new(rtc.alarm0(), cortex_m::asm::sev));
|
||||
&*ptr
|
||||
};
|
||||
|
||||
@ -63,6 +63,9 @@ fn main() -> ! {
|
||||
executor.spawn(run1()).dewrap();
|
||||
executor.spawn(run2()).dewrap();
|
||||
|
||||
executor.run()
|
||||
loop {
|
||||
executor.run();
|
||||
cortex_m::asm::wfe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user