This commit is contained in:
Jorge Aparicio 2018-05-16 01:15:44 +02:00
parent d665ea95b3
commit 14fedeb342
5 changed files with 24 additions and 22 deletions

View file

@ -1,8 +1,6 @@
use core::cmp::Ordering;
use core::{ops, ptr};
use cortex_m::peripheral::DWT;
#[derive(Clone, Copy, Debug)]
pub struct Instant(pub u32);

View file

@ -16,6 +16,7 @@ mod tq;
pub type FreeQueue<N> = Queue<u8, N, u8>;
pub type ReadyQueue<T, N> = Queue<(T, u8), N, u8>;
#[allow(non_snake_case)]
#[cfg(feature = "timer-queue")]
pub struct Peripherals<'a> {
pub CBP: CBP,
@ -30,6 +31,7 @@ pub struct Peripherals<'a> {
pub TPIU: TPIU,
}
#[allow(non_snake_case)]
#[cfg(not(feature = "timer-queue"))]
pub struct Peripherals {
pub CBP: CBP,

View file

@ -3,7 +3,7 @@ use core::cmp::{self, Ordering};
use cortex_m::peripheral::{SCB, SYST};
use heapless::binary_heap::{BinaryHeap, Min};
use heapless::ArrayLength;
use typenum::{Max, Maximum, Unsigned};
use typenum::{Max, Unsigned};
use _impl::Instant;
use resource::{Priority, Resource};
@ -71,7 +71,7 @@ where
}
// set SysTick pending
unsafe { (*SCB::ptr()).icsr.write(1 << 26) }
(*SCB::ptr()).icsr.write(1 << 26);
}
self.queue.push_unchecked(m);

View file

@ -1,10 +1,12 @@
// #![deny(missing_docs)]
// #![deny(warnings)]
//! Real Time for The Masses: high performance, predictable, bare metal task scheduler
#![allow(warnings)]
#![deny(missing_docs)]
#![deny(warnings)]
#![feature(const_fn)]
#![feature(never_type)]
#![feature(proc_macro)]
#![feature(untagged_unions)]
#![feature(never_type)]
#![no_std]
extern crate cortex_m;
@ -12,11 +14,8 @@ extern crate cortex_m_rtfm_macros;
extern crate heapless;
extern crate typenum;
use core::mem;
use cortex_m::interrupt::{self, Nr};
use cortex_m::interrupt;
pub use cortex_m_rtfm_macros::app;
use heapless::ring_buffer::RingBuffer;
use typenum::consts::*;
use typenum::Unsigned;
@ -26,15 +25,17 @@ pub use resource::{Priority, Resource};
pub mod _impl;
mod resource;
/// TODO
pub fn atomic<R, P, F>(t: &mut Priority<P>, f: F) -> R
/// Executes the given closure atomically
///
/// 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
F: FnOnce(&mut Priority<U255>) -> R,
P: Unsigned,
{
unsafe {
// Sanity check
debug_assert!(P::to_u8() <= 255);
debug_assert!(P::to_usize() <= 255);
if P::to_u8() < 255 {
interrupt::disable();

View file

@ -6,7 +6,7 @@ use cortex_m::register::basepri;
use typenum::type_operators::IsGreaterOrEqual;
use typenum::{Max, Maximum, True, Unsigned};
/// TODO
/// Token that represents the current priority level of a task
pub struct Priority<N> {
_not_send_or_sync: PhantomData<*const ()>,
_n: PhantomData<N>,
@ -22,22 +22,22 @@ impl<N> Priority<N> {
}
}
/// TODO
/// A resource shared between two or more tasks
pub unsafe trait Resource {
#[doc(hidden)]
const NVIC_PRIO_BITS: u8;
/// TODO
/// The priority ceiling of the resource
type Ceiling;
/// TODO
/// The data protected by the resource
type Data: 'static + Send;
// The `static mut` variable that the resource protects fs
#[doc(hidden)]
unsafe fn _var() -> &'static mut Self::Data;
/// TODO
/// Borrows the resource data for the span of the current priority
#[inline(always)]
fn borrow<'cs, P>(&'cs self, _p: &'cs Priority<P>) -> &'cs Self::Data
where
@ -46,7 +46,7 @@ pub unsafe trait Resource {
unsafe { Self::_var() }
}
/// TODO
/// Mutably borrows the resource data for the span of the current priority
#[inline(always)]
fn borrow_mut<'cs, P>(&'cs mut self, _p: &'cs Priority<P>) -> &'cs mut Self::Data
where
@ -55,7 +55,7 @@ pub unsafe trait Resource {
unsafe { Self::_var() }
}
/// TODO
/// Creates a critical section, by raising the task priority, to access the resource data
#[inline(always)]
fn claim<'cs, R, F, P>(&self, _p: &mut Priority<P>, f: F) -> R
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)]
fn claim_mut<'cs, R, F, P>(&mut self, _p: &mut Priority<P>, f: F) -> R
where