diff --git a/ci.sh b/ci.sh index a5ddda3a1..a804647e1 100755 --- a/ci.sh +++ b/ci.sh @@ -208,8 +208,8 @@ cargo batch \ $BUILD_EXTRA # walkaround: "-Z" option not working on cargo batch -cargo build --release --manifest-path embassy-executor/Cargo.toml --target avr-unknown-gnu-atmega328 -Z build-std=core,alloc --features nightly,arch-avr -cargo build --release --manifest-path embassy-executor/Cargo.toml --target avr-unknown-gnu-atmega328 -Z build-std=core,alloc --features nightly,arch-avr,integrated-timers +cargo build --release --manifest-path embassy-executor/Cargo.toml --target avr-unknown-gnu-atmega328 -Z build-std=core,alloc --features nightly,arch-avr,avr-device/atmega328p +cargo build --release --manifest-path embassy-executor/Cargo.toml --target avr-unknown-gnu-atmega328 -Z build-std=core,alloc --features nightly,arch-avr,integrated-timers,avr-device/atmega328p rm out/tests/stm32wb55rg/wpan_mac diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index ade37913b..c937194ce 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml @@ -36,10 +36,11 @@ embassy-executor-macros = { version = "0.4.0", path = "../embassy-executor-macro embassy-time = { version = "0.2", path = "../embassy-time", optional = true} critical-section = "1.1" -# needed for riscv +# needed for riscv and avr # remove when https://github.com/rust-lang/rust/pull/114499 is merged portable-atomic = { version = "1.5", optional = true } + # arch-cortex-m dependencies cortex-m = { version = "0.7.6", optional = true } @@ -47,6 +48,9 @@ cortex-m = { version = "0.7.6", optional = true } wasm-bindgen = { version = "0.2.82", optional = true } js-sys = { version = "0.3", optional = true } +# arch-avr dependencies +avr-device = { version = "0.5.3", optional = true } + [dev-dependencies] critical-section = { version = "1.1", features = ["std"] } @@ -55,7 +59,7 @@ critical-section = { version = "1.1", features = ["std"] } # Architecture _arch = [] # some arch was picked -arch-avr = ["_arch", "dep:portable-atomic"] +arch-avr = ["_arch", "dep:portable-atomic", "dep:avr-device"] arch-std = ["_arch", "critical-section/std"] arch-cortex-m = ["_arch", "dep:cortex-m"] arch-riscv32 = ["_arch", "dep:portable-atomic"] diff --git a/embassy-executor/src/arch/avr.rs b/embassy-executor/src/arch/avr.rs index 2c715f297..fa6afe762 100644 --- a/embassy-executor/src/arch/avr.rs +++ b/embassy-executor/src/arch/avr.rs @@ -8,11 +8,16 @@ mod thread { use core::marker::PhantomData; pub use embassy_executor_macros::main_avr as main; + use portable_atomic::{AtomicBool, Ordering}; use crate::{raw, Spawner}; + static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); + #[export_name = "__pender"] - fn __pender(_context: *mut ()) {} + fn __pender(_context: *mut ()) { + SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); + } /// avr Executor pub struct Executor { @@ -52,7 +57,11 @@ mod thread { loop { unsafe { - self.inner.poll(); + if SIGNAL_WORK_THREAD_MODE.swap(false, Ordering::SeqCst) { + self.inner.poll(); + } else { + avr_device::asm::sleep(); + } } } }