mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 22:05:37 +01:00
add example of using async from an interrupt triggered task
This commit is contained in:
parent
9058a655dc
commit
20c5e277f7
12 changed files with 168 additions and 16 deletions
|
|
@ -1,4 +1,3 @@
|
|||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
74
examples/interrupt-async-after.rs
Normal file
74
examples/interrupt-async-after.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use]
|
||||
extern crate cortex_m;
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate panic_abort;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
use cortex_m::asm;
|
||||
use cortex_m::peripheral::{DWT, ITM};
|
||||
use rtfm::app;
|
||||
|
||||
app! {
|
||||
device: stm32f103xx,
|
||||
|
||||
resources: {
|
||||
static ITM: ITM;
|
||||
},
|
||||
|
||||
free_interrupts: [EXTI1],
|
||||
|
||||
tasks: {
|
||||
exti0: {
|
||||
interrupt: EXTI0,
|
||||
async_after: [a],
|
||||
resources: [ITM],
|
||||
},
|
||||
|
||||
a: {
|
||||
resources: [ITM],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const S: u32 = 8_000_000;
|
||||
|
||||
#[inline(always)]
|
||||
fn init(ctxt: init::Context) -> init::LateResources {
|
||||
unsafe { rtfm::set_pending(stm32f103xx::Interrupt::EXTI0) }
|
||||
|
||||
init::LateResources { ITM: ctxt.core.ITM }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn idle(_ctxt: idle::Context) -> ! {
|
||||
loop {
|
||||
asm::wfi();
|
||||
}
|
||||
}
|
||||
|
||||
fn exti0(mut ctxt: exti0::Context) {
|
||||
let now = DWT::get_cycle_count();
|
||||
iprintln!(
|
||||
&mut ctxt.resources.ITM.stim[0],
|
||||
"exti0(bl={}, now={})",
|
||||
ctxt.baseline,
|
||||
now
|
||||
);
|
||||
|
||||
let t = &mut ctxt.threshold;
|
||||
ctxt.async.a.post(t, 1 * S, ()).ok();
|
||||
}
|
||||
|
||||
fn a(ctxt: a::Context) {
|
||||
let now = DWT::get_cycle_count();
|
||||
iprintln!(
|
||||
&mut ctxt.resources.ITM.stim[0],
|
||||
"a(bl={}, now={})",
|
||||
ctxt.baseline,
|
||||
now
|
||||
);
|
||||
}
|
||||
72
examples/interrupt-async.rs
Normal file
72
examples/interrupt-async.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use]
|
||||
extern crate cortex_m;
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
extern crate panic_abort;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
use cortex_m::asm;
|
||||
use cortex_m::peripheral::{DWT, ITM};
|
||||
use rtfm::app;
|
||||
|
||||
app! {
|
||||
device: stm32f103xx,
|
||||
|
||||
resources: {
|
||||
static ITM: ITM;
|
||||
},
|
||||
|
||||
free_interrupts: [EXTI1],
|
||||
|
||||
tasks: {
|
||||
exti0: {
|
||||
interrupt: EXTI0,
|
||||
async: [a],
|
||||
resources: [ITM],
|
||||
},
|
||||
|
||||
a: {
|
||||
resources: [ITM],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn init(ctxt: init::Context) -> init::LateResources {
|
||||
unsafe { rtfm::set_pending(stm32f103xx::Interrupt::EXTI0) }
|
||||
|
||||
init::LateResources { ITM: ctxt.core.ITM }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn idle(_ctxt: idle::Context) -> ! {
|
||||
loop {
|
||||
asm::wfi();
|
||||
}
|
||||
}
|
||||
|
||||
fn exti0(mut ctxt: exti0::Context) {
|
||||
let now = DWT::get_cycle_count();
|
||||
iprintln!(
|
||||
&mut ctxt.resources.ITM.stim[0],
|
||||
"exti0(bl={}, now={})",
|
||||
ctxt.baseline,
|
||||
now
|
||||
);
|
||||
|
||||
let t = &mut ctxt.threshold;
|
||||
ctxt.async.a.post(t, ()).ok();
|
||||
}
|
||||
|
||||
fn a(ctxt: a::Context) {
|
||||
let now = DWT::get_cycle_count();
|
||||
iprintln!(
|
||||
&mut ctxt.resources.ITM.stim[0],
|
||||
"a(bl={}, now={})",
|
||||
ctxt.baseline,
|
||||
now
|
||||
);
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
// a(bl=16000000, now=16000168, input=1)
|
||||
// a(bl=24000000, now=24000168, input=2)
|
||||
|
||||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
// b(bl=96000000, now=96000259, input=3)
|
||||
// a(bl=96000000, now=96002397, input=5)
|
||||
|
||||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
// b(bl=96000000, now=96000257)
|
||||
// a(bl=96000000, now=96001705)
|
||||
|
||||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
@ -33,8 +32,7 @@
|
|||
#[macro_use]
|
||||
extern crate cortex_m;
|
||||
extern crate cortex_m_rtfm as rtfm;
|
||||
// extern crate panic_abort;
|
||||
extern crate panic_itm;
|
||||
extern crate panic_abort;
|
||||
extern crate stm32f103xx;
|
||||
|
||||
use cortex_m::asm;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
// a(bl=8000000, now=8000168)
|
||||
// a(bl=16000000, now=16000168)
|
||||
|
||||
#![allow(warnings)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![feature(proc_macro)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue