mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 21:05:35 +01:00
Add SYSTIMER based ESP32-C3 monotonic (#972)
* add esp32c3 monotonic * fix tests
This commit is contained in:
parent
6e68a5e615
commit
805ea267a8
12 changed files with 395 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[target.riscv32imc-unknown-none-elf]
|
||||
# Real hardware
|
||||
#runner = "espflash flash --monitor"
|
||||
# runner = "espflash flash --monitor"
|
||||
|
||||
# QEMU emulator
|
||||
runner = "./runner.sh"
|
||||
|
|
@ -14,6 +14,3 @@ rustflags = [
|
|||
]
|
||||
|
||||
target = "riscv32imc-unknown-none-elf"
|
||||
|
||||
[unstable]
|
||||
build-std = ["core"]
|
||||
|
|
|
|||
78
examples/esp32c3/Cargo.lock
generated
78
examples/esp32c3/Cargo.lock
generated
|
|
@ -144,6 +144,15 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal-async"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884"
|
||||
dependencies = [
|
||||
"embedded-hal 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum-as-inner"
|
||||
version = "0.4.0"
|
||||
|
|
@ -285,6 +294,7 @@ dependencies = [
|
|||
"esp-println",
|
||||
"esp32c3 0.22.0",
|
||||
"rtic",
|
||||
"rtic-monotonics",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -384,6 +394,30 @@ dependencies = [
|
|||
"gcd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gcd"
|
||||
version = "2.3.0"
|
||||
|
|
@ -479,6 +513,18 @@ version = "1.0.14"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.6.0"
|
||||
|
|
@ -611,6 +657,14 @@ dependencies = [
|
|||
"rtic-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtic-common"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtic-core"
|
||||
version = "1.0.0"
|
||||
|
|
@ -628,6 +682,30 @@ dependencies = [
|
|||
"syn 2.0.53",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtic-monotonics"
|
||||
version = "2.0.2"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"esp32c3 0.22.0",
|
||||
"fugit",
|
||||
"portable-atomic",
|
||||
"riscv",
|
||||
"rtic-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtic-time"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"fugit",
|
||||
"futures-util",
|
||||
"rtic-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.14"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ license = "MIT OR Apache-2.0"
|
|||
|
||||
[dependencies]
|
||||
rtic = {path = "../../rtic/"}
|
||||
rtic-monotonics = {path = "../../rtic-monotonics/"}
|
||||
esp-hal = { version = "0.16.1", features = ["esp32c3", "direct-vectoring", "interrupt-preemption"] }
|
||||
esp-backtrace = { version = "0.11.0", features = [
|
||||
"esp32c3",
|
||||
|
|
@ -21,4 +22,4 @@ esp-println = { version = "0.9.0", features = ["esp32c3", "uart"] }
|
|||
|
||||
[features]
|
||||
test-critical-section = []
|
||||
riscv-esp32c3-backend = ["rtic/riscv-esp32c3-backend"]
|
||||
riscv-esp32c3-backend = ["rtic/riscv-esp32c3-backend", "rtic-monotonics/esp32c3-systimer"]
|
||||
|
|
|
|||
|
|
@ -15,12 +15,24 @@ This crate uses the most convenient option in ``cargo-espflash`` and ``espflash`
|
|||
|
||||
## Running the crate
|
||||
|
||||
Uncomment the
|
||||
|
||||
```runner = "espflash flash --monitor"```
|
||||
|
||||
line in ``.cargo/config.toml``
|
||||
|
||||
and comment out (or remove)
|
||||
|
||||
```runner = "./runner.sh"```
|
||||
|
||||
Now, running
|
||||
|
||||
```cargo run --example sw_and_hw --features=riscv-esp32c3-backend (--release)```
|
||||
|
||||
should do the trick.
|
||||
in the root of this crate should do the trick.
|
||||
|
||||
# Expected behavior
|
||||
The program
|
||||
The example ``sw_and_hw``
|
||||
- Prints ``init``
|
||||
- Enters a high prio task
|
||||
- During the execution of the high prio task, the button should be non-functional
|
||||
|
|
@ -31,3 +43,9 @@ The program
|
|||
- Exits the low prio task
|
||||
- Prints ``idle``
|
||||
|
||||
The example ``monotonic``
|
||||
- Prints ``init``
|
||||
- Spawns the ``foo``, ``bar``, ``baz`` tasks (because of hardware interrupt latency dispatch, the order here may vary).
|
||||
- Each task prints ``hello from $TASK`` on entry
|
||||
- The tasks wait for 1, 2, 3 seconds respectively
|
||||
- Once the wait period is over, each task exits printing ``bye from $TASK`` (now in the proper order).
|
||||
|
|
|
|||
51
examples/esp32c3/examples/monotonic.rs
Normal file
51
examples/esp32c3/examples/monotonic.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
use esp_backtrace as _;
|
||||
#[rtic::app(device = esp32c3, dispatchers = [])]
|
||||
mod app {
|
||||
use rtic_monotonics::esp32c3::prelude::*;
|
||||
esp32c3_systimer_monotonic!(Mono);
|
||||
use esp_hal as _;
|
||||
use esp_println::println;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(cx: init::Context) -> (Shared, Local) {
|
||||
println!("init");
|
||||
let timer = cx.device.SYSTIMER;
|
||||
|
||||
Mono::start(timer);
|
||||
|
||||
foo::spawn().unwrap();
|
||||
bar::spawn().unwrap();
|
||||
baz::spawn().unwrap();
|
||||
|
||||
(Shared {}, Local {})
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn foo(_cx: foo::Context) {
|
||||
println!("hello from foo");
|
||||
Mono::delay(2_u64.secs()).await;
|
||||
println!("bye from foo");
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn bar(_cx: bar::Context) {
|
||||
println!("hello from bar");
|
||||
Mono::delay(3_u64.secs()).await;
|
||||
println!("bye from bar");
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn baz(_cx: baz::Context) {
|
||||
println!("hello from baz");
|
||||
Mono::delay(4_u64.secs()).await;
|
||||
println!("bye from baz");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
#[rtic::app(device = esp32c3, dispatchers=[FROM_CPU_INTR0, FROM_CPU_INTR1])]
|
||||
mod app {
|
||||
use esp_backtrace as _;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2023-11-14"
|
||||
channel = "stable"
|
||||
components = ["rust-src"]
|
||||
targets = ["riscv32imc-unknown-none-elf"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue