Skip to content

Commit 12f13cb

Browse files
authored
Update embassy-time (#6)
* Update embassy-time * Update and test MSRV * Document embassy-time requirements
1 parent 4d08756 commit 12f13cb

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@ on:
99
- cron: '50 4 * * *'
1010
workflow_dispatch:
1111

12-
env:
13-
rust_toolchain: nightly
14-
1512
jobs:
1613
compile:
1714
name: Compile
1815
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
rust_toolchain:
20+
- nightly
21+
- 1.83 # MSRV
22+
1923
steps:
2024
- name: Setup | Checkout
2125
uses: actions/checkout@v2
2226
- name: Setup | Rust
2327
uses: actions-rs/toolchain@v1
2428
with:
25-
toolchain: ${{ env.rust_toolchain }}
29+
toolchain: ${{ matrix.rust_toolchain }}
2630
components: rustfmt, clippy
2731
- name: Setup | Std
28-
run: rustup component add rust-src --toolchain ${{ env.rust_toolchain }}-x86_64-unknown-linux-gnu
32+
run: rustup component add rust-src --toolchain ${{ matrix.rust_toolchain }}-x86_64-unknown-linux-gnu
2933
- name: Setup | Set default toolchain
30-
run: rustup default ${{ env.rust_toolchain }}
34+
run: rustup default ${{ matrix.rust_toolchain }}
3135
- name: Build | Fmt Check
3236
run: cargo fmt -- --check
3337
- name: Build | Clippy

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "async-io-mini"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Stjepan Glavina <[email protected]>", "Ivan Markov"]
55
edition = "2021"
6-
rust-version = "1.77"
6+
rust-version = "1.83"
77
description = "Async I/O fork for embedded systems"
88
license = "Apache-2.0 OR MIT"
99
repository = "https://github.com/ivmarkov/async-io-mini"
@@ -13,7 +13,7 @@ exclude = ["/.*"]
1313

1414
[features]
1515
default = ["futures-io", "futures-lite", "embassy-time"]
16-
embassy-time = ["embassy-time-driver", "embassy-time-queue-driver", "dep:embassy-time"]
16+
embassy-time = ["embassy-time-driver", "dep:embassy-time"]
1717

1818
[dependencies]
1919
libc = "0.2"
@@ -22,14 +22,14 @@ heapless = "0.8"
2222
log = { version = "0.4", default-features = false }
2323
futures-io = { version = "0.3", default-features = false, optional = true, features = ["std"] }
2424
futures-lite = { version = "2", default-features = false, optional = true }
25-
embassy-time-driver = { version = "0.1", optional = true }
26-
embassy-time-queue-driver = { version = "0.1", optional = true }
27-
embassy-time = { version = "0.3", optional = true }
25+
embassy-time-driver = { version = "0.2", optional = true }
26+
embassy-time = { version = "0.4", optional = true }
2827

2928
[dev-dependencies]
3029
futures-io = "0.3"
3130
futures-lite = "2"
32-
embassy-time = { version = "0.3", features = ["std", "generic-queue"] }
31+
embassy-time = { version = "0.4", features = ["std"] }
32+
embassy-time-queue-utils = { version = "0.1", features = ["generic-queue-64"] }
3333
async-channel = "2"
3434
env_logger = "0.10"
3535

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ This crate is a fork of the splendid [`async-io`](https://github.com/smol-rs/asy
1111

1212
## How to use?
1313

14-
`async-io-mini` is a drop-in, API-compatible replacement for the `Async` and `Timer` types from `async-io`.
14+
`async-io-mini` is an API-compatible replacement for the `Async` and `Timer` types from `async-io`.
1515

1616
So either:
1717
* Just replace all `use async_io` occurances in your crate with `use async_io_mini`
1818
* Or - in your `Cargo.toml` - replace:
1919
* `async-io = "..."`
2020
* with `async-io = { package = "async-io-mini", ... }`
2121

22+
Additionally, you need to provide an `embassy-time-driver` implementation. This is either done by the HAL of your MCU, or `embassy-time` provides you with a `std`-specific implementation. If you are not using `embassy-executor`, you will also need to select one of the `embassy-time/generic-queue-*` features.
23+
2224
## Justification
2325

2426
While `async-io` supports a ton of operating systems - _including ESP-IDF for the Espressif MCU chips_ - it does have a non-trivial memory consumption in the hidden thread named `async-io`. Since its hidden `Reactor` object is initialized lazily, it so happens that it is first allocated on-stack, and then it is moved into the static context. This requires the `async-io` thread (as well as _any_ thread from where you are polling sockets) to have at least 8K stack, which - by MCU standards! - is relatively large if you are memory-constrained.
@@ -39,7 +41,7 @@ Further, `async-io` has a non-trivial set of dependencies (again - for MCUs; for
3941

4042
## Enhancements
4143

42-
The `Timer` type of `async_io_mini` is based on the `embassy-time` crate, and as such should offer a higher resolution on embedded operating systems like the ESP-IDF than what can be normally achieved by implementing timers using the `timeout` parameter of the `select` syscall (as `async-io` does).
44+
The `Timer` type of `async_io_mini` is based on the `embassy-time` crate, and as such should offer a higher resolution on embedded operating systems like the ESP-IDF than what can be normally achieved by implementing timers using the `timeout` parameter of the `select` syscall (as `async-io` does).
4345

4446
The reason for this is that on the ESP-IDF, the `timeout` parameter of `select` provides a resolution of 10ms (one FreeRTOS sys-tick), while
4547
`embassy-time` is implemented using the [ESP-IDF Timer service](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/esp_timer.html), which provides resolutions up to 1 microsecond.

src/timer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Timer {
283283
self.period = Duration::MAX;
284284

285285
if let Some(waker) = self.waker.as_ref() {
286-
embassy_time_queue_driver::schedule_wake(ticks, waker);
286+
embassy_time_driver::schedule_wake(ticks, waker);
287287
}
288288
} else {
289289
self.set_never();
@@ -347,7 +347,7 @@ impl Timer {
347347
self.period = period;
348348

349349
if let Some(waker) = self.waker.as_ref() {
350-
embassy_time_queue_driver::schedule_wake(ticks, waker);
350+
embassy_time_driver::schedule_wake(ticks, waker);
351351
}
352352
} else {
353353
// Overflow to never going off.
@@ -375,7 +375,7 @@ impl Timer {
375375
.unwrap_or(true)
376376
{
377377
self.waker = Some(cx.waker().clone());
378-
embassy_time_queue_driver::schedule_wake(ticks, cx.waker());
378+
embassy_time_driver::schedule_wake(ticks, cx.waker());
379379
}
380380
} else {
381381
self.set_never();

0 commit comments

Comments
 (0)