diff options
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/CHANGELOG.md | 4 | ||||
| -rw-r--r-- | embassy-executor/Cargo.toml | 1 | ||||
| -rw-r--r-- | embassy-executor/src/arch/xtensa.rs | 89 | ||||
| -rw-r--r-- | embassy-executor/src/lib.rs | 4 |
4 files changed, 5 insertions, 93 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md index 559717da6..c839981d6 100644 --- a/embassy-executor/CHANGELOG.md +++ b/embassy-executor/CHANGELOG.md | |||
| @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. | |||
| 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
| 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
| 7 | 7 | ||
| 8 | ## Unreleased | ||
| 9 | |||
| 10 | - Removed `arch-xtensa`. Use the executor provided by the HAL crate (`esp-hal`, `esp32s3-hal`, etc...) instead. | ||
| 11 | |||
| 8 | ## 0.3.3 - 2023-11-15 | 12 | ## 0.3.3 - 2023-11-15 |
| 9 | 13 | ||
| 10 | - Add `main` macro reexport for Xtensa arch. | 14 | - Add `main` macro reexport for Xtensa arch. |
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index ae46b17c6..bf58a2e1b 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -57,7 +57,6 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 57 | _arch = [] # some arch was picked | 57 | _arch = [] # some arch was picked |
| 58 | arch-std = ["_arch", "critical-section/std"] | 58 | arch-std = ["_arch", "critical-section/std"] |
| 59 | arch-cortex-m = ["_arch", "dep:cortex-m"] | 59 | arch-cortex-m = ["_arch", "dep:cortex-m"] |
| 60 | arch-xtensa = ["_arch"] | ||
| 61 | arch-riscv32 = ["_arch", "dep:portable-atomic"] | 60 | arch-riscv32 = ["_arch", "dep:portable-atomic"] |
| 62 | arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] | 61 | arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] |
| 63 | 62 | ||
diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs deleted file mode 100644 index 6ed9f9e72..000000000 --- a/embassy-executor/src/arch/xtensa.rs +++ /dev/null | |||
| @@ -1,89 +0,0 @@ | |||
| 1 | #[cfg(feature = "executor-interrupt")] | ||
| 2 | compile_error!("`executor-interrupt` is not supported with `arch-xtensa`."); | ||
| 3 | |||
| 4 | #[cfg(feature = "executor-thread")] | ||
| 5 | pub use thread::*; | ||
| 6 | #[cfg(feature = "executor-thread")] | ||
| 7 | mod thread { | ||
| 8 | use core::marker::PhantomData; | ||
| 9 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 10 | |||
| 11 | pub use embassy_macros::main_riscv as main; | ||
| 12 | |||
| 13 | use crate::{raw, Spawner}; | ||
| 14 | |||
| 15 | /// global atomic used to keep track of whether there is work to do since sev() is not available on Xtensa | ||
| 16 | static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); | ||
| 17 | |||
| 18 | #[export_name = "__pender"] | ||
| 19 | fn __pender(_context: *mut ()) { | ||
| 20 | SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); | ||
| 21 | } | ||
| 22 | |||
| 23 | /// Xtensa Executor | ||
| 24 | pub struct Executor { | ||
| 25 | inner: raw::Executor, | ||
| 26 | not_send: PhantomData<*mut ()>, | ||
| 27 | } | ||
| 28 | |||
| 29 | impl Executor { | ||
| 30 | /// Create a new Executor. | ||
| 31 | pub fn new() -> Self { | ||
| 32 | Self { | ||
| 33 | inner: raw::Executor::new(core::ptr::null_mut()), | ||
| 34 | not_send: PhantomData, | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | /// Run the executor. | ||
| 39 | /// | ||
| 40 | /// The `init` closure is called with a [`Spawner`] that spawns tasks on | ||
| 41 | /// this executor. Use it to spawn the initial task(s). After `init` returns, | ||
| 42 | /// the executor starts running the tasks. | ||
| 43 | /// | ||
| 44 | /// To spawn more tasks later, you may keep copies of the [`Spawner`] (it is `Copy`), | ||
| 45 | /// for example by passing it as an argument to the initial tasks. | ||
| 46 | /// | ||
| 47 | /// This function requires `&'static mut self`. This means you have to store the | ||
| 48 | /// Executor instance in a place where it'll live forever and grants you mutable | ||
| 49 | /// access. There's a few ways to do this: | ||
| 50 | /// | ||
| 51 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) | ||
| 52 | /// - a `static mut` (unsafe) | ||
| 53 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | ||
| 54 | /// | ||
| 55 | /// This function never returns. | ||
| 56 | pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { | ||
| 57 | init(self.inner.spawner()); | ||
| 58 | |||
| 59 | loop { | ||
| 60 | unsafe { | ||
| 61 | self.inner.poll(); | ||
| 62 | |||
| 63 | // Manual critical section implementation that only masks interrupts handlers. | ||
| 64 | // We must not acquire the cross-core on dual-core systems because that would | ||
| 65 | // prevent the other core from doing useful work while this core is sleeping. | ||
| 66 | let token: critical_section::RawRestoreState; | ||
| 67 | core::arch::asm!("rsil {0}, 5", out(reg) token); | ||
| 68 | |||
| 69 | // we do not care about race conditions between the load and store operations, interrupts | ||
| 70 | // will only set this value to true. | ||
| 71 | // if there is work to do, loop back to polling | ||
| 72 | if SIGNAL_WORK_THREAD_MODE.load(Ordering::SeqCst) { | ||
| 73 | SIGNAL_WORK_THREAD_MODE.store(false, Ordering::SeqCst); | ||
| 74 | |||
| 75 | core::arch::asm!( | ||
| 76 | "wsr.ps {0}", | ||
| 77 | "rsync", in(reg) token) | ||
| 78 | } else { | ||
| 79 | // waiti sets the PS.INTLEVEL when slipping into sleep | ||
| 80 | // because critical sections in Xtensa are implemented via increasing | ||
| 81 | // PS.INTLEVEL the critical section ends here | ||
| 82 | // take care not add code after `waiti` if it needs to be inside the CS | ||
| 83 | core::arch::asm!("waiti 0"); // critical section ends here | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index d8ac4893b..897696150 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] | 1 | #![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)] |
| 2 | #![cfg_attr(feature = "arch-xtensa", feature(asm_experimental_arch))] | ||
| 3 | #![allow(clippy::new_without_default)] | 2 | #![allow(clippy::new_without_default)] |
| 4 | #![doc = include_str!("../README.md")] | 3 | #![doc = include_str!("../README.md")] |
| 5 | #![warn(missing_docs)] | 4 | #![warn(missing_docs)] |
| @@ -21,12 +20,11 @@ macro_rules! check_at_most_one { | |||
| 21 | check_at_most_one!(@amo [$($f)*] [$($f)*] []); | 20 | check_at_most_one!(@amo [$($f)*] [$($f)*] []); |
| 22 | }; | 21 | }; |
| 23 | } | 22 | } |
| 24 | check_at_most_one!("arch-cortex-m", "arch-riscv32", "arch-xtensa", "arch-std", "arch-wasm",); | 23 | check_at_most_one!("arch-cortex-m", "arch-riscv32", "arch-std", "arch-wasm",); |
| 25 | 24 | ||
| 26 | #[cfg(feature = "_arch")] | 25 | #[cfg(feature = "_arch")] |
| 27 | #[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")] | 26 | #[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")] |
| 28 | #[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")] | 27 | #[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")] |
| 29 | #[cfg_attr(feature = "arch-xtensa", path = "arch/xtensa.rs")] | ||
| 30 | #[cfg_attr(feature = "arch-std", path = "arch/std.rs")] | 28 | #[cfg_attr(feature = "arch-std", path = "arch/std.rs")] |
| 31 | #[cfg_attr(feature = "arch-wasm", path = "arch/wasm.rs")] | 29 | #[cfg_attr(feature = "arch-wasm", path = "arch/wasm.rs")] |
| 32 | mod arch; | 30 | mod arch; |
