From 3cebf49a2feb10b6dbf7e40e4671dbf7a3d8bedf Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 6 Jul 2017 23:25:29 -0500 Subject: syntax tweaks, relax check, add set_pending(), deal with imported types - allow trailing commas in list of resources - make task.resources optional - add rtfm::set_pending function which can be used to force an interrupt into the pending state. This is a replacement of the old rtfm::request. rtfm::set_pending takes the Interrupt enum provided by the device crate as argument. (The old rtfm::request took a task function as argument) - the user may want to use types they imported into the root of the crate. These types are not available in e.g. `mod idle` so `idle::Resources` *can't* be defined in that module. To workaround this problem `idle::Resources` will be defined in the root, with some other name, and then be re-exported in the `idle` module. - remove the "a resource only used by one task should be local data" check. In some cases you do want a resource owned by a single task instead of local data since `init` can access resources but not a task local data. --- macros/src/util.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'macros/src/util.rs') diff --git a/macros/src/util.rs b/macros/src/util.rs index 45f1fee..4722ca7 100644 --- a/macros/src/util.rs +++ b/macros/src/util.rs @@ -1,3 +1,4 @@ +use std::cmp; use std::collections::HashMap; use syn::Ident; @@ -8,13 +9,18 @@ pub type Ceilings = HashMap; #[derive(Clone, Copy, Debug, PartialEq)] pub enum Ceiling { - Owned, + // Owned by one or more tasks that have the same priority + Owned(u8), + // Shared by tasks with different priorities Shared(u8), } impl Ceiling { pub fn is_owned(&self) -> bool { - *self == Ceiling::Owned + match *self { + Ceiling::Owned(_) => true, + _ => false, + } } } @@ -22,14 +28,22 @@ pub fn compute_ceilings(app: &App) -> Ceilings { let mut ceilings = HashMap::new(); for resource in &app.idle.resources { - ceilings.insert(resource.clone(), Ceiling::Owned); + ceilings.insert(resource.clone(), Ceiling::Owned(0)); } for task in app.tasks.values() { for resource in &task.resources { if let Some(ceiling) = ceilings.get_mut(resource) { match *ceiling { - Ceiling::Owned => *ceiling = Ceiling::Shared(task.priority), + Ceiling::Owned(current) => { + if current == task.priority { + *ceiling = Ceiling::Owned(current); + } else { + *ceiling = Ceiling::Shared( + cmp::max(current, task.priority), + ); + } + } Ceiling::Shared(old) => { if task.priority > old { *ceiling = Ceiling::Shared(task.priority); @@ -40,7 +54,7 @@ pub fn compute_ceilings(app: &App) -> Ceilings { continue; } - ceilings.insert(resource.clone(), Ceiling::Owned); + ceilings.insert(resource.clone(), Ceiling::Owned(task.priority)); } } -- cgit v1.2.3