aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/timer_queue.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/codegen/timer_queue.rs')
-rw-r--r--macros/src/codegen/timer_queue.rs41
1 files changed, 29 insertions, 12 deletions
diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs
index fa2c7b36..9a430a07 100644
--- a/macros/src/codegen/timer_queue.rs
+++ b/macros/src/codegen/timer_queue.rs
@@ -5,10 +5,10 @@ use rtic_syntax::ast::App;
use crate::{analyze::Analysis, check::Extra, codegen::util};
/// Generates timer queues and timer queue handlers
-pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream2> {
+pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStream2> {
let mut items = vec![];
- if let Some(m) = &extra.monotonic {
+ if !app.monotonics.is_empty() {
let t = util::schedule_t_ident();
// Enumeration of `schedule`-able tasks
@@ -36,12 +36,17 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
}
));
}
+ }
- let tq = util::tq_ident();
+ for (_, monotonic) in &app.monotonics {
+ let monotonic_name = monotonic.ident.to_string();
+ let tq = util::tq_ident(&monotonic_name);
+ let t = util::schedule_t_ident();
+ let m = &monotonic.ident;
- // Static variable and resource proxy
+ // Static variables and resource proxy
{
- let doc = "Timer queue".to_string();
+ let doc = &format!("Timer queue for {}", monotonic_name);
let cap = app
.software_tasks
.iter()
@@ -62,6 +67,9 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
// Timer queue handler
{
+ let enum_ = util::interrupt_ident();
+ let rt_err = util::rt_err_ident();
+
let arms = app
.software_tasks
.iter()
@@ -70,12 +78,13 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let priority = task.args.priority;
let rq = util::rq_ident(priority);
let rqt = util::spawn_t_ident(priority);
- let enum_ = util::interrupt_ident();
+
+ // The interrupt that runs the task dispatcher
let interrupt = &analysis.interrupts.get(&priority).expect("RTIC-ICE: interrupt not found").0;
let pend = {
quote!(
- rtic::pend(you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml::#enum_::#interrupt);
+ rtic::pend(#rt_err::#enum_::#interrupt);
)
};
@@ -90,13 +99,20 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
})
.collect::<Vec<_>>();
- let sys_tick = util::suffixed("SysTick");
+ let bound_interrupt = &monotonic.args.binds;
+ let enable_isr = if &*bound_interrupt.to_string() == "SysTick" {
+ quote!(core::mem::transmute::<_, cortex_m::peripheral::SYST>(()).enable_interrupt())
+ } else {
+ quote!(rtic::export::NVIC::mask(#rt_err::#enum_::#bound_interrupt))
+ };
+
items.push(quote!(
#[no_mangle]
- unsafe fn #sys_tick() {
- use rtic::Mutex as _;
-
- while let Some((task, index)) = rtic::export::interrupt::free(|_| #tq.dequeue())
+ #[allow(non_snake_case)]
+ unsafe fn #bound_interrupt() {
+ while let Some((task, index)) = rtic::export::interrupt::free(|_| #tq.dequeue(
+ || #enable_isr,
+ ))
{
match task {
#(#arms)*
@@ -106,5 +122,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
));
}
}
+
items
}