mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
Port ESP32-C3 changes to ESP32-C6 branch
This commit is contained in:
parent
0efb77300e
commit
ef09e4b65f
13 changed files with 916 additions and 454 deletions
51
examples/esp32c6/examples/monotonic.rs
Normal file
51
examples/esp32c6/examples/monotonic.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
use esp_backtrace as _;
|
||||
#[rtic::app(device = esp32c6, dispatchers = [])]
|
||||
mod app {
|
||||
use rtic_monotonics::esp32c6::prelude::*;
|
||||
esp32c6_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");
|
||||
}
|
||||
}
|
||||
|
|
@ -4,27 +4,23 @@
|
|||
#[rtic::app(device = esp32c6, dispatchers=[FROM_CPU_INTR0, FROM_CPU_INTR1])]
|
||||
mod app {
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{
|
||||
gpio::{Event, Gpio9, Input, PullUp, IO},
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
};
|
||||
use esp_hal::gpio::{Event, Input, Pull};
|
||||
use esp_println::println;
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
button: Gpio9<Input<PullUp>>,
|
||||
button: Input<'static>,
|
||||
}
|
||||
|
||||
// do nothing in init
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local) {
|
||||
println!("init");
|
||||
let peripherals = Peripherals::take();
|
||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut button = io.pins.gpio9.into_pull_up_input();
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
let mut button = Input::new(peripherals.GPIO9, Pull::Up);
|
||||
button.listen(Event::FallingEdge);
|
||||
foo::spawn().unwrap();
|
||||
(Shared {}, Local { button })
|
||||
|
|
@ -41,17 +37,18 @@ mod app {
|
|||
bar::spawn().unwrap(); //enqueue low prio task
|
||||
println!("Inside high prio task, press button now!");
|
||||
let mut x = 0;
|
||||
while x < 5000000 {
|
||||
while x < 50000000 {
|
||||
x += 1; //burn cycles
|
||||
esp_hal::riscv::asm::nop();
|
||||
}
|
||||
println!("Leaving high prio task.");
|
||||
}
|
||||
|
||||
#[task(priority = 2)]
|
||||
async fn bar(_: bar::Context) {
|
||||
println!("Inside low prio task, press button now!");
|
||||
let mut x = 0;
|
||||
while x < 5000000 {
|
||||
while x < 50000000 {
|
||||
x += 1; //burn cycles
|
||||
esp_hal::riscv::asm::nop();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue