diff --git a/src/riot-rs-embassy/Cargo.toml b/src/riot-rs-embassy/Cargo.toml index ba4e4bd47..5bbabdcb1 100644 --- a/src/riot-rs-embassy/Cargo.toml +++ b/src/riot-rs-embassy/Cargo.toml @@ -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] @@ -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 = [] diff --git a/src/riot-rs-embassy/src/arch/esp.rs b/src/riot-rs-embassy/src/arch/esp.rs index 6cb2364c5..4f500ff29 100644 --- a/src/riot-rs-embassy/src/arch/esp.rs +++ b/src/riot-rs-embassy/src/arch/esp.rs @@ -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; -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(); diff --git a/src/riot-rs-embassy/src/lib.rs b/src/riot-rs-embassy/src/lib.rs index bb48ec007..28af2d8e5 100644 --- a/src/riot-rs-embassy/src/lib.rs +++ b/src/riot-rs-embassy/src/lib.rs @@ -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] diff --git a/src/riot-rs-rt/Cargo.toml b/src/riot-rs-rt/Cargo.toml index 339f7941a..34d956e22 100644 --- a/src/riot-rs-rt/Cargo.toml +++ b/src/riot-rs-rt/Cargo.toml @@ -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 = [] diff --git a/src/riot-rs-rt/src/cortexm.rs b/src/riot-rs-rt/src/cortexm.rs index 9079c7e0a..b8e3de0f9 100644 --- a/src/riot-rs-rt/src/cortexm.rs +++ b/src/riot-rs-rt/src/cortexm.rs @@ -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; diff --git a/src/riot-rs-rt/src/lib.rs b/src/riot-rs-rt/src/lib.rs index 2eec80248..c45feb3f0 100644 --- a/src/riot-rs-rt/src/lib.rs +++ b/src/riot-rs-rt/src/lib.rs @@ -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)] diff --git a/src/riot-rs/Cargo.toml b/src/riot-rs/Cargo.toml index db63a4fbf..ece296979 100644 --- a/src/riot-rs/Cargo.toml +++ b/src/riot-rs/Cargo.toml @@ -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"]