Skip to content

Commit

Permalink
Strip down everything unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Oct 10, 2023
1 parent cb2d6b4 commit 835dde5
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 625 deletions.
23 changes: 7 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
name = "edge-executor"
version = "0.3.1"
authors = ["Ivan Markov <ivan.markov@gmail.com>"]
edition = "2018"
resolver = "2"
edition = "2021"
categories = ["embedded", "hardware-support"]
keywords = ["embedded", "async", "executor"]
description = "Async executor suitable for embedded environments."
Expand All @@ -14,27 +13,19 @@ readme = "README.md"
[patch.crates-io]
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
async-task = { git = "https://github.com/ivmarkov/async-task" }

[features]
default = ["std"]
std = []
std = ["futures-lite/std"]
unbounded = []
portable-atomic = ["dep:portable-atomic", "portable-atomic-util", "atomic-waker/portable-atomic", "async-task/portable-atomic"]

[dependencies]
heapless = { version = "0.7", default-featgures = false, features = ["cas"], optional = true }
portable-atomic = { version = "1.4", features = ["critical-section"], optional = true }
portable-atomic-util = { version = "0.1", default-features = false, features = ["alloc"], optional = true }
crossbeam-queue = { version = "0.3", default-features = false, features = ["alloc"] }
async-task = { version = "4", default-features = false }
atomic-waker = { version = "1", default-features = false }
futures-lite = { version = "1", default-features = false }
log = { version = "0.4", default-features = false }

# ESP-IDF dependencies
[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-hal = { version = "0.41", default-features = false }

# WASM dependencies
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2.82", default-features = false }
js-sys = { version = "0.3", default-features = false }

[dev-dependencies]
simple_logger = "2.2"
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,27 @@
![crates.io](https://img.shields.io/crates/v/edge-executor.svg)
[![Documentation](https://docs.rs/edge-executor/badge.svg)](https://docs.rs/edge-executor)

This crate ships a minimal async executor suitable for microcontrollers.
This crate ships a minimal async executor suitable for microcontrollers and embedded systems in general.

The implementation is a thin wrapper around [smol](https://github.com/smol-rs/smol)'s [async-task](https://github.com/smol-rs/async-task) crate.
A `no_std` drop-in replacement for [smol](https://github.com/smol-rs/smol)'s [async-executor](https://github.com/smol-rs/async-executor), with the implementation being a thin wrapper around [smol](https://github.com/smol-rs/smol)'s [async-task](https://github.com/smol-rs/async-task) as well.

**Highlights**

- `no_std` (but does need `alloc`; for a `no_std` *and* "no_alloc" executor, look at [embassy-executor](https://github.com/embassy-rs/embassy/tree/main/embassy-executor), which statically pre-allocates all tasks);
(note also that the executor uses allocations in a limited way: when a new task is being spawn, as well as the executor itself);
- `no_std` (but does need `alloc`); for a `no_std` *and* "no_alloc" executor, look at [embassy-executor](https://github.com/embassy-rs/embassy/tree/main/embassy-executor), which statically pre-allocates all tasks;
(note also that the executor uses allocations in a limited way: when a new task is being spawn, as well as during the construction of the executor itself);

- Follow closely the API of [smol](https://github.com/smol-rs/smol)'s [async-executor](https://github.com/smol-rs/async-executor) (`async_executor::LocalExecutor` specifically), so that it can serve as a (mostly) drop-in replacement;
- Works on targets which have no `core::sync::atomic` support, thanks to [portable-atomic](https://github.com/taiki-e/portable-atomic);

- Does not assume an RTOS and can run completely bare-metal (or on top of an RTOS);
- Does not assume an RTOS and can run completely bare-metal too;

- Local execution only. No plans for implementing work-stealing execution, as threads are either a scarce resource on microcontrollers' RTOS,
or do not exist at all (Rust bare-metal);
- Lockless, atomic-based, bounded task queue by default, which works well for waking the executor directly from an ISR on e.g. FreeRTOS or ESP-IDF (unbounded also an option with feature `unbounded`, yet that might mean potential allocations in an ISR context, which should be avoided).

- Pluggable `Wakeup` mechanism which makes it customizable for different microcontrollers;
**Useful features inspired from [async-executor](https://github.com/smol-rs/async-executor)**:

- ISR-friendly, i.e. tasks can be woken up (and thus re-scheduled) from within an ISR
(feature `wake-from-isr` should be enabled);
- Futures spawned on `edge_executor::LocalExecutor` need to live only as long as the executor itself, which enables stack borrows;

- `StdWakeup` implementation based on a mutex + condvar pair, usable on top of the Rust Standard Library;
- Completely portable and async. `Executor::run` simply returns a `Future`. Polling this future runs the executor, i.e. `block_on(executor.run(core::task:forever::<()>()))`;

- `EspWakeup` implementation for ESP-IDF based on FreeRTOS task notifications, compatible with the `wake-from-isr` feature;
**TODO**:

- `WasmWakeup` implementation for the WASM event loop, compatible with WASM;

- `CEventLoopWakeup` implementation for native event loops like those of GLIB, the Matter C++ SDK and others.
Upstream the `portable-atomic` dependency into `async-task` (and possibly into `crossbeam-queue`) so that the crate can compile on targets that do not support `core::sync` atomics.
Loading

0 comments on commit 835dde5

Please sign in to comment.