aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2025-05-28 15:27:27 +0000
committerGitHub <[email protected]>2025-05-28 15:27:27 +0000
commit4766cc6f9756b54bb2e25be5ba5276538ea4917b (patch)
treea9b6980ee1c3301bef0dc7c8d287add2ed4a43a8 /embassy-executor
parentf35aa4005a63e8d478b2b95aaa2bfb316b72dece (diff)
parent5a07ea5d851768223e2e41342e69d14c1afb2b2b (diff)
Merge pull request #3957 from us-irs/add-cortex-ar-support
Add support for Cortex-A/R
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/CHANGELOG.md4
-rw-r--r--embassy-executor/Cargo.toml5
-rw-r--r--embassy-executor/src/arch/cortex_ar.rs84
-rw-r--r--embassy-executor/src/lib.rs2
4 files changed, 95 insertions, 0 deletions
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.
5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6and 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
46cortex-m = { version = "0.7.6", optional = true } 46cortex-m = { version = "0.7.6", optional = true }
47 47
48# arch-cortex-ar dependencies
49cortex-ar = { version = "0.2", optional = true }
50
48# arch-wasm dependencies 51# arch-wasm dependencies
49wasm-bindgen = { version = "0.2.82", optional = true } 52wasm-bindgen = { version = "0.2.82", optional = true }
50js-sys = { version = "0.3", optional = true } 53js-sys = { version = "0.3", optional = true }
@@ -73,6 +76,8 @@ _arch = [] # some arch was picked
73arch-std = ["_arch"] 76arch-std = ["_arch"]
74## Cortex-M 77## Cortex-M
75arch-cortex-m = ["_arch", "dep:cortex-m"] 78arch-cortex-m = ["_arch", "dep:cortex-m"]
79## Cortex-A/R
80arch-cortex-ar = ["_arch", "dep:cortex-ar"]
76## RISC-V 32 81## RISC-V 32
77arch-riscv32 = ["_arch"] 82arch-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")]
2compile_error!("`executor-interrupt` is not supported with `arch-cortex-ar`.");
3
4#[export_name = "__pender"]
5#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))]
6fn __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")]
19pub use thread::*;
20#[cfg(feature = "executor-thread")]
21mod 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 {
26check_at_most_one!( 26check_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")]