hazard3-executor
Published replacement:
hazard3-executorreplaces the formerly publishedembassy-executor-riscv. See the project repository for the publication status of the Hazard3 packages. Upstream license and attribution notices are retained.
Fork of Embassy for RISC-V.
hazard3-executoris an independent fork ofembassy-executortaken from the Embassymainbranch, maintained by Jorge Andre Castro at https://github.com/jorgeandrecastro/Hazard3. It was originally republished under another name becausehazard3-rpneeds the unreleased changes ofmain, and crates.io does not accept git dependencies. Addhazard3-executordirectly in Cargo.toml and import it ashazard3_executor. Use thehazard3-*versions of the forked crates together (hazard3-time,hazard3-executor,hazard3-sync, ...) to avoid duplicate/incompatible copies in your build.
An async/await executor designed for embedded usage.
- No
alloc, no heap needed. - Tasks are statically allocated. Each task gets its own
static, with the exact size to hold the task (or multiple instances of it, if usingpool_size) calculated automatically at compile time. If tasks don't fit in RAM, this is detected at compile time by the linker. Runtime panics due to running out of memory are not possible. - No "fixed capacity" data structures, executor works with 1 or 1000 tasks without needing config/tuning.
- Integrated timer queue: sleeping is easy, just do
Timer::after_secs(1).await;. - No busy-loop polling: CPU sleeps when there's no work to do, using interrupts or
WFE/SEV. - Efficient polling: a wake will only poll the woken task, not all of them.
- Fair: a task can't monopolize CPU time even if it's constantly being woken. All other tasks get a chance to run before a given task gets polled for the second time.
- Creating multiple executor instances is supported, to run tasks with multiple priority levels. This allows higher-priority tasks to preempt lower-priority tasks.
Migration to 0.3.0
The Rust library is now hazard3_executor instead of embassy_executor. Update imports and macro paths; this is a source-breaking change. Add the package directly without a package alias:
[]
= "0.3"
Use compatible versions of the other Hazard3 crates together; older releases may use different library names.
The embassy-time-driver feature is now named hazard3-time-driver.
Platforms
The executor requires a "platform" to be defined to work. A platform defines the following things:
- The main loop, which typically consists of an infinite loop of polling the executor then sleeping the current thread/core in a platform-specific way.
- A "pender" callback, which must cause the executor's thread/core to exit sleep so the executor gets polled again. This is called when a task running in the executor is woken.
The hazard3-executor crate ships with support for some commonly used platforms, see the crate's feature documentation.
Chip-specific executor platform implementations are maintained in their respective HALs:
embassy-rp: multicore support. Enabled with theexecutor-interruptorexecutor-threadfeatures.embassy-stm32: automatic low-power sleep support. Enabled with theexecutor-interruptorexecutor-threadfeatures.embassy-mcxa: automatic low-power sleep support. Enabled with theexecutor-platformfeature.esp-rtos: ESP32 RTOS support, multicore support. Enabled with theembassyfeature.
To use the executor, you must provide exactly one platform implementation, either from this crate, a HAL crate, or a custom one.
Implementing a custom platform
To implement your own custom platform, e.g. on top of an RTOS, do the following:
- define the
__pendercallback.
- Wrap the
raw::Executorinto your ownExecutorstruct that defines the main loop.
Acknowledgements
This crate is a derivative work of the Embassy project (embassy-rs/embassy),
Copyright (c) Embassy project contributors, used under the MIT OR Apache-2.0 licenses. The original copyright and license notices are
kept (see LICENSE-MIT and LICENSE-APACHE). Embassy and its authors are not affiliated with, and do not endorse, this fork.
Thank you to the Embassy team and contributors for their work.