aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
authorKarun Koppula <[email protected]>2024-03-07 15:20:29 -0500
committerGitHub <[email protected]>2024-03-07 15:20:29 -0500
commit54751b7a5093b7960e42cee1bc9a850f9c4b7a8f (patch)
treedf08df503f2b441c5b62306d50532403fe4c19c9 /embassy-executor
parent3b1d87050e2a30b598e92979b6f202b67664a29c (diff)
parentb2d236ee390081ec6aeef1a27da06098f9febbf9 (diff)
Merge branch 'main' into karun/main_octospi_implementation
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/Cargo.toml14
-rw-r--r--embassy-executor/src/arch/avr.rs72
-rw-r--r--embassy-executor/src/arch/riscv32.rs2
-rw-r--r--embassy-executor/src/lib.rs3
-rw-r--r--embassy-executor/src/raw/mod.rs12
5 files changed, 95 insertions, 8 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index b6b156c9f..431165cee 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -40,8 +40,7 @@ critical-section = "1.1"
40 40
41document-features = "0.2.7" 41document-features = "0.2.7"
42 42
43# needed for riscv 43# needed for AVR
44# remove when https://github.com/rust-lang/rust/pull/114499 is merged
45portable-atomic = { version = "1.5", optional = true } 44portable-atomic = { version = "1.5", optional = true }
46 45
47# arch-cortex-m dependencies 46# arch-cortex-m dependencies
@@ -51,6 +50,9 @@ cortex-m = { version = "0.7.6", optional = true }
51wasm-bindgen = { version = "0.2.82", optional = true } 50wasm-bindgen = { version = "0.2.82", optional = true }
52js-sys = { version = "0.3", optional = true } 51js-sys = { version = "0.3", optional = true }
53 52
53# arch-avr dependencies
54avr-device = { version = "0.5.3", optional = true }
55
54[dev-dependencies] 56[dev-dependencies]
55critical-section = { version = "1.1", features = ["std"] } 57critical-section = { version = "1.1", features = ["std"] }
56 58
@@ -75,9 +77,11 @@ arch-std = ["_arch", "critical-section/std"]
75## Cortex-M 77## Cortex-M
76arch-cortex-m = ["_arch", "dep:cortex-m"] 78arch-cortex-m = ["_arch", "dep:cortex-m"]
77## RISC-V 32 79## RISC-V 32
78arch-riscv32 = ["_arch", "dep:portable-atomic"] 80arch-riscv32 = ["_arch"]
79## WASM 81## WASM
80arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"] 82arch-wasm = ["_arch", "dep:wasm-bindgen", "dep:js-sys"]
83## AVR
84arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"]
81 85
82#! ### Executor 86#! ### Executor
83 87
@@ -88,11 +92,11 @@ executor-interrupt = []
88 92
89#! ### Task Arena Size 93#! ### Task Arena Size
90#! Sets the [task arena](#task-arena) size. Necessary if you’re not using `nightly`. 94#! Sets the [task arena](#task-arena) size. Necessary if you’re not using `nightly`.
91#! 95#!
92#! <details> 96#! <details>
93#! <summary>Preconfigured Task Arena Sizes:</summary> 97#! <summary>Preconfigured Task Arena Sizes:</summary>
94#! <!-- rustdoc requires the following blank line for the feature list to render correctly! --> 98#! <!-- rustdoc requires the following blank line for the feature list to render correctly! -->
95#! 99#!
96 100
97# BEGIN AUTOGENERATED CONFIG FEATURES 101# BEGIN AUTOGENERATED CONFIG FEATURES
98# Generated by gen_config.py. DO NOT EDIT. 102# Generated by gen_config.py. DO NOT EDIT.
diff --git a/embassy-executor/src/arch/avr.rs b/embassy-executor/src/arch/avr.rs
new file mode 100644
index 000000000..70085d04d
--- /dev/null
+++ b/embassy-executor/src/arch/avr.rs
@@ -0,0 +1,72 @@
1#[cfg(feature = "executor-interrupt")]
2compile_error!("`executor-interrupt` is not supported with `arch-avr`.");
3
4#[cfg(feature = "executor-thread")]
5pub use thread::*;
6#[cfg(feature = "executor-thread")]
7mod thread {
8 use core::marker::PhantomData;
9
10 pub use embassy_executor_macros::main_avr as main;
11 use portable_atomic::{AtomicBool, Ordering};
12
13 use crate::{raw, Spawner};
14
15 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
16
17 #[export_name = "__pender"]
18 fn __pender(_context: *mut ()) {
19 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst);
20 }
21
22 /// avr Executor
23 pub struct Executor {
24 inner: raw::Executor,
25 not_send: PhantomData<*mut ()>,
26 }
27
28 impl Executor {
29 /// Create a new Executor.
30 pub fn new() -> Self {
31 Self {
32 inner: raw::Executor::new(core::ptr::null_mut()),
33 not_send: PhantomData,
34 }
35 }
36
37 /// Run the executor.
38 ///
39 /// The `init` closure is called with a [`Spawner`] that spawns tasks on
40 /// this executor. Use it to spawn the initial task(s). After `init` returns,
41 /// the executor starts running the tasks.
42 ///
43 /// To spawn more tasks later, you may keep copies of the [`Spawner`] (it is `Copy`),
44 /// for example by passing it as an argument to the initial tasks.
45 ///
46 /// This function requires `&'static mut self`. This means you have to store the
47 /// Executor instance in a place where it'll live forever and grants you mutable
48 /// access. There's a few ways to do this:
49 ///
50 /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe)
51 /// - a `static mut` (unsafe)
52 /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe)
53 ///
54 /// This function never returns.
55 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
56 init(self.inner.spawner());
57
58 loop {
59 unsafe {
60 avr_device::interrupt::disable();
61 if !SIGNAL_WORK_THREAD_MODE.swap(false, Ordering::SeqCst) {
62 avr_device::interrupt::enable();
63 avr_device::asm::sleep();
64 } else {
65 avr_device::interrupt::enable();
66 self.inner.poll();
67 }
68 }
69 }
70 }
71 }
72}
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index c56f502d3..01e63a9fd 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -6,9 +6,9 @@ pub use thread::*;
6#[cfg(feature = "executor-thread")] 6#[cfg(feature = "executor-thread")]
7mod thread { 7mod thread {
8 use core::marker::PhantomData; 8 use core::marker::PhantomData;
9 use core::sync::atomic::{AtomicBool, Ordering};
9 10
10 pub use embassy_executor_macros::main_riscv as main; 11 pub use embassy_executor_macros::main_riscv as main;
11 use portable_atomic::{AtomicBool, Ordering};
12 12
13 use crate::{raw, Spawner}; 13 use crate::{raw, Spawner};
14 14
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index eea118ade..6a2e493a2 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -23,9 +23,10 @@ macro_rules! check_at_most_one {
23 check_at_most_one!(@amo [$($f)*] [$($f)*] []); 23 check_at_most_one!(@amo [$($f)*] [$($f)*] []);
24 }; 24 };
25} 25}
26check_at_most_one!("arch-cortex-m", "arch-riscv32", "arch-std", "arch-wasm",); 26check_at_most_one!("arch-avr", "arch-cortex-m", "arch-riscv32", "arch-std", "arch-wasm",);
27 27
28#[cfg(feature = "_arch")] 28#[cfg(feature = "_arch")]
29#[cfg_attr(feature = "arch-avr", path = "arch/avr.rs")]
29#[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")] 30#[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")]
30#[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")] 31#[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")]
31#[cfg_attr(feature = "arch-std", path = "arch/std.rs")] 32#[cfg_attr(feature = "arch-std", path = "arch/std.rs")]
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 3f00be4a8..3d5e3ab9f 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -581,6 +581,15 @@ impl embassy_time_queue_driver::TimerQueue for TimerQueue {
581#[cfg(feature = "integrated-timers")] 581#[cfg(feature = "integrated-timers")]
582embassy_time_queue_driver::timer_queue_impl!(static TIMER_QUEUE: TimerQueue = TimerQueue); 582embassy_time_queue_driver::timer_queue_impl!(static TIMER_QUEUE: TimerQueue = TimerQueue);
583 583
584#[cfg(all(feature = "rtos-trace", feature = "integrated-timers"))]
585const fn gcd(a: u64, b: u64) -> u64 {
586 if b == 0 {
587 a
588 } else {
589 gcd(b, a % b)
590 }
591}
592
584#[cfg(feature = "rtos-trace")] 593#[cfg(feature = "rtos-trace")]
585impl rtos_trace::RtosTraceOSCallbacks for Executor { 594impl rtos_trace::RtosTraceOSCallbacks for Executor {
586 fn task_list() { 595 fn task_list() {
@@ -588,7 +597,8 @@ impl rtos_trace::RtosTraceOSCallbacks for Executor {
588 } 597 }
589 #[cfg(feature = "integrated-timers")] 598 #[cfg(feature = "integrated-timers")]
590 fn time() -> u64 { 599 fn time() -> u64 {
591 Instant::now().as_micros() 600 const GCD_1M: u64 = gcd(embassy_time_driver::TICK_HZ, 1_000_000);
601 embassy_time_driver::now() * (1_000_000 / GCD_1M) / (embassy_time_driver::TICK_HZ / GCD_1M)
592 } 602 }
593 #[cfg(not(feature = "integrated-timers"))] 603 #[cfg(not(feature = "integrated-timers"))]
594 fn time() -> u64 { 604 fn time() -> u64 {