mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-29 23:14:34 +01:00
WIP
This commit is contained in:
parent
d665ea95b3
commit
14fedeb342
5 changed files with 24 additions and 22 deletions
|
@ -1,8 +1,6 @@
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::{ops, ptr};
|
use core::{ops, ptr};
|
||||||
|
|
||||||
use cortex_m::peripheral::DWT;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Instant(pub u32);
|
pub struct Instant(pub u32);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ mod tq;
|
||||||
pub type FreeQueue<N> = Queue<u8, N, u8>;
|
pub type FreeQueue<N> = Queue<u8, N, u8>;
|
||||||
pub type ReadyQueue<T, N> = Queue<(T, u8), N, u8>;
|
pub type ReadyQueue<T, N> = Queue<(T, u8), N, u8>;
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
pub struct Peripherals<'a> {
|
pub struct Peripherals<'a> {
|
||||||
pub CBP: CBP,
|
pub CBP: CBP,
|
||||||
|
@ -30,6 +31,7 @@ pub struct Peripherals<'a> {
|
||||||
pub TPIU: TPIU,
|
pub TPIU: TPIU,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
pub struct Peripherals {
|
pub struct Peripherals {
|
||||||
pub CBP: CBP,
|
pub CBP: CBP,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use core::cmp::{self, Ordering};
|
||||||
use cortex_m::peripheral::{SCB, SYST};
|
use cortex_m::peripheral::{SCB, SYST};
|
||||||
use heapless::binary_heap::{BinaryHeap, Min};
|
use heapless::binary_heap::{BinaryHeap, Min};
|
||||||
use heapless::ArrayLength;
|
use heapless::ArrayLength;
|
||||||
use typenum::{Max, Maximum, Unsigned};
|
use typenum::{Max, Unsigned};
|
||||||
|
|
||||||
use _impl::Instant;
|
use _impl::Instant;
|
||||||
use resource::{Priority, Resource};
|
use resource::{Priority, Resource};
|
||||||
|
@ -71,7 +71,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// set SysTick pending
|
// set SysTick pending
|
||||||
unsafe { (*SCB::ptr()).icsr.write(1 << 26) }
|
(*SCB::ptr()).icsr.write(1 << 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.queue.push_unchecked(m);
|
self.queue.push_unchecked(m);
|
||||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -1,10 +1,12 @@
|
||||||
// #![deny(missing_docs)]
|
//! Real Time for The Masses: high performance, predictable, bare metal task scheduler
|
||||||
// #![deny(warnings)]
|
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
|
#![deny(missing_docs)]
|
||||||
|
#![deny(warnings)]
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
|
#![feature(never_type)]
|
||||||
#![feature(proc_macro)]
|
#![feature(proc_macro)]
|
||||||
#![feature(untagged_unions)]
|
#![feature(untagged_unions)]
|
||||||
#![feature(never_type)]
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate cortex_m;
|
extern crate cortex_m;
|
||||||
|
@ -12,11 +14,8 @@ extern crate cortex_m_rtfm_macros;
|
||||||
extern crate heapless;
|
extern crate heapless;
|
||||||
extern crate typenum;
|
extern crate typenum;
|
||||||
|
|
||||||
use core::mem;
|
use cortex_m::interrupt;
|
||||||
|
|
||||||
use cortex_m::interrupt::{self, Nr};
|
|
||||||
pub use cortex_m_rtfm_macros::app;
|
pub use cortex_m_rtfm_macros::app;
|
||||||
use heapless::ring_buffer::RingBuffer;
|
|
||||||
use typenum::consts::*;
|
use typenum::consts::*;
|
||||||
use typenum::Unsigned;
|
use typenum::Unsigned;
|
||||||
|
|
||||||
|
@ -26,15 +25,17 @@ pub use resource::{Priority, Resource};
|
||||||
pub mod _impl;
|
pub mod _impl;
|
||||||
mod resource;
|
mod resource;
|
||||||
|
|
||||||
/// TODO
|
/// Executes the given closure atomically
|
||||||
pub fn atomic<R, P, F>(t: &mut Priority<P>, f: F) -> R
|
///
|
||||||
|
/// While the closure is being executed no new task can start
|
||||||
|
pub fn atomic<R, P, F>(_p: &mut Priority<P>, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Priority<U255>) -> R,
|
F: FnOnce(&mut Priority<U255>) -> R,
|
||||||
P: Unsigned,
|
P: Unsigned,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
// Sanity check
|
// Sanity check
|
||||||
debug_assert!(P::to_u8() <= 255);
|
debug_assert!(P::to_usize() <= 255);
|
||||||
|
|
||||||
if P::to_u8() < 255 {
|
if P::to_u8() < 255 {
|
||||||
interrupt::disable();
|
interrupt::disable();
|
||||||
|
|
|
@ -6,7 +6,7 @@ use cortex_m::register::basepri;
|
||||||
use typenum::type_operators::IsGreaterOrEqual;
|
use typenum::type_operators::IsGreaterOrEqual;
|
||||||
use typenum::{Max, Maximum, True, Unsigned};
|
use typenum::{Max, Maximum, True, Unsigned};
|
||||||
|
|
||||||
/// TODO
|
/// Token that represents the current priority level of a task
|
||||||
pub struct Priority<N> {
|
pub struct Priority<N> {
|
||||||
_not_send_or_sync: PhantomData<*const ()>,
|
_not_send_or_sync: PhantomData<*const ()>,
|
||||||
_n: PhantomData<N>,
|
_n: PhantomData<N>,
|
||||||
|
@ -22,22 +22,22 @@ impl<N> Priority<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// A resource shared between two or more tasks
|
||||||
pub unsafe trait Resource {
|
pub unsafe trait Resource {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
const NVIC_PRIO_BITS: u8;
|
const NVIC_PRIO_BITS: u8;
|
||||||
|
|
||||||
/// TODO
|
/// The priority ceiling of the resource
|
||||||
type Ceiling;
|
type Ceiling;
|
||||||
|
|
||||||
/// TODO
|
/// The data protected by the resource
|
||||||
type Data: 'static + Send;
|
type Data: 'static + Send;
|
||||||
|
|
||||||
// The `static mut` variable that the resource protects fs
|
// The `static mut` variable that the resource protects fs
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
unsafe fn _var() -> &'static mut Self::Data;
|
unsafe fn _var() -> &'static mut Self::Data;
|
||||||
|
|
||||||
/// TODO
|
/// Borrows the resource data for the span of the current priority
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn borrow<'cs, P>(&'cs self, _p: &'cs Priority<P>) -> &'cs Self::Data
|
fn borrow<'cs, P>(&'cs self, _p: &'cs Priority<P>) -> &'cs Self::Data
|
||||||
where
|
where
|
||||||
|
@ -46,7 +46,7 @@ pub unsafe trait Resource {
|
||||||
unsafe { Self::_var() }
|
unsafe { Self::_var() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Mutably borrows the resource data for the span of the current priority
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn borrow_mut<'cs, P>(&'cs mut self, _p: &'cs Priority<P>) -> &'cs mut Self::Data
|
fn borrow_mut<'cs, P>(&'cs mut self, _p: &'cs Priority<P>) -> &'cs mut Self::Data
|
||||||
where
|
where
|
||||||
|
@ -55,7 +55,7 @@ pub unsafe trait Resource {
|
||||||
unsafe { Self::_var() }
|
unsafe { Self::_var() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Creates a critical section, by raising the task priority, to access the resource data
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn claim<'cs, R, F, P>(&self, _p: &mut Priority<P>, f: F) -> R
|
fn claim<'cs, R, F, P>(&self, _p: &mut Priority<P>, f: F) -> R
|
||||||
where
|
where
|
||||||
|
@ -79,7 +79,8 @@ pub unsafe trait Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// Creates a critical section, by raising the task priority, to mutably access the resource
|
||||||
|
/// data
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn claim_mut<'cs, R, F, P>(&mut self, _p: &mut Priority<P>, f: F) -> R
|
fn claim_mut<'cs, R, F, P>(&mut self, _p: &mut Priority<P>, f: F) -> R
|
||||||
where
|
where
|
||||||
|
|
Loading…
Reference in a new issue