diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index bf77c4d9fb..d15b5eca8a 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -204,10 +204,6 @@ pub fn codegen( items.push(quote!( #(#cfgs)* pub fn spawn(#(#args,)*) -> Result<(), #ty> { - // #let_instant // do we need it? - use rtic::Mutex as _; - use rtic::mutex_prelude::*; - let input = #tupled; unsafe { @@ -277,9 +273,6 @@ pub fn codegen( #(,#args)* ) -> Result<(), #ty> { unsafe { - use rtic::Mutex as _; - use rtic::mutex_prelude::*; - let input = #tupled; if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) { #app_path::#inputs diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index ef0fda37df..99dfa5bf2a 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -68,8 +68,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec Vec(pub BinaryHeap, N, Min>) +pub struct TimerQueue(pub BinaryHeap, N, Min>) where - M: Monotonic, - N: ArrayLength>, - T: Copy; + Mono: Monotonic, + N: ArrayLength>, + Task: Copy; -impl TimerQueue +impl TimerQueue where - M: Monotonic, - N: ArrayLength>, - T: Copy, + Mono: Monotonic, + N: ArrayLength>, + Task: Copy, { /// # Safety /// @@ -23,7 +23,7 @@ where #[inline] pub unsafe fn enqueue_unchecked( &mut self, - nr: NotReady, + nr: NotReady, enable_interrupt: F1, pend_handler: F2, ) where @@ -63,44 +63,39 @@ where /// Dequeue a task from the TimerQueue #[inline] - pub fn dequeue(&mut self, disable_interrupt: F) -> Option<(T, u8)> + pub fn dequeue(&mut self, disable_interrupt: F) -> Option<(Task, u8)> where F: FnOnce(), { unsafe { - M::clear_compare(); + Mono::clear_compare(); if let Some(instant) = self.0.peek().map(|p| p.instant) { - let now = M::now(); + if instant < Mono::now() { + // instant < now + // task became ready + let nr = self.0.pop_unchecked(); - match instant.checked_duration_since(&now) { - None => { - // instant < now - // task became ready + Some((nr.task, nr.index)) + } else { + // TODO: Fix this hack... + // Extract the compare time + Mono::set_compare(*instant.duration_since_epoch().integer()); + + // Double check that the instant we set is really in the future, else + // dequeue. If the monotonic is fast enough it can happen that from the + // read of now to the set of the compare, the time can overflow. This is to + // guard against this. + if instant < Mono::now() { let nr = self.0.pop_unchecked(); Some((nr.task, nr.index)) + } else { + None } - Some(_) => { - // TODO: Fix this hack... - // Extract the compare time - M::set_compare(*instant.duration_since_epoch().integer()); - // Double check that the instant we set is really in the future, else - // dequeue. If the monotonic is fast enough it can happen that from the - // read of now to the set of the compare, the time can overflow. This is to - // guard against this. - if instant.checked_duration_since(&M::now()).is_none() { - let nr = self.0.pop_unchecked(); - - Some((nr.task, nr.index)) - } else { - None - } - - // Start counting down from the new reload - // mem::transmute::<_, SYST>(()).clear_current(); - } + // Start counting down from the new reload + // mem::transmute::<_, SYST>(()).clear_current(); } } else { // The queue is empty @@ -113,47 +108,47 @@ where } } -pub struct NotReady +pub struct NotReady where - T: Copy, - M: Monotonic, + Task: Copy, + Mono: Monotonic, { pub index: u8, - pub instant: Instant, - pub task: T, + pub instant: Instant, + pub task: Task, } -impl Eq for NotReady +impl Eq for NotReady where - T: Copy, - M: Monotonic, + Task: Copy, + Mono: Monotonic, { } -impl Ord for NotReady +impl Ord for NotReady where - T: Copy, - M: Monotonic, + Task: Copy, + Mono: Monotonic, { fn cmp(&self, other: &Self) -> Ordering { self.instant.cmp(&other.instant) } } -impl PartialEq for NotReady +impl PartialEq for NotReady where - T: Copy, - M: Monotonic, + Task: Copy, + Mono: Monotonic, { fn eq(&self, other: &Self) -> bool { self.instant == other.instant } } -impl PartialOrd for NotReady +impl PartialOrd for NotReady where - T: Copy, - M: Monotonic, + Task: Copy, + Mono: Monotonic, { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(&other))