mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-29 15:04:32 +01:00
Cleanup
This commit is contained in:
parent
6277183906
commit
aaa92ea2fa
3 changed files with 47 additions and 63 deletions
|
@ -204,10 +204,6 @@ pub fn codegen(
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub fn spawn(#(#args,)*) -> Result<(), #ty> {
|
pub fn spawn(#(#args,)*) -> Result<(), #ty> {
|
||||||
// #let_instant // do we need it?
|
|
||||||
use rtic::Mutex as _;
|
|
||||||
use rtic::mutex_prelude::*;
|
|
||||||
|
|
||||||
let input = #tupled;
|
let input = #tupled;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -277,9 +273,6 @@ pub fn codegen(
|
||||||
#(,#args)*
|
#(,#args)*
|
||||||
) -> Result<(), #ty> {
|
) -> Result<(), #ty> {
|
||||||
unsafe {
|
unsafe {
|
||||||
use rtic::Mutex as _;
|
|
||||||
use rtic::mutex_prelude::*;
|
|
||||||
|
|
||||||
let input = #tupled;
|
let input = #tupled;
|
||||||
if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) {
|
if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) {
|
||||||
#app_path::#inputs
|
#app_path::#inputs
|
||||||
|
|
|
@ -68,8 +68,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
|
||||||
// Timer queue handler
|
// Timer queue handler
|
||||||
{
|
{
|
||||||
let enum_ = util::interrupt_ident();
|
let enum_ = util::interrupt_ident();
|
||||||
let app_name = &app.name;
|
|
||||||
let app_path = quote! {crate::#app_name};
|
|
||||||
let rt_err = util::rt_err_ident();
|
let rt_err = util::rt_err_ident();
|
||||||
|
|
||||||
let arms = app
|
let arms = app
|
||||||
|
@ -111,8 +109,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe fn #bound_interrupt() {
|
unsafe fn #bound_interrupt() {
|
||||||
use rtic::Mutex as _;
|
|
||||||
|
|
||||||
while let Some((task, index)) = rtic::export::interrupt::free(|_| #tq.dequeue(
|
while let Some((task, index)) = rtic::export::interrupt::free(|_| #tq.dequeue(
|
||||||
|| #enable_isr,
|
|| #enable_isr,
|
||||||
))
|
))
|
||||||
|
|
99
src/tq.rs
99
src/tq.rs
|
@ -2,17 +2,17 @@ use crate::{time::Instant, Monotonic};
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use heapless::{binary_heap::Min, ArrayLength, BinaryHeap};
|
use heapless::{binary_heap::Min, ArrayLength, BinaryHeap};
|
||||||
|
|
||||||
pub struct TimerQueue<M, T, N>(pub BinaryHeap<NotReady<M, T>, N, Min>)
|
pub struct TimerQueue<Mono, Task, N>(pub BinaryHeap<NotReady<Mono, Task>, N, Min>)
|
||||||
where
|
where
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
N: ArrayLength<NotReady<M, T>>,
|
N: ArrayLength<NotReady<Mono, Task>>,
|
||||||
T: Copy;
|
Task: Copy;
|
||||||
|
|
||||||
impl<M, T, N> TimerQueue<M, T, N>
|
impl<Mono, Task, N> TimerQueue<Mono, Task, N>
|
||||||
where
|
where
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
N: ArrayLength<NotReady<M, T>>,
|
N: ArrayLength<NotReady<Mono, Task>>,
|
||||||
T: Copy,
|
Task: Copy,
|
||||||
{
|
{
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
|
@ -23,7 +23,7 @@ where
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn enqueue_unchecked<F1, F2>(
|
pub unsafe fn enqueue_unchecked<F1, F2>(
|
||||||
&mut self,
|
&mut self,
|
||||||
nr: NotReady<M, T>,
|
nr: NotReady<Mono, Task>,
|
||||||
enable_interrupt: F1,
|
enable_interrupt: F1,
|
||||||
pend_handler: F2,
|
pend_handler: F2,
|
||||||
) where
|
) where
|
||||||
|
@ -63,44 +63,39 @@ where
|
||||||
|
|
||||||
/// Dequeue a task from the TimerQueue
|
/// Dequeue a task from the TimerQueue
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn dequeue<F>(&mut self, disable_interrupt: F) -> Option<(T, u8)>
|
pub fn dequeue<F>(&mut self, disable_interrupt: F) -> Option<(Task, u8)>
|
||||||
where
|
where
|
||||||
F: FnOnce(),
|
F: FnOnce(),
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
M::clear_compare();
|
Mono::clear_compare();
|
||||||
|
|
||||||
if let Some(instant) = self.0.peek().map(|p| p.instant) {
|
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) {
|
Some((nr.task, nr.index))
|
||||||
None => {
|
} else {
|
||||||
// instant < now
|
// TODO: Fix this hack...
|
||||||
// task became ready
|
// 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();
|
let nr = self.0.pop_unchecked();
|
||||||
|
|
||||||
Some((nr.task, nr.index))
|
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
|
// Start counting down from the new reload
|
||||||
// dequeue. If the monotonic is fast enough it can happen that from the
|
// mem::transmute::<_, SYST>(()).clear_current();
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The queue is empty
|
// The queue is empty
|
||||||
|
@ -113,47 +108,47 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NotReady<M, T>
|
pub struct NotReady<Mono, Task>
|
||||||
where
|
where
|
||||||
T: Copy,
|
Task: Copy,
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
{
|
{
|
||||||
pub index: u8,
|
pub index: u8,
|
||||||
pub instant: Instant<M>,
|
pub instant: Instant<Mono>,
|
||||||
pub task: T,
|
pub task: Task,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M, T> Eq for NotReady<M, T>
|
impl<Mono, Task> Eq for NotReady<Mono, Task>
|
||||||
where
|
where
|
||||||
T: Copy,
|
Task: Copy,
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M, T> Ord for NotReady<M, T>
|
impl<Mono, Task> Ord for NotReady<Mono, Task>
|
||||||
where
|
where
|
||||||
T: Copy,
|
Task: Copy,
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
{
|
{
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
self.instant.cmp(&other.instant)
|
self.instant.cmp(&other.instant)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M, T> PartialEq for NotReady<M, T>
|
impl<Mono, Task> PartialEq for NotReady<Mono, Task>
|
||||||
where
|
where
|
||||||
T: Copy,
|
Task: Copy,
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
{
|
{
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.instant == other.instant
|
self.instant == other.instant
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M, T> PartialOrd for NotReady<M, T>
|
impl<Mono, Task> PartialOrd for NotReady<Mono, Task>
|
||||||
where
|
where
|
||||||
T: Copy,
|
Task: Copy,
|
||||||
M: Monotonic,
|
Mono: Monotonic,
|
||||||
{
|
{
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
Some(self.cmp(&other))
|
Some(self.cmp(&other))
|
||||||
|
|
Loading…
Reference in a new issue