Skip to content

Commit

Permalink
Update to embassy-executor 0.3 (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored Aug 29, 2023
1 parent 9a89487 commit 92a2cc7
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 57 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ jobs:
# FIXME: `time-systick` feature disabled for now, see 'esp32s2-hal/Cargo.toml'.
# - name: check esp32s2-hal (async, systick)
# run: cd esp32s2-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick,executor
- name: check esp32-hal (embassy, timg0)
- name: check esp32s2-hal (embassy, timg0)
run: |
cd esp32s2-hal/
cargo check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread
cargo check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-interrupt
- name: check esp32-hal (embassy, timg0, async)
- name: check esp32s2-hal (embassy, timg0, async)
run: |
cd esp32s2-hal/
cargo check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread
Expand Down Expand Up @@ -360,28 +360,28 @@ jobs:
# confident that they link.
- name: check esp32s3-hal (common features)
run: cd esp32s3-hal/ && cargo check --examples --features=eh1,ufmt
- name: check esp32-hal (embassy, timg0)
- name: check esp32s3-hal (embassy, timg0)
run: |
cd esp32s3-hal/
cargo check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread
cargo check --example=embassy_multicore --features=embassy,embassy-time-timg0,embassy-executor-thread
cargo check --example=embassy_multicore_interrupt --features=embassy,embassy-time-timg0,embassy-executor-interrupt
cargo check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-interrupt
- name: check esp32-hal (embassy, systick)
- name: check esp32s3-hal (embassy, systick)
run: |
cd esp32s3-hal/
cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread
cargo check --example=embassy_multicore --features=embassy,embassy-time-systick,embassy-executor-thread
cargo check --example=embassy_multicore_interrupt --features=embassy,embassy-time-systick,embassy-executor-interrupt
cargo check --example=embassy_multiprio --features=embassy,embassy-time-systick,embassy-executor-interrupt
- name: check esp32-hal (embassy, timg0, async)
- name: check esp32s3-hal (embassy, timg0, async)
run: |
cd esp32s3-hal/
cargo check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread
cargo check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread
- name: check esp32-hal (embassy, systick, async)
- name: check esp32s3-hal (embassy, systick, async)
run: |
cd esp32s3-hal/
cargo check --example=embassy_wait --features=embassy,embassy-time-systick,async,embassy-executor-thread
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add multicore-aware embassy executor for Xtensa MCUs (#723).
- Add interrupt-executor for Xtensa MCUs (#723).
- Add PARL_IO RX driver for ESP32-C6 / ESP32-H2 (#760)
- Add multicore-aware embassy executor for Xtensa MCUs (#723, #756).
- Add interrupt-executor for Xtensa MCUs (#723, #756).

### Changed

Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ usb-device = { version = "0.2.9", optional = true }
# async
embedded-hal-async = { version = "=1.0.0-rc.1", optional = true }
embedded-io-async = { version = "0.5.0", optional = true }
embassy-executor = { version = "0.2.1", features = ["pender-callback", "integrated-timers"], optional = true } # pender is temporary
embassy-executor = { version = "0.3.0", features = ["integrated-timers"], optional = true }
embassy-sync = { version = "0.2.0", optional = true }
embassy-time = { version = "0.1.3", features = ["nightly"], optional = true }
embassy-futures = { version = "0.1.0", optional = true }
Expand Down
34 changes: 16 additions & 18 deletions esp-hal-common/src/embassy/executor/xtensa/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ use core::{
cell::UnsafeCell,
marker::PhantomData,
mem::MaybeUninit,
ptr,
sync::atomic::{AtomicUsize, Ordering},
};

use embassy_executor::{
raw::{self, Pender},
SendSpawner,
};
use embassy_executor::{raw, SendSpawner};
#[cfg(dport)]
use peripherals::DPORT as SystemPeripheral;
#[cfg(system)]
Expand All @@ -22,34 +18,39 @@ static FROM_CPU_IRQ_USED: AtomicUsize = AtomicUsize::new(0);

pub trait SwPendableInterrupt {
fn enable(priority: interrupt::Priority);
fn number() -> usize;
fn pend();
fn clear();
}

macro_rules! from_cpu {
($cpu:literal) => {
($irq:literal) => {
paste::paste! {
pub struct [<FromCpu $cpu>];
pub struct [<FromCpu $irq>];

/// We don't allow using the same interrupt for multiple executors.
impl [<FromCpu $cpu>] {
impl [<FromCpu $irq>] {
fn set_bit(value: bool) {
let system = unsafe { &*SystemPeripheral::PTR };
system
.[<cpu_intr_from_cpu_ $cpu>]
.write(|w| w.[<cpu_intr_from_cpu_ $cpu>]().bit(value));
.[<cpu_intr_from_cpu_ $irq>]
.write(|w| w.[<cpu_intr_from_cpu_ $irq>]().bit(value));
}
}

impl SwPendableInterrupt for [<FromCpu $cpu>] {
impl SwPendableInterrupt for [<FromCpu $irq>] {
fn enable(priority: interrupt::Priority) {
let mask = 1 << $cpu;
let mask = 1 << $irq;
if FROM_CPU_IRQ_USED.fetch_or(mask, Ordering::SeqCst) & mask != 0 {
panic!(concat!("FROM_CPU_", $cpu, " is already used by a different executor."));
panic!(concat!("FROM_CPU_", $irq, " is already used by a different executor."));
}

interrupt::enable(peripherals::Interrupt::[<FROM_CPU_INTR $cpu>], priority).unwrap();
interrupt::enable(peripherals::Interrupt::[<FROM_CPU_INTR $irq>], priority).unwrap();
}

fn number() -> usize {
$irq
}

fn pend() {
Expand Down Expand Up @@ -165,10 +166,7 @@ where
unsafe {
(*self.executor.get())
.as_mut_ptr()
.write(raw::Executor::new(Pender::new_from_callback(
|_| SWI::pend(),
ptr::null_mut(),
)))
.write(raw::Executor::new(SWI::number() as *mut ()))
}

SWI::enable(priority);
Expand Down
20 changes: 20 additions & 0 deletions esp-hal-common/src/embassy/executor/xtensa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,23 @@ pub mod thread;

#[cfg(feature = "embassy-executor-thread")]
pub use thread::*;

#[export_name = "__pender"]
fn __pender(context: *mut ()) {
let context = (context as usize).to_le_bytes();

cfg_if::cfg_if! {
if #[cfg(feature = "embassy-executor-interrupt")] {
match context[0] {
#[cfg(feature = "embassy-executor-thread")]
0 => pend_thread_mode(context[1] as usize),
1 => FromCpu1::pend(),
2 => FromCpu2::pend(),
3 => FromCpu3::pend(),
_ => {}
}
} else {
pend_thread_mode(context[1] as usize);
}
}
}
53 changes: 28 additions & 25 deletions esp-hal-common/src/embassy/executor/xtensa/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use core::{
sync::atomic::{AtomicBool, Ordering},
};

use embassy_executor::{
raw::{self, Pender},
Spawner,
};
use embassy_executor::{raw, Spawner};
#[cfg(all(dport, multi_core))]
use peripherals::DPORT as SystemPeripheral;
#[cfg(all(system, multi_core))]
Expand Down Expand Up @@ -39,6 +36,32 @@ fn FROM_CPU_INTR0() {
}
}

pub(super) fn pend_thread_mode(core: usize) {
use core::sync::atomic::Ordering;

#[cfg(dport)]
use crate::peripherals::DPORT as SystemPeripheral;
#[cfg(system)]
use crate::peripherals::SYSTEM as SystemPeripheral;

// Signal that there is work to be done.
SIGNAL_WORK_THREAD_MODE[core].store(true, Ordering::SeqCst);

// If we are pending a task on the current core, we're done. Otherwise, we
// need to make sure the other core wakes up.
#[cfg(multi_core)]
if core != crate::get_core() as usize {
// We need to clear the interrupt from software. We don't actually
// need it to trigger and run the interrupt handler, we just need to
// kick waiti to return.

let system = unsafe { &*SystemPeripheral::PTR };
system
.cpu_intr_from_cpu_0
.write(|w| w.cpu_intr_from_cpu_0().bit(true));
}
}

/// Multi-core Xtensa Executor
pub struct Executor {
inner: raw::Executor,
Expand All @@ -56,27 +79,7 @@ impl Executor {
.unwrap();

Self {
inner: raw::Executor::new(Pender::new_from_callback(
|ctx| {
let core = ctx as usize;

// Signal that there is work to be done.
SIGNAL_WORK_THREAD_MODE[core].store(true, Ordering::SeqCst);

// If we are pending a task on the current core, we're done. Otherwise, we
// need to make sure the other core wakes up.
#[cfg(multi_core)]
if core != get_core() as usize {
// We need to clear the interrupt from software.

let system = unsafe { &*SystemPeripheral::PTR };
system
.cpu_intr_from_cpu_0
.write(|w| w.cpu_intr_from_cpu_0().bit(true));
}
},
get_core() as usize as *mut (),
)),
inner: raw::Executor::new(usize::from_le_bytes([0, get_core() as u8, 0, 0]) as *mut ()),
not_send: PhantomData,
}
}
Expand Down
2 changes: 1 addition & 1 deletion esp32-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ embassy-time = { version = "0.1.3", features = ["nightly"], optional = true }
aes = "0.8.3"
critical-section = "1.1.2"
crypto-bigint = { version = "0.5.2", default-features = false }
embassy-executor = { version = "0.2.1", features = ["nightly"] }
embassy-executor = { version = "0.3.0", features = ["nightly"] }
embassy-sync = "0.2.0"
embedded-graphics = "0.8.1"
embedded-hal-1 = { version = "=1.0.0-rc.1", package = "embedded-hal" }
Expand Down
2 changes: 1 addition & 1 deletion esp32c2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ embassy-time = { version = "0.1.3", features = ["nightly"], optional = true }

[dev-dependencies]
critical-section = "1.1.2"
embassy-executor = { version = "0.2.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embassy-executor = { version = "0.3.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embedded-graphics = "0.8.1"
embedded-hal-1 = { version = "=1.0.0-rc.1", package = "embedded-hal" }
embedded-hal-async = "=1.0.0-rc.1"
Expand Down
2 changes: 1 addition & 1 deletion esp32c3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ embassy-time = { version = "0.1.3", features = ["nightly"], optional = true }
aes = "0.8.3"
critical-section = "1.1.2"
crypto-bigint = { version = "0.5.2", default-features = false }
embassy-executor = { version = "0.2.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embassy-executor = { version = "0.3.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embedded-can = "0.4.1"
embedded-graphics = "0.8.1"
embedded-hal = { version = "0.2.7", features = ["unproven"] }
Expand Down
2 changes: 1 addition & 1 deletion esp32c6-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ embassy-time = { version = "0.1.3", features = ["nightly"], optional = true }
aes = "0.8.3"
critical-section = "1.1.2"
crypto-bigint = { version = "0.5.2", default-features = false}
embassy-executor = { version = "0.2.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embassy-executor = { version = "0.3.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embedded-graphics = "0.8.1"
embedded-hal-1 = { version = "=1.0.0-rc.1", package = "embedded-hal" }
embedded-hal-async = "=1.0.0-rc.1"
Expand Down
2 changes: 1 addition & 1 deletion esp32h2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ embassy-time = { version = "0.1.3", features = ["nightly"], optional = true }
aes = "0.8.3"
critical-section = "1.1.2"
crypto-bigint = { version = "0.5.2", default-features = false }
embassy-executor = { version = "0.2.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embassy-executor = { version = "0.3.0", features = ["nightly", "integrated-timers", "arch-riscv32", "executor-thread"] }
embedded-graphics = "0.8.1"
embedded-hal-1 = { version = "=1.0.0-rc.1", package = "embedded-hal" }
embedded-hal-async = "=1.0.0-rc.1"
Expand Down
2 changes: 1 addition & 1 deletion esp32s2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ xtensa-atomic-emulation-trap = "0.4.0"
aes = "0.8.3"
critical-section = "1.1.2"
crypto-bigint = { version = "0.5.2", default-features = false }
embassy-executor = { version = "0.2.1", features = ["nightly"] }
embassy-executor = { version = "0.3.0", features = ["nightly"] }
embassy-sync = "0.2.0"
embedded-graphics = "0.8.1"
embedded-hal-1 = { version = "=1.0.0-rc.1", package = "embedded-hal" }
Expand Down
2 changes: 1 addition & 1 deletion esp32s3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ r0 = { version = "1.0.0", optional = true }
aes = "0.8.3"
critical-section = "1.1.2"
crypto-bigint = { version = "0.5.2", default-features = false }
embassy-executor = { version = "0.2.1", features = ["nightly"] }
embassy-executor = { version = "0.3.0", features = ["nightly"] }
embassy-sync = "0.2.0"
embedded-graphics = "0.8.1"
embedded-hal = { version = "0.2.7", features = ["unproven"] }
Expand Down

0 comments on commit 92a2cc7

Please sign in to comment.