diff options
| author | Robin Mueller <[email protected]> | 2025-03-09 20:55:11 +0100 |
|---|---|---|
| committer | Robin Mueller <[email protected]> | 2025-05-28 17:00:42 +0200 |
| commit | 5a07ea5d851768223e2e41342e69d14c1afb2b2b (patch) | |
| tree | a9b6980ee1c3301bef0dc7c8d287add2ed4a43a8 | |
| parent | f35aa4005a63e8d478b2b95aaa2bfb316b72dece (diff) | |
Add support for Cortex-A/R
| -rwxr-xr-x | ci-nightly.sh | 1 | ||||
| -rwxr-xr-x | ci.sh | 3 | ||||
| -rw-r--r-- | embassy-executor-macros/src/lib.rs | 25 | ||||
| -rw-r--r-- | embassy-executor-macros/src/macros/main.rs | 6 | ||||
| -rw-r--r-- | embassy-executor/CHANGELOG.md | 4 | ||||
| -rw-r--r-- | embassy-executor/Cargo.toml | 5 | ||||
| -rw-r--r-- | embassy-executor/src/arch/cortex_ar.rs | 84 | ||||
| -rw-r--r-- | embassy-executor/src/lib.rs | 2 | ||||
| -rw-r--r-- | rust-toolchain-nightly.toml | 1 | ||||
| -rw-r--r-- | rust-toolchain.toml | 3 |
10 files changed, 134 insertions, 0 deletions
diff --git a/ci-nightly.sh b/ci-nightly.sh index c0a2482e7..d486d442c 100755 --- a/ci-nightly.sh +++ b/ci-nightly.sh | |||
| @@ -21,5 +21,6 @@ cargo batch \ | |||
| 21 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32 \ | 21 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32 \ |
| 22 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread \ | 22 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread \ |
| 23 | --- build --release --manifest-path examples/nrf52840-rtic/Cargo.toml --target thumbv7em-none-eabi --artifact-dir out/examples/nrf52840-rtic \ | 23 | --- build --release --manifest-path examples/nrf52840-rtic/Cargo.toml --target thumbv7em-none-eabi --artifact-dir out/examples/nrf52840-rtic \ |
| 24 | --- build --release --manifest-path embassy-executor/Cargo.toml --target armv7a-none-eabi --features nightly,arch-cortex-ar,executor-thread \ | ||
| 24 | 25 | ||
| 25 | RUSTFLAGS="$RUSTFLAGS -C target-cpu=atmega328p" cargo build --release --manifest-path embassy-executor/Cargo.toml --target avr-none -Z build-std=core,alloc --features nightly,arch-avr,avr-device/atmega328p | 26 | RUSTFLAGS="$RUSTFLAGS -C target-cpu=atmega328p" cargo build --release --manifest-path embassy-executor/Cargo.toml --target avr-none -Z build-std=core,alloc --features nightly,arch-avr,avr-device/atmega328p |
| @@ -35,6 +35,9 @@ cargo batch \ | |||
| 35 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread \ | 35 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread \ |
| 36 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-interrupt \ | 36 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-interrupt \ |
| 37 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread,executor-interrupt \ | 37 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features arch-cortex-m,executor-thread,executor-interrupt \ |
| 38 | --- build --release --manifest-path embassy-executor/Cargo.toml --target armv7a-none-eabi --features arch-cortex-ar,executor-thread \ | ||
| 39 | --- build --release --manifest-path embassy-executor/Cargo.toml --target armv7r-none-eabi --features arch-cortex-ar,executor-thread \ | ||
| 40 | --- build --release --manifest-path embassy-executor/Cargo.toml --target armv7r-none-eabihf --features arch-cortex-ar,executor-thread \ | ||
| 38 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32 \ | 41 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32 \ |
| 39 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread \ | 42 | --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread \ |
| 40 | --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \ | 43 | --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \ |
diff --git a/embassy-executor-macros/src/lib.rs b/embassy-executor-macros/src/lib.rs index 8e737db6a..962ce2e75 100644 --- a/embassy-executor-macros/src/lib.rs +++ b/embassy-executor-macros/src/lib.rs | |||
| @@ -70,6 +70,31 @@ pub fn main_cortex_m(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 70 | main::run(args.into(), item.into(), &main::ARCH_CORTEX_M).into() | 70 | main::run(args.into(), item.into(), &main::ARCH_CORTEX_M).into() |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | /// Creates a new `executor` instance and declares an application entry point for Cortex-A/R | ||
| 74 | /// spawning the corresponding function body as an async task. | ||
| 75 | /// | ||
| 76 | /// The following restrictions apply: | ||
| 77 | /// | ||
| 78 | /// * The function must accept exactly 1 parameter, an `embassy_executor::Spawner` handle that it | ||
| 79 | /// can use to spawn additional tasks. | ||
| 80 | /// * The function must be declared `async`. | ||
| 81 | /// * The function must not use generics. | ||
| 82 | /// * Only a single `main` task may be declared. | ||
| 83 | /// | ||
| 84 | /// ## Examples | ||
| 85 | /// Spawning a task: | ||
| 86 | /// | ||
| 87 | /// ``` rust | ||
| 88 | /// #[embassy_executor::main] | ||
| 89 | /// async fn main(_s: embassy_executor::Spawner) { | ||
| 90 | /// // Function body | ||
| 91 | /// } | ||
| 92 | /// ``` | ||
| 93 | #[proc_macro_attribute] | ||
| 94 | pub fn main_cortex_ar(args: TokenStream, item: TokenStream) -> TokenStream { | ||
| 95 | main::run(args.into(), item.into(), &main::ARCH_CORTEX_AR).into() | ||
| 96 | } | ||
| 97 | |||
| 73 | /// Creates a new `executor` instance and declares an architecture agnostic application entry point spawning | 98 | /// Creates a new `executor` instance and declares an architecture agnostic application entry point spawning |
| 74 | /// the corresponding function body as an async task. | 99 | /// the corresponding function body as an async task. |
| 75 | /// | 100 | /// |
diff --git a/embassy-executor-macros/src/macros/main.rs b/embassy-executor-macros/src/macros/main.rs index 95722b19b..a0e7b3401 100644 --- a/embassy-executor-macros/src/macros/main.rs +++ b/embassy-executor-macros/src/macros/main.rs | |||
| @@ -37,6 +37,12 @@ pub static ARCH_CORTEX_M: Arch = Arch { | |||
| 37 | executor_required: false, | 37 | executor_required: false, |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | pub static ARCH_CORTEX_AR: Arch = Arch { | ||
| 41 | default_entry: None, | ||
| 42 | flavor: Flavor::Standard, | ||
| 43 | executor_required: false, | ||
| 44 | }; | ||
| 45 | |||
| 40 | pub static ARCH_SPIN: Arch = Arch { | 46 | pub static ARCH_SPIN: Arch = Arch { |
| 41 | default_entry: None, | 47 | default_entry: None, |
| 42 | flavor: Flavor::Standard, | 48 | flavor: Flavor::Standard, |
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md index 5d2468c58..608c67724 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 | - Added support for Cortex-A and Cortex-R | ||
| 11 | |||
| 8 | ## 0.7.0 - 2025-01-02 | 12 | ## 0.7.0 - 2025-01-02 |
| 9 | 13 | ||
| 10 | - Performance optimizations. | 14 | - Performance optimizations. |
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 9f9eaa600..f014ccf30 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -45,6 +45,9 @@ portable-atomic = { version = "1.5", optional = true } | |||
| 45 | # arch-cortex-m dependencies | 45 | # arch-cortex-m dependencies |
| 46 | cortex-m = { version = "0.7.6", optional = true } | 46 | cortex-m = { version = "0.7.6", optional = true } |
| 47 | 47 | ||
| 48 | # arch-cortex-ar dependencies | ||
| 49 | cortex-ar = { version = "0.2", optional = true } | ||
| 50 | |||
| 48 | # arch-wasm dependencies | 51 | # arch-wasm dependencies |
| 49 | wasm-bindgen = { version = "0.2.82", optional = true } | 52 | wasm-bindgen = { version = "0.2.82", optional = true } |
| 50 | js-sys = { version = "0.3", optional = true } | 53 | js-sys = { version = "0.3", optional = true } |
| @@ -73,6 +76,8 @@ _arch = [] # some arch was picked | |||
| 73 | arch-std = ["_arch"] | 76 | arch-std = ["_arch"] |
| 74 | ## Cortex-M | 77 | ## Cortex-M |
| 75 | arch-cortex-m = ["_arch", "dep:cortex-m"] | 78 | arch-cortex-m = ["_arch", "dep:cortex-m"] |
| 79 | ## Cortex-A/R | ||
| 80 | arch-cortex-ar = ["_arch", "dep:cortex-ar"] | ||
| 76 | ## RISC-V 32 | 81 | ## RISC-V 32 |
| 77 | arch-riscv32 = ["_arch"] | 82 | arch-riscv32 = ["_arch"] |
| 78 | ## WASM | 83 | ## WASM |
diff --git a/embassy-executor/src/arch/cortex_ar.rs b/embassy-executor/src/arch/cortex_ar.rs new file mode 100644 index 000000000..f9e2f3f7c --- /dev/null +++ b/embassy-executor/src/arch/cortex_ar.rs | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | #[cfg(feature = "executor-interrupt")] | ||
| 2 | compile_error!("`executor-interrupt` is not supported with `arch-cortex-ar`."); | ||
| 3 | |||
| 4 | #[export_name = "__pender"] | ||
| 5 | #[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] | ||
| 6 | fn __pender(context: *mut ()) { | ||
| 7 | // `context` is always `usize::MAX` created by `Executor::run`. | ||
| 8 | let context = context as usize; | ||
| 9 | |||
| 10 | #[cfg(feature = "executor-thread")] | ||
| 11 | // Try to make Rust optimize the branching away if we only use thread mode. | ||
| 12 | if !cfg!(feature = "executor-interrupt") || context == THREAD_PENDER { | ||
| 13 | cortex_ar::asm::sev(); | ||
| 14 | return; | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | #[cfg(feature = "executor-thread")] | ||
| 19 | pub use thread::*; | ||
| 20 | #[cfg(feature = "executor-thread")] | ||
| 21 | mod thread { | ||
| 22 | pub(super) const THREAD_PENDER: usize = usize::MAX; | ||
| 23 | |||
| 24 | use core::marker::PhantomData; | ||
| 25 | |||
| 26 | use cortex_ar::asm::wfe; | ||
| 27 | pub use embassy_executor_macros::main_cortex_ar as main; | ||
| 28 | |||
| 29 | use crate::{raw, Spawner}; | ||
| 30 | |||
| 31 | /// Thread mode executor, using WFE/SEV. | ||
| 32 | /// | ||
| 33 | /// This is the simplest and most common kind of executor. It runs on | ||
| 34 | /// thread mode (at the lowest priority level), and uses the `WFE` ARM instruction | ||
| 35 | /// to sleep when it has no more work to do. When a task is woken, a `SEV` instruction | ||
| 36 | /// is executed, to make the `WFE` exit from sleep and poll the task. | ||
| 37 | /// | ||
| 38 | /// This executor allows for ultra low power consumption for chips where `WFE` | ||
| 39 | /// triggers low-power sleep without extra steps. If your chip requires extra steps, | ||
| 40 | /// you may use [`raw::Executor`] directly to program custom behavior. | ||
| 41 | pub struct Executor { | ||
| 42 | inner: raw::Executor, | ||
| 43 | not_send: PhantomData<*mut ()>, | ||
| 44 | } | ||
| 45 | |||
| 46 | impl Executor { | ||
| 47 | /// Create a new Executor. | ||
| 48 | pub fn new() -> Self { | ||
| 49 | Self { | ||
| 50 | inner: raw::Executor::new(THREAD_PENDER as *mut ()), | ||
| 51 | not_send: PhantomData, | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | /// Run the executor. | ||
| 56 | /// | ||
| 57 | /// The `init` closure is called with a [`Spawner`] that spawns tasks on | ||
| 58 | /// this executor. Use it to spawn the initial task(s). After `init` returns, | ||
| 59 | /// the executor starts running the tasks. | ||
| 60 | /// | ||
| 61 | /// To spawn more tasks later, you may keep copies of the [`Spawner`] (it is `Copy`), | ||
| 62 | /// for example by passing it as an argument to the initial tasks. | ||
| 63 | /// | ||
| 64 | /// This function requires `&'static mut self`. This means you have to store the | ||
| 65 | /// Executor instance in a place where it'll live forever and grants you mutable | ||
| 66 | /// access. There's a few ways to do this: | ||
| 67 | /// | ||
| 68 | /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe) | ||
| 69 | /// - a `static mut` (unsafe) | ||
| 70 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | ||
| 71 | /// | ||
| 72 | /// This function never returns. | ||
| 73 | pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { | ||
| 74 | init(self.inner.spawner()); | ||
| 75 | |||
| 76 | loop { | ||
| 77 | unsafe { | ||
| 78 | self.inner.poll(); | ||
| 79 | } | ||
| 80 | wfe(); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index d6fd3d651..dfe420bab 100644 --- a/embassy-executor/src/lib.rs +++ b/embassy-executor/src/lib.rs | |||
| @@ -26,6 +26,7 @@ macro_rules! check_at_most_one { | |||
| 26 | check_at_most_one!( | 26 | check_at_most_one!( |
| 27 | "arch-avr", | 27 | "arch-avr", |
| 28 | "arch-cortex-m", | 28 | "arch-cortex-m", |
| 29 | "arch-cortex-ar", | ||
| 29 | "arch-riscv32", | 30 | "arch-riscv32", |
| 30 | "arch-std", | 31 | "arch-std", |
| 31 | "arch-wasm", | 32 | "arch-wasm", |
| @@ -35,6 +36,7 @@ check_at_most_one!( | |||
| 35 | #[cfg(feature = "_arch")] | 36 | #[cfg(feature = "_arch")] |
| 36 | #[cfg_attr(feature = "arch-avr", path = "arch/avr.rs")] | 37 | #[cfg_attr(feature = "arch-avr", path = "arch/avr.rs")] |
| 37 | #[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")] | 38 | #[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")] |
| 39 | #[cfg_attr(feature = "arch-cortex-ar", path = "arch/cortex_ar.rs")] | ||
| 38 | #[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")] | 40 | #[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")] |
| 39 | #[cfg_attr(feature = "arch-std", path = "arch/std.rs")] | 41 | #[cfg_attr(feature = "arch-std", path = "arch/std.rs")] |
| 40 | #[cfg_attr(feature = "arch-wasm", path = "arch/wasm.rs")] | 42 | #[cfg_attr(feature = "arch-wasm", path = "arch/wasm.rs")] |
diff --git a/rust-toolchain-nightly.toml b/rust-toolchain-nightly.toml index d803b29a0..e75ea40cc 100644 --- a/rust-toolchain-nightly.toml +++ b/rust-toolchain-nightly.toml | |||
| @@ -9,4 +9,5 @@ targets = [ | |||
| 9 | "thumbv8m.main-none-eabihf", | 9 | "thumbv8m.main-none-eabihf", |
| 10 | "riscv32imac-unknown-none-elf", | 10 | "riscv32imac-unknown-none-elf", |
| 11 | "wasm32-unknown-unknown", | 11 | "wasm32-unknown-unknown", |
| 12 | "armv7a-none-eabi", | ||
| 12 | ] | 13 | ] |
diff --git a/rust-toolchain.toml b/rust-toolchain.toml index ca5816121..870904c3a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml | |||
| @@ -9,4 +9,7 @@ targets = [ | |||
| 9 | "thumbv8m.main-none-eabihf", | 9 | "thumbv8m.main-none-eabihf", |
| 10 | "riscv32imac-unknown-none-elf", | 10 | "riscv32imac-unknown-none-elf", |
| 11 | "wasm32-unknown-unknown", | 11 | "wasm32-unknown-unknown", |
| 12 | "armv7a-none-eabi", | ||
| 13 | "armv7r-none-eabi", | ||
| 14 | "armv7r-none-eabihf", | ||
| 12 | ] | 15 | ] |
