From 524273c96a978299b64e51a9cdcc007585a0f170 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 11 Oct 2020 18:38:38 +0200 Subject: Now with spawn/schedule from anywhere --- macros/src/codegen/timer_queue.rs | 69 +++++++++++++-------------------------- 1 file changed, 22 insertions(+), 47 deletions(-) (limited to 'macros/src/codegen/timer_queue.rs') diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index 030158e2..e7d710c6 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -8,16 +8,16 @@ use crate::{analyze::Analysis, check::Extra, codegen::util}; pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec { let mut items = vec![]; - if let Some(timer_queue) = &analysis.timer_queues.first() { + if extra.monotonic.is_some() { let t = util::schedule_t_ident(); // Enumeration of `schedule`-able tasks { - let variants = timer_queue - .tasks + let variants = app + .software_tasks .iter() - .map(|name| { - let cfgs = &app.software_tasks[name].cfgs; + .map(|(name, task)| { + let cfgs = &task.cfgs; quote!( #(#cfgs)* @@ -31,7 +31,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec); items.push(quote!( #[doc = #doc] - static mut #tq: #tq_ty = rtic::export::TimerQueue( + pub static mut #tq: #tq_ty = rtic::export::TimerQueue( rtic::export::BinaryHeap( rtic::export::iBinaryHeap::new() ) ); - - struct #tq<'a> { - priority: &'a rtic::export::Priority, - } - )); - - items.push(util::impl_mutex( - extra, - &[], - false, - &tq, - tq_ty, - timer_queue.ceiling, - quote!(&mut #tq), )); } // Timer queue handler { let device = extra.device; - let arms = timer_queue - .tasks + let arms = app + .software_tasks .iter() - .map(|name| { - let task = &app.software_tasks[name]; - + .map(|(name, task)| { let cfgs = &task.cfgs; let priority = task.args.priority; let rq = util::rq_ident(priority); @@ -95,9 +84,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec { - (#rq { priority: &rtic::export::Priority::new(PRIORITY) }).lock(|rq| { - rq.split().0.enqueue_unchecked((#rqt::#name, index)) - }); + rtic::export::interrupt::free(|_| #rq.split().0.enqueue_unchecked((#rqt::#name, index))); #pend } @@ -105,30 +92,18 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec>(); - let priority = timer_queue.priority; let sys_tick = util::suffixed("SysTick"); items.push(quote!( #[no_mangle] unsafe fn #sys_tick() { use rtic::Mutex as _; - /// The priority of this handler - const PRIORITY: u8 = #priority; - - rtic::export::run(PRIORITY, || { - while let Some((task, index)) = (#tq { - // NOTE dynamic priority is always the static priority at this point - priority: &rtic::export::Priority::new(PRIORITY), - }) - // NOTE `inline(always)` produces faster and smaller code - .lock(#[inline(always)] - |tq| tq.dequeue()) - { - match task { - #(#arms)* - } + while let Some((task, index)) = rtic::export::interrupt::free(|_| #tq.dequeue()) + { + match task { + #(#arms)* } - }); + } } )); } -- cgit v1.2.3