rtic/examples/esp32c3/examples/monotonic.rs
onsdagens 805ea267a8
Add SYSTIMER based ESP32-C3 monotonic (#972)
* add esp32c3 monotonic

* fix tests
2024-09-29 04:21:14 +00:00

51 lines
1.1 KiB
Rust

#![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");
}
}