diff --git a/Cargo.toml b/Cargo.toml index 5e9d548338..e703dbdbf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,14 @@ name = "empty" [[example]] name = "interrupt" +[[example]] +name = "interrupt-async" +required-features = ["timer-queue"] + +[[example]] +name = "interrupt-async-after" +required-features = ["timer-queue"] + [[example]] name = "periodic-payload" required-features = ["timer-queue"] diff --git a/examples/async-after.rs b/examples/async-after.rs index f28a05b670..f96ceb8ed1 100644 --- a/examples/async-after.rs +++ b/examples/async-after.rs @@ -1,4 +1,3 @@ -#![allow(warnings)] #![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] diff --git a/examples/async.rs b/examples/async.rs index 6a3efc9c27..f56e9a495b 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -1,4 +1,3 @@ -#![allow(warnings)] #![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] diff --git a/examples/empty.rs b/examples/empty.rs index a89cc78189..85ec24ce8d 100644 --- a/examples/empty.rs +++ b/examples/empty.rs @@ -1,4 +1,3 @@ -#![allow(warnings)] #![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] diff --git a/examples/interrupt-async-after.rs b/examples/interrupt-async-after.rs new file mode 100644 index 0000000000..1e7a3ac0ab --- /dev/null +++ b/examples/interrupt-async-after.rs @@ -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 + ); +} diff --git a/examples/interrupt-async.rs b/examples/interrupt-async.rs new file mode 100644 index 0000000000..c3b6f3d2ae --- /dev/null +++ b/examples/interrupt-async.rs @@ -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 + ); +} diff --git a/examples/interrupt.rs b/examples/interrupt.rs index 3f4239dc23..6b0b3a670c 100644 --- a/examples/interrupt.rs +++ b/examples/interrupt.rs @@ -1,4 +1,3 @@ -#![allow(warnings)] #![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] diff --git a/examples/periodic-payload.rs b/examples/periodic-payload.rs index df17dd172a..7b09e91c82 100644 --- a/examples/periodic-payload.rs +++ b/examples/periodic-payload.rs @@ -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)] diff --git a/examples/periodic-preemption-payload.rs b/examples/periodic-preemption-payload.rs index 9f46eaf7de..9f3bbb2b1f 100644 --- a/examples/periodic-preemption-payload.rs +++ b/examples/periodic-preemption-payload.rs @@ -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)] diff --git a/examples/periodic-preemption.rs b/examples/periodic-preemption.rs index bf5e3fe52d..08ad528c05 100644 --- a/examples/periodic-preemption.rs +++ b/examples/periodic-preemption.rs @@ -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; diff --git a/examples/periodic.rs b/examples/periodic.rs index 1b65d21eee..e086e0ae94 100644 --- a/examples/periodic.rs +++ b/examples/periodic.rs @@ -7,7 +7,6 @@ // a(bl=8000000, now=8000168) // a(bl=16000000, now=16000168) -#![allow(warnings)] #![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] diff --git a/macros/src/trans.rs b/macros/src/trans.rs index ec36d10f8b..66a39498cf 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -335,6 +335,7 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { let task = &app.tasks[name]; let priority = task.priority; let __priority = Ident::from(format!("__{}", priority)); + let interrupt = ctxt.dispatchers[&priority].interrupt(); let ty = &task.input; let sqc = Ident::from(format!( @@ -370,8 +371,8 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { #krate::Maximum: #krate::Unsigned, { unsafe { - if let Some(slot) = - ::#name::SQ::new().claim_mut(t, |sq, _| sq.dequeue()) { + let slot = ::#name::SQ::new().claim_mut(t, |sq, _| sq.dequeue()); + if let Some(slot) = slot { let tp = slot .write(self.baseline, payload) .tag(::#__priority::Task::#name); @@ -380,6 +381,8 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { q.split().0.enqueue_unchecked(tp); }); + #krate::set_pending(#device::Interrupt::#interrupt); + Ok(()) } else { Err(payload) @@ -424,6 +427,8 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { q.split().0.enqueue_unchecked(tp); }); + #krate::set_pending(#device::Interrupt::#interrupt); + Ok(()) } else { Err(payload) @@ -750,10 +755,12 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { let async_exprs = app.init .async .iter() - .map(|task| if cfg!(feature = "timer-queue") { - quote!(#task: ::__async::#task::new(_bl)) - } else { - quote!(#task: ::__async::#task::new()) + .map(|task| { + if cfg!(feature = "timer-queue") { + quote!(#task: ::__async::#task::new(_bl)) + } else { + quote!(#task: ::__async::#task::new()) + } }) .chain( app.init