Skip to content

Commit

Permalink
support single thread mode executor, use for esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Mar 7, 2024
1 parent 8a31550 commit acb572c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
5 changes: 4 additions & 1 deletion src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ embassy-rp = { workspace = true, features = [
] }

[target.'cfg(context = "esp")'.dependencies]
esp-hal = { workspace = true, features = [ "embassy", "embassy-executor-interrupt" ] }
esp-hal = { workspace = true, features = [ "embassy", "embassy-executor-thread" ] }
esp-wifi = { workspace = true, features = [ "async", "embassy-net", "wifi" ], optional = true }

[target.'cfg(context = "esp32c3")'.dependencies]
Expand All @@ -82,3 +82,6 @@ wifi-cyw43 = ["dep:cyw43", "dep:cyw43-pio", "dep:embassy-net-driver-channel", "n
threading = ["dep:riot-rs-core"]
override-network-config = []
override-usb-config = []

executor-single-thread = []
executor-interrupt = []
20 changes: 3 additions & 17 deletions src/riot-rs-embassy/src/arch/esp.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
use esp_hal::{
clock::ClockControl,
embassy::{
self,
executor::{FromCpu1, InterruptExecutor},
},
prelude::*,
timer::TimerGroup,
};
use esp_hal::{clock::ClockControl, embassy, prelude::*, timer::TimerGroup};

pub use esp_hal::embassy::executor::Executor;

pub(crate) use esp_hal::interrupt::{self};
pub use esp_hal::peripherals::{OptionalPeripherals, Peripherals};

pub(crate) type Executor = InterruptExecutor<FromCpu1>;
pub static SWI: () = ();

#[derive(Default)]
pub struct Config {}

#[interrupt]
fn FROM_CPU_INTR1() {
unsafe { crate::EXECUTOR.on_interrupt() }
}

pub fn init(_config: Config) -> OptionalPeripherals {
let mut peripherals = OptionalPeripherals::from(Peripherals::take());
let system = peripherals.SYSTEM.take().unwrap().split();
Expand Down
23 changes: 17 additions & 6 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,36 @@ pub mod sendcell;

pub type Task = fn(&Spawner, &mut arch::OptionalPeripherals);

pub static EXECUTOR: arch::Executor = arch::Executor::new();

#[distributed_slice]
pub static EMBASSY_TASKS: [Task] = [..];

#[cfg(feature = "executor-interrupt")]
pub static EXECUTOR: arch::Executor = arch::Executor::new();

#[cfg(feature = "executor-interrupt")]
#[distributed_slice(riot_rs_rt::INIT_FUNCS)]
pub(crate) fn init() {
riot_rs_rt::debug::println!("riot-rs-embassy::init()");
let p = arch::init(Default::default());

#[cfg(any(context = "nrf52", context = "rp2040"))]
EXECUTOR.start(arch::SWI);
{
EXECUTOR.start(arch::SWI);
EXECUTOR.spawner().must_spawn(init_task(p));
}

#[cfg(context = "esp")]
EXECUTOR.start(arch::interrupt::Priority::Priority1);
EXECUTOR.run(|spawner| spawner.must_spawn(init_task(p)));
}

EXECUTOR.spawner().must_spawn(init_task(p));
#[cfg(feature = "executor-single-thread")]
#[export_name = "riot_rs_embassy_init"]
fn init() -> ! {
riot_rs_rt::debug::println!("riot-rs-embassy::init()");
let p = arch::init(Default::default());

riot_rs_rt::debug::println!("riot-rs-embassy::init() done");
let mut executor = make_static!(arch::Executor::new());
executor.run(|spawner| spawner.must_spawn(init_task(p)));
}

#[embassy_executor::task]
Expand Down
1 change: 1 addition & 0 deletions src/riot-rs-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ portable-atomic = { version = "1.6.0", default-features = false, features = ["re
#default = ["threading"]
threading = ["dep:riot-rs-threads"]
debug-console = []
executor-single-thread = []
silent-panic = []
_panic-handler = []

Expand Down
2 changes: 1 addition & 1 deletion src/riot-rs-rt/src/cortexm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn ipsr_isr_number_to_str(isr_number: usize) -> &'static str {
/// Extra verbose Cortex-M HardFault handler
///
/// (copied from Tock OS)
#[allow(non_snake_case)]
#[allow(non_snake_case, unsafe_op_in_unsafe_fn)]
#[exception]
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
use core::arch::asm;
Expand Down
8 changes: 8 additions & 0 deletions src/riot-rs-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ fn startup() -> ! {
}
}

#[cfg(feature = "executor-single-thread")]
{
extern "Rust" {
fn riot_rs_embassy_init();
}
unsafe { riot_rs_embassy_init() };
}

#[cfg(not(feature = "threading"))]
{
#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions src/riot-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ riot-rs-rt = { path = "../riot-rs-rt" }
riot-rs-threads = { path = "../riot-rs-threads", optional = true }
static_cell = { workspace = true }

[target.'cfg(context = "cortex-m")'.dependencies]
riot-rs-embassy = { path = "../riot-rs-embassy", features = [ "executor-interrupt" ] }

[target.'cfg(context = "esp")'.dependencies]
riot-rs-embassy = { path = "../riot-rs-embassy", features = [ "executor-single-thread" ] }
riot-rs-rt = { path = "../riot-rs-rt", features = [ "executor-single-thread" ] }

[features]
default = ["riot-rs-rt/_panic-handler"]

Expand Down

0 comments on commit acb572c

Please sign in to comment.