From 7a57f1686063fec31d9a04678bd997ab57c91b7b Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Thu, 15 Oct 2020 17:45:34 +0200 Subject: [PATCH 1/7] Made relation between priority and number explicit When quickly reading through the priorities chapter, I couldn't find in which order the priorities were, so I assumed it was the same as in the hardware. In the cortex-m hardware, interrupts with the **lower** priority number will preempt the other interrupts. RTIC does the reverse, so I think it's good to be more explicit about it. --- book/en/src/by-example/app.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md index c4f18c7ad6..2c70af0e09 100644 --- a/book/en/src/by-example/app.md +++ b/book/en/src/by-example/app.md @@ -119,10 +119,13 @@ The static priority of each handler can be declared in the `task` attribute using the `priority` argument. Tasks can have priorities in the range `1..=(1 << NVIC_PRIO_BITS)` where `NVIC_PRIO_BITS` is a constant defined in the `device` crate. When the `priority` argument is omitted, the priority is assumed to be -`1`. The `idle` task has a non-configurable static priority of `0`, the lowest -priority. +`1`. The `idle` task has a non-configurable static priority of `0`, the lowest priority. -When several tasks are ready to be executed the one with *highest* static +> A higher number means a higher priority in RTIC, which is the opposite from what +> Cortex-M does in the NVIC peripheral. +> Explicitly, this means that number `10` has a **higher** priority than number `9`. + +When several tasks are ready to be executed the one with highest static priority will be executed first. Task prioritization can be observed in the following scenario: an interrupt signal arrives during the execution of a low priority task; the signal puts the higher priority task in the pending state. From 6eafcf10e944fb5875c086631dde7fad6f0a7b3b Mon Sep 17 00:00:00 2001 From: Per Date: Wed, 4 Mar 2020 15:06:03 +0100 Subject: [PATCH 2/7] task_local and lock_free analysis (take 1) --- examples/local.rs | 79 ++++++++++++++++ examples/local_err.rs | 82 +++++++++++++++++ examples/local_minimal.rs | 30 +++++++ examples/static.rs | 54 +++++++++++ macros/Cargo.toml | 7 +- macros/src/custom_local.rs | 178 +++++++++++++++++++++++++++++++++++++ macros/src/lib.rs | 15 ++++ 7 files changed, 444 insertions(+), 1 deletion(-) create mode 100644 examples/local.rs create mode 100644 examples/local_err.rs create mode 100644 examples/local_minimal.rs create mode 100644 examples/static.rs create mode 100644 macros/src/custom_local.rs diff --git a/examples/local.rs b/examples/local.rs new file mode 100644 index 0000000000..802ab20f50 --- /dev/null +++ b/examples/local.rs @@ -0,0 +1,79 @@ +//! examples/local.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + struct Resources { + // An early resource + #[init(0)] + shared: u32, + + // A local (move), early resource + #[task_local] + #[init(1)] + l1: u32, + + // An exclusive, early resource + #[lock_free] + #[init(1)] + e1: u32, + + // A local (move), late resource + #[task_local] + l2: u32, + + // An exclusive, late resource + #[lock_free] + e2: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + rtfm::pend(Interrupt::UART0); + rtfm::pend(Interrupt::UART1); + init::LateResources { e2: 2, l2: 2 } + } + + // `shared` cannot be accessed from this context + // l1 ok (task_local) + // e2 ok (lock_free) + #[idle(resources =[l1, e2])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap(); + hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop {} + } + + // `shared` can be accessed from this context + // l2 ok (task_local) + // e1 ok (lock_free) + #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])] + fn uart0(cx: uart0::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + *cx.resources.e1 += 10; + hprintln!("UART0: shared = {}", shared).unwrap(); + hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap(); + hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap(); + } + + // `shared` can be accessed from this context + // e1 ok (lock_free) + #[task(priority = 1, binds = UART1, resources = [shared, e1])] + fn uart1(cx: uart1::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + + hprintln!("UART1: shared = {}", shared).unwrap(); + hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); + } +}; diff --git a/examples/local_err.rs b/examples/local_err.rs new file mode 100644 index 0000000000..3be593a842 --- /dev/null +++ b/examples/local_err.rs @@ -0,0 +1,82 @@ +//! examples/local_err.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +// errors here, since we cannot bail compilation or generate stubs +// run cargo expand, then you see the root of the problem... +use cortex_m_semihosting::{debug, hprintln}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + struct Resources { + // An early resource + #[init(0)] + shared: u32, + + // A local (move), early resource + #[task_local] + #[init(1)] + l1: u32, + + // An exclusive, early resource + #[lock_free] + #[init(1)] + e1: u32, + + // A local (move), late resource + #[task_local] + l2: u32, + + // An exclusive, late resource + #[lock_free] + e2: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + rtfm::pend(Interrupt::UART0); + rtfm::pend(Interrupt::UART1); + init::LateResources { e2: 2, l2: 2 } + } + + // `shared` cannot be accessed from this context + // l1 ok + // l2 rejeceted (not task_local) + // e2 ok + #[idle(resources =[l1, l2, e2])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap(); + hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop {} + } + + // `shared` can be accessed from this context + // l2 rejected (not task_local) + // e1 rejected (not lock_free) + #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])] + fn uart0(cx: uart0::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + *cx.resources.e1 += 10; + hprintln!("UART0: shared = {}", shared).unwrap(); + hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap(); + hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap(); + } + + // l2 rejected (not task_local) + #[task(priority = 2, binds = UART1, resources = [shared, l2, e1])] + fn uart1(cx: uart1::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + + hprintln!("UART1: shared = {}", shared).unwrap(); + hprintln!("UART1:l2 = {}", cx.resources.l2).unwrap(); + hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); + } +}; diff --git a/examples/local_minimal.rs b/examples/local_minimal.rs new file mode 100644 index 0000000000..13531c5ecb --- /dev/null +++ b/examples/local_minimal.rs @@ -0,0 +1,30 @@ +//! examples/local_minimal.rs +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + struct Resources { + // A local (move), late resource + #[task_local] + l: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + init::LateResources { l: 42 } + } + + // l is task_local + #[idle(resources =[l])] + fn idle(cx: idle::Context) -> ! { + hprintln!("IDLE:l = {}", cx.resources.l).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop {} + } +}; diff --git a/examples/static.rs b/examples/static.rs new file mode 100644 index 0000000000..ddcb11e66c --- /dev/null +++ b/examples/static.rs @@ -0,0 +1,54 @@ +//! examples/late.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use heapless::{ + consts::*, + i, + spsc::{Consumer, Producer, Queue}, +}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + // Late resources + struct Resources { + p: Producer<'static, u32, U4>, + c: Consumer<'static, u32, U4>, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + static mut Q: Queue = Queue(i::Queue::new()); + + let (p, c) = Q.split(); + + // Initialization of late resources + init::LateResources { p, c } + } + + #[idle(resources = [c])] + fn idle(c: idle::Context) -> ! { + loop { + if let Some(byte) = c.resources.c.dequeue() { + hprintln!("received message: {}", byte).unwrap(); + + debug::exit(debug::EXIT_SUCCESS); + } else { + rtfm::pend(Interrupt::UART0); + } + } + } + + #[task(binds = UART0, resources = [p])] + fn uart0(c: uart0::Context) { + static mut KALLE: u32 = 0; + *KALLE += 1; + c.resources.p.enqueue(42).unwrap(); + } +}; diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 610890bbfb..74f54433b2 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -21,5 +21,10 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = "1" -rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" } +#rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" } + +[dependencies.rtic-syntax] +git = "https://github.com/rtic-rs/rtic-syntax.git" +branch = "task_local_experiment" +version = "0.4.1" diff --git a/macros/src/custom_local.rs b/macros/src/custom_local.rs new file mode 100644 index 0000000000..338179052a --- /dev/null +++ b/macros/src/custom_local.rs @@ -0,0 +1,178 @@ +use syn::parse; +//use syn::Ident; +//use proc_macro2::{Ident, Span}; +use proc_macro2::Ident; +use rtfm_syntax::{ + analyze::{Analysis, Ownership}, + ast::App, +}; +use syn::Error; +// ast::{App, CustomArg}, + +type Idents<'a> = Vec<&'a Ident>; + +// Assign an `extern` interrupt to each priority level +pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<()> { + // collect task local resources + let task_local: Idents = app + .resources + .iter() + .filter(|(_, r)| r.properties.task_local) + .map(|(i, _)| i) + .chain( + app.late_resources + .iter() + .filter(|(_, r)| r.properties.task_local) + .map(|(i, _)| i), + ) + .collect(); + + let lock_free: Idents = app + .resources + .iter() + .filter(|(_, r)| r.properties.lock_free) + .map(|(i, _)| i) + .chain( + app.late_resources + .iter() + .filter(|(_, r)| r.properties.lock_free) + .map(|(i, _)| i), + ) + .collect(); + + // collect all tasks into a vector + type Task = String; + + let all_tasks: Vec<(Task, Idents)> = app + .idles + .iter() + .map(|(core, ht)| { + ( + format!("Idle (core {})", core), + ht.args.resources.iter().map(|(v, _)| v).collect::>(), + ) + }) + .chain(app.software_tasks.iter().map(|(name, ht)| { + ( + name.to_string(), + ht.args.resources.iter().map(|(v, _)| v).collect::>(), + ) + })) + .chain(app.hardware_tasks.iter().map(|(name, ht)| { + ( + name.to_string(), + ht.args.resources.iter().map(|(v, _)| v).collect::>(), + ) + })) + .collect(); + + // check that task_local resources is only used once + let mut error = vec![]; + for task_local_id in task_local.iter() { + let mut used = vec![]; + for (task, tr) in all_tasks.iter() { + for r in tr { + if task_local_id == r { + used.push((task, r)); + } + } + } + if used.len() > 1 { + error.push(Error::new( + task_local_id.span(), + format!( + "task local resource {:?} is used by multiple tasks", + task_local_id.to_string() + ), + )); + + used.iter().for_each(|(task, resource)| { + error.push(Error::new( + resource.span(), + format!( + "task local resource {:?} is used by task {:?}", + resource.to_string(), + task + ), + )) + }); + } + } + + // filter out contended resources + let contended: Vec<(&Ident, &Ownership)> = _analysis + .ownerships + .iter() + .filter(|(_id, own)| match own { + Ownership::Contended { .. } => true, + _ => false, + }) + .collect(); + + // filter out lock_free contended resources + let lock_free_violation: Vec<&(&Ident, &Ownership)> = contended + .iter() + .filter(|(cont_id, _)| lock_free.iter().any(|lf_id| cont_id == lf_id)) + .collect(); + + // report contention error + lock_free_violation.iter().for_each(|(lf_err_id, _)| { + error.push(Error::new( + lf_err_id.span(), + format!( + "lock_free resource {:?} is contended by higher priority task", + lf_err_id.to_string() + ), + )) + }); + + // collect errors + if error.is_empty() { + Ok(()) + } else { + let mut err = error.iter().next().unwrap().clone(); + error.iter().for_each(|e| err.combine(e.clone())); + Err(err) + } + + // for tl in task_local { + // println!("tl {:?}", tl); + // // let mut first_use = None; + // for i in _analysis.ownerships.iter() { + // println!("\nown: {:?}", i); + // } + + // // println!("analysis {:?}", _analysis.locations); + + // for i in _analysis.locations.iter() { + // println!("\nloc: {:?}", i); + // } + + // ErrorMessage { + // // Span is implemented as an index into a thread-local interner to keep the + // // size small. It is not safe to access from a different thread. We want + // // errors to be Send and Sync to play nicely with the Failure crate, so pin + // // the span we're given to its original thread and assume it is + // // Span::call_site if accessed from any other thread. + // start_span: ThreadBound, + // end_span: ThreadBound, + // message: String, + // } + // (app.name, "here"); + // let span = app.name.span(); + // let start = span.start(); + // Err(vec![ErrorMessage { start_span: app.name.}]); + + // let mut task_locals = Vec::new(); + // println!("-- app:late_resources"); + + // println!( + // "task_locals {:?}", + // app.late_resources.filter(|r| r.task_local) + // ); + + // println!("-- resources"); + // for i in app.resources.iter() { + // println!("res: {:?}", i); + // } +} diff --git a/macros/src/lib.rs b/macros/src/lib.rs index e659559e9b..2c81ede06d 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -10,6 +10,7 @@ use rtic_syntax::Settings; mod analyze; mod check; mod codegen; +mod custom_local; #[cfg(test)] mod tests; @@ -214,13 +215,27 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { Ok(x) => x, }; + match custom_local::app(&app, &analysis) { + Err(e) => return e.to_compile_error().into(), + Ok(_) => {} + } + let extra = match check::app(&app, &analysis) { Err(e) => return e.to_compile_error().into(), Ok(x) => x, }; + // println!("extra {:?}", extra); + let analysis = analyze::app(analysis, &app); + // println!("after analysis, extra {:?}", extra); + + // match custom_local::app(&app, &analysis) { + // Err(e) => return e.to_compile_error().into(), + // Ok(_) => {} + // } + let ts = codegen::app(&app, &analysis, &extra); // Try to write the expanded code to disk From d4439fe73be1467e8881f7d11941b2768c37fc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 7 Mar 2020 23:39:20 +0100 Subject: [PATCH 3/7] Print module name and priority --- macros/src/custom_local.rs | 135 +++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 74 deletions(-) diff --git a/macros/src/custom_local.rs b/macros/src/custom_local.rs index 338179052a..f220c3d8e2 100644 --- a/macros/src/custom_local.rs +++ b/macros/src/custom_local.rs @@ -1,13 +1,11 @@ use syn::parse; -//use syn::Ident; -//use proc_macro2::{Ident, Span}; +use std::collections::HashMap; use proc_macro2::Ident; use rtfm_syntax::{ - analyze::{Analysis, Ownership}, + analyze::Analysis, ast::App, }; use syn::Error; -// ast::{App, CustomArg}, type Idents<'a> = Vec<&'a Ident>; @@ -42,26 +40,31 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<()> { // collect all tasks into a vector type Task = String; + type Priority = u8; - let all_tasks: Vec<(Task, Idents)> = app + let all_tasks: Vec<(Task, Idents, Priority)> = app .idles .iter() .map(|(core, ht)| { ( format!("Idle (core {})", core), ht.args.resources.iter().map(|(v, _)| v).collect::>(), + 0 + ) }) .chain(app.software_tasks.iter().map(|(name, ht)| { ( name.to_string(), ht.args.resources.iter().map(|(v, _)| v).collect::>(), + ht.args.priority ) })) .chain(app.hardware_tasks.iter().map(|(name, ht)| { ( name.to_string(), ht.args.resources.iter().map(|(v, _)| v).collect::>(), + ht.args.priority ) })) .collect(); @@ -70,10 +73,10 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<()> { let mut error = vec![]; for task_local_id in task_local.iter() { let mut used = vec![]; - for (task, tr) in all_tasks.iter() { + for (task, tr, priority) in all_tasks.iter() { for r in tr { if task_local_id == r { - used.push((task, r)); + used.push((task, r, priority)); } } } @@ -86,46 +89,71 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<()> { ), )); - used.iter().for_each(|(task, resource)| { + used.iter().for_each(|(task, resource, priority)| { error.push(Error::new( resource.span(), format!( - "task local resource {:?} is used by task {:?}", + "task local resource {:?} is used by task {:?} with priority {:?}", resource.to_string(), - task + task, + priority ), )) }); } } - // filter out contended resources - let contended: Vec<(&Ident, &Ownership)> = _analysis - .ownerships - .iter() - .filter(|(_id, own)| match own { - Ownership::Contended { .. } => true, - _ => false, - }) - .collect(); + let mut lf_res_with_error = vec![]; + let mut lf_hash = HashMap::new(); - // filter out lock_free contended resources - let lock_free_violation: Vec<&(&Ident, &Ownership)> = contended - .iter() - .filter(|(cont_id, _)| lock_free.iter().any(|lf_id| cont_id == lf_id)) - .collect(); + for lf_res in lock_free.iter() { + for (task, tr, priority) in all_tasks.iter() { + for r in tr { + // Get all uses of resources annotated lock_free + if lf_res == r { + // HashMap returns the previous existing object if old.key == new.key + if let Some(lf_res) = lf_hash.insert(r.to_string(), (task, r, priority)) { + // Check if priority differ, if it does, append to + // list of resources which will be annotated with errors + if priority != lf_res.2 { + lf_res_with_error.push(lf_res.1); + lf_res_with_error.push(r); + } + // If the resource already violates lock free properties + if lf_res_with_error.contains(&r) { + lf_res_with_error.push(lf_res.1); + lf_res_with_error.push(r); + } + } + } + } + } + } - // report contention error - lock_free_violation.iter().for_each(|(lf_err_id, _)| { + // Add error message in the resource struct + for r in lock_free { + if lf_res_with_error.contains(&&r) { + error.push(Error::new( + r.span(), + format!( + "Lock free resource {:?} is used by tasks at different priorities", + r.to_string(), + ), + )); + } + } + + // Add error message for each use of the resource + for resource in lf_res_with_error.clone() { error.push(Error::new( - lf_err_id.span(), + resource.span(), format!( - "lock_free resource {:?} is contended by higher priority task", - lf_err_id.to_string() + "Resource {:?} is declared lock free but used by tasks at different priorities", + resource.to_string(), ), - )) - }); - + )); + } + // collect errors if error.is_empty() { Ok(()) @@ -134,45 +162,4 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<()> { error.iter().for_each(|e| err.combine(e.clone())); Err(err) } - - // for tl in task_local { - // println!("tl {:?}", tl); - // // let mut first_use = None; - // for i in _analysis.ownerships.iter() { - // println!("\nown: {:?}", i); - // } - - // // println!("analysis {:?}", _analysis.locations); - - // for i in _analysis.locations.iter() { - // println!("\nloc: {:?}", i); - // } - - // ErrorMessage { - // // Span is implemented as an index into a thread-local interner to keep the - // // size small. It is not safe to access from a different thread. We want - // // errors to be Send and Sync to play nicely with the Failure crate, so pin - // // the span we're given to its original thread and assume it is - // // Span::call_site if accessed from any other thread. - // start_span: ThreadBound, - // end_span: ThreadBound, - // message: String, - // } - // (app.name, "here"); - // let span = app.name.span(); - // let start = span.start(); - // Err(vec![ErrorMessage { start_span: app.name.}]); - - // let mut task_locals = Vec::new(); - // println!("-- app:late_resources"); - - // println!( - // "task_locals {:?}", - // app.late_resources.filter(|r| r.task_local) - // ); - - // println!("-- resources"); - // for i in app.resources.iter() { - // println!("res: {:?}", i); - // } -} +} \ No newline at end of file From b29a0c134811cdde9ace237493f9dbed58c7d671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 28 Apr 2020 07:32:09 +0000 Subject: [PATCH 4/7] Add example with features on all resources combined with lock_free and task_local --- examples/local-cfg-task-local.rs | 65 ++++++++++++++++ examples/local-cfg.rs | 127 +++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 examples/local-cfg-task-local.rs create mode 100644 examples/local-cfg.rs diff --git a/examples/local-cfg-task-local.rs b/examples/local-cfg-task-local.rs new file mode 100644 index 0000000000..4906911377 --- /dev/null +++ b/examples/local-cfg-task-local.rs @@ -0,0 +1,65 @@ +//! examples/local-cfg-task-local.rs + +#![deny(unsafe_code)] +//#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::hprintln; +use cortex_m_semihosting::debug; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + struct Resources { + // A local (move), early resource + #[cfg(feature = "feature_l1")] + #[task_local] + #[init(1)] + l1: u32, + + // A local (move), late resource + #[task_local] + l2: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + rtfm::pend(Interrupt::UART0); + rtfm::pend(Interrupt::UART1); + init::LateResources { + #[cfg(feature = "feature_l2")] + l2: 2, + #[cfg(not(feature = "feature_l2"))] + l2: 5 + } + } + + // l1 ok (task_local) + #[idle(resources =[#[cfg(feature = "feature_l1")]l1])] + fn idle(_cx: idle::Context) -> ! { + #[cfg(feature = "feature_l1")] + hprintln!("IDLE:l1 = {}", _cx.resources.l1).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop {} + } + + // l2 ok (task_local) + #[task(priority = 1, binds = UART0, resources = [ + #[cfg(feature = "feature_l2")]l2, + ])] + fn uart0(_cx: uart0::Context) { + #[cfg(feature = "feature_l2")] + hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); + } + + // l2 error, conflicting with uart0 for l2 (task_local) + #[task(priority = 1, binds = UART1, resources = [ + #[cfg(not(feature = "feature_l2"))]l2 + ])] + fn uart1(_cx: uart1::Context) { + #[cfg(not(feature = "feature_l2"))] + hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); + } +}; diff --git a/examples/local-cfg.rs b/examples/local-cfg.rs new file mode 100644 index 0000000000..b91655087c --- /dev/null +++ b/examples/local-cfg.rs @@ -0,0 +1,127 @@ +//! examples/local.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +#[cfg( + any( + feature = "feature_s", + feature = "feature_e1", + feature = "feature_e2", + feature = "feature_l1", + feature = "feature_l2" + ) + ) +] +use cortex_m_semihosting::hprintln; +use cortex_m_semihosting::debug; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + struct Resources { + // An early resource + #[cfg(feature = "feature_s")] + #[init(0)] + shared: u32, + + // A local (move), early resource + #[cfg(feature = "feature_l1")] + #[task_local] + #[init(1)] + l1: u32, + + // An exclusive, early resource + #[cfg(feature = "feature_e1")] + #[lock_free] + #[init(1)] + e1: u32, + + // A local (move), late resource + #[task_local] + #[cfg(feature = "feature_l2")] + l2: u32, + + // An exclusive, late resource + #[cfg(feature = "feature_e2")] + #[lock_free] + e2: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + rtfm::pend(Interrupt::UART0); + rtfm::pend(Interrupt::UART1); + init::LateResources { + #[cfg(feature = "feature_e2")] + e2: 2, + #[cfg(feature = "feature_l2")] + l2: 2 + } + } + + // `shared` cannot be accessed from this context + // l1 ok (task_local) + // e2 ok (lock_free) + #[idle(resources =[#[cfg(feature = "feature_l1")]l1, e2])] + fn idle(_cx: idle::Context) -> ! { + #[cfg(feature = "feature_l1")] + hprintln!("IDLE:l1 = {}", _cx.resources.l1).unwrap(); + #[cfg(feature = "feature_e2")] + hprintln!("IDLE:e2 = {}", _cx.resources.e2).unwrap(); + debug::exit(debug::EXIT_SUCCESS); + loop {} + } + + // `shared` can be accessed from this context + // l2 ok (task_local) + // e1 ok (lock_free) + #[task(priority = 1, binds = UART0, resources = [shared, #[cfg(feature = "feature_l2")]l2, #[cfg(feature = "feature_e1")]e1])] + fn uart0(_cx: uart0::Context) { + #[cfg(feature = "feature_s")] + let shared: &mut u32 = _cx.resources.shared; + + #[cfg(feature = "feature_s")] + { + *shared += 1; + } + + #[cfg(feature = "feature_e1")] + { + // Unless put in a closure, the following error: + // error[E0658]: attributes on expressions are experimental + // --> examples/local-cfg.rs:69:9 + // 69 | #[cfg(feature = "feature_x")] + // | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // = note: see issue #15701 + // for more information + *_cx.resources.e1 += 10; + } + #[cfg(feature = "feature_s")] + hprintln!("UART0: shared = {}", shared).unwrap(); + #[cfg(feature = "feature_l2")] + hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); + #[cfg(feature = "feature_e1")] + hprintln!("UART0:e1 = {}", _cx.resources.e1).unwrap(); + } + + // `shared` can be accessed from this context + // e1 ok (lock_free) + #[task(priority = 1, binds = UART1, resources = [#[cfg(feature = "feature_s")]shared, #[cfg(feature = "feature_e1")]e1])] + fn uart1(_cx: uart1::Context) { + #[cfg(feature = "feature_s")] + let shared: &mut u32 = _cx.resources.shared; + #[cfg(feature = "feature_s")] + { + *shared += 1; + } + + #[cfg(feature = "feature_s")] + hprintln!("UART1: shared = {}", shared).unwrap(); + #[cfg(feature = "feature_e1")] + hprintln!("UART1:e1 = {}", _cx.resources.e1).unwrap(); + } +}; From e2364aae3eebf3326534bd4818d0312a03817538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Tue, 8 Sep 2020 17:51:10 +0000 Subject: [PATCH 5/7] Updated examples and rtic-name --- examples/local-cfg.rs | 127 -------------- examples/static.rs | 15 +- ...local_minimal.rs => task-local-minimal.rs} | 13 +- examples/{local.rs => task-local.rs} | 17 +- macros/Cargo.toml | 8 +- macros/src/custom_local.rs | 165 ------------------ macros/src/lib.rs | 15 -- .../single/local-cfg-task-local-err.rs | 15 +- ui/single/local-cfg-task-local-err.stderr | 37 ++++ .../local_err.rs => ui/single/local-err.rs | 11 +- ui/single/local-err.stderr | 60 +++++++ 11 files changed, 141 insertions(+), 342 deletions(-) delete mode 100644 examples/local-cfg.rs rename examples/{local_minimal.rs => task-local-minimal.rs} (78%) rename examples/{local.rs => task-local.rs} (89%) delete mode 100644 macros/src/custom_local.rs rename examples/local-cfg-task-local.rs => ui/single/local-cfg-task-local-err.rs (91%) create mode 100644 ui/single/local-cfg-task-local-err.stderr rename examples/local_err.rs => ui/single/local-err.rs (94%) create mode 100644 ui/single/local-err.stderr diff --git a/examples/local-cfg.rs b/examples/local-cfg.rs deleted file mode 100644 index b91655087c..0000000000 --- a/examples/local-cfg.rs +++ /dev/null @@ -1,127 +0,0 @@ -//! examples/local.rs - -#![deny(unsafe_code)] -#![deny(warnings)] -#![no_main] -#![no_std] - -#[cfg( - any( - feature = "feature_s", - feature = "feature_e1", - feature = "feature_e2", - feature = "feature_l1", - feature = "feature_l2" - ) - ) -] -use cortex_m_semihosting::hprintln; -use cortex_m_semihosting::debug; -use lm3s6965::Interrupt; -use panic_semihosting as _; - -#[rtfm::app(device = lm3s6965)] -const APP: () = { - struct Resources { - // An early resource - #[cfg(feature = "feature_s")] - #[init(0)] - shared: u32, - - // A local (move), early resource - #[cfg(feature = "feature_l1")] - #[task_local] - #[init(1)] - l1: u32, - - // An exclusive, early resource - #[cfg(feature = "feature_e1")] - #[lock_free] - #[init(1)] - e1: u32, - - // A local (move), late resource - #[task_local] - #[cfg(feature = "feature_l2")] - l2: u32, - - // An exclusive, late resource - #[cfg(feature = "feature_e2")] - #[lock_free] - e2: u32, - } - - #[init] - fn init(_: init::Context) -> init::LateResources { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); - init::LateResources { - #[cfg(feature = "feature_e2")] - e2: 2, - #[cfg(feature = "feature_l2")] - l2: 2 - } - } - - // `shared` cannot be accessed from this context - // l1 ok (task_local) - // e2 ok (lock_free) - #[idle(resources =[#[cfg(feature = "feature_l1")]l1, e2])] - fn idle(_cx: idle::Context) -> ! { - #[cfg(feature = "feature_l1")] - hprintln!("IDLE:l1 = {}", _cx.resources.l1).unwrap(); - #[cfg(feature = "feature_e2")] - hprintln!("IDLE:e2 = {}", _cx.resources.e2).unwrap(); - debug::exit(debug::EXIT_SUCCESS); - loop {} - } - - // `shared` can be accessed from this context - // l2 ok (task_local) - // e1 ok (lock_free) - #[task(priority = 1, binds = UART0, resources = [shared, #[cfg(feature = "feature_l2")]l2, #[cfg(feature = "feature_e1")]e1])] - fn uart0(_cx: uart0::Context) { - #[cfg(feature = "feature_s")] - let shared: &mut u32 = _cx.resources.shared; - - #[cfg(feature = "feature_s")] - { - *shared += 1; - } - - #[cfg(feature = "feature_e1")] - { - // Unless put in a closure, the following error: - // error[E0658]: attributes on expressions are experimental - // --> examples/local-cfg.rs:69:9 - // 69 | #[cfg(feature = "feature_x")] - // | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - // = note: see issue #15701 - // for more information - *_cx.resources.e1 += 10; - } - #[cfg(feature = "feature_s")] - hprintln!("UART0: shared = {}", shared).unwrap(); - #[cfg(feature = "feature_l2")] - hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); - #[cfg(feature = "feature_e1")] - hprintln!("UART0:e1 = {}", _cx.resources.e1).unwrap(); - } - - // `shared` can be accessed from this context - // e1 ok (lock_free) - #[task(priority = 1, binds = UART1, resources = [#[cfg(feature = "feature_s")]shared, #[cfg(feature = "feature_e1")]e1])] - fn uart1(_cx: uart1::Context) { - #[cfg(feature = "feature_s")] - let shared: &mut u32 = _cx.resources.shared; - #[cfg(feature = "feature_s")] - { - *shared += 1; - } - - #[cfg(feature = "feature_s")] - hprintln!("UART1: shared = {}", shared).unwrap(); - #[cfg(feature = "feature_e1")] - hprintln!("UART1:e1 = {}", _cx.resources.e1).unwrap(); - } -}; diff --git a/examples/static.rs b/examples/static.rs index ddcb11e66c..9c3110c035 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -1,4 +1,4 @@ -//! examples/late.rs +//! examples/static.rs #![deny(unsafe_code)] #![deny(warnings)] @@ -14,9 +14,14 @@ use heapless::{ use lm3s6965::Interrupt; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + + use crate::U4; + use crate::{Consumer, Producer}; + // Late resources + #[resources] struct Resources { p: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, @@ -40,7 +45,7 @@ const APP: () = { debug::exit(debug::EXIT_SUCCESS); } else { - rtfm::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART0); } } } @@ -51,4 +56,4 @@ const APP: () = { *KALLE += 1; c.resources.p.enqueue(42).unwrap(); } -}; +} diff --git a/examples/local_minimal.rs b/examples/task-local-minimal.rs similarity index 78% rename from examples/local_minimal.rs rename to examples/task-local-minimal.rs index 13531c5ecb..fd5ac68a29 100644 --- a/examples/local_minimal.rs +++ b/examples/task-local-minimal.rs @@ -1,4 +1,4 @@ -//! examples/local_minimal.rs +//! examples/task-local_minimal.rs #![deny(unsafe_code)] #![deny(warnings)] #![no_main] @@ -7,8 +7,9 @@ use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] struct Resources { // A local (move), late resource #[task_local] @@ -25,6 +26,8 @@ const APP: () = { fn idle(cx: idle::Context) -> ! { hprintln!("IDLE:l = {}", cx.resources.l).unwrap(); debug::exit(debug::EXIT_SUCCESS); - loop {} + loop { + cortex_m::asm::nop(); + } } -}; +} diff --git a/examples/local.rs b/examples/task-local.rs similarity index 89% rename from examples/local.rs rename to examples/task-local.rs index 802ab20f50..8f0dfc792a 100644 --- a/examples/local.rs +++ b/examples/task-local.rs @@ -1,4 +1,4 @@ -//! examples/local.rs +//! examples/task-local.rs #![deny(unsafe_code)] #![deny(warnings)] @@ -9,8 +9,9 @@ use cortex_m_semihosting::{debug, hprintln}; use lm3s6965::Interrupt; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] struct Resources { // An early resource #[init(0)] @@ -37,8 +38,8 @@ const APP: () = { #[init] fn init(_: init::Context) -> init::LateResources { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); init::LateResources { e2: 2, l2: 2 } } @@ -50,7 +51,9 @@ const APP: () = { hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap(); hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap(); debug::exit(debug::EXIT_SUCCESS); - loop {} + loop { + cortex_m::asm::nop(); + } } // `shared` can be accessed from this context @@ -76,4 +79,4 @@ const APP: () = { hprintln!("UART1: shared = {}", shared).unwrap(); hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); } -}; +} diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 74f54433b2..4fac48fe41 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -21,10 +21,6 @@ proc-macro = true proc-macro2 = "1" quote = "1" syn = "1" -#rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.4.0" } - -[dependencies.rtic-syntax] -git = "https://github.com/rtic-rs/rtic-syntax.git" -branch = "task_local_experiment" -version = "0.4.1" +#rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "task_local_experiment", version = "0.4.1" } +rtic-syntax = { git = "https://github.com/AfoHT/rtic-syntax", branch = "task_local_experiment", version = "0.4.1" } diff --git a/macros/src/custom_local.rs b/macros/src/custom_local.rs deleted file mode 100644 index f220c3d8e2..0000000000 --- a/macros/src/custom_local.rs +++ /dev/null @@ -1,165 +0,0 @@ -use syn::parse; -use std::collections::HashMap; -use proc_macro2::Ident; -use rtfm_syntax::{ - analyze::Analysis, - ast::App, -}; -use syn::Error; - -type Idents<'a> = Vec<&'a Ident>; - -// Assign an `extern` interrupt to each priority level -pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<()> { - // collect task local resources - let task_local: Idents = app - .resources - .iter() - .filter(|(_, r)| r.properties.task_local) - .map(|(i, _)| i) - .chain( - app.late_resources - .iter() - .filter(|(_, r)| r.properties.task_local) - .map(|(i, _)| i), - ) - .collect(); - - let lock_free: Idents = app - .resources - .iter() - .filter(|(_, r)| r.properties.lock_free) - .map(|(i, _)| i) - .chain( - app.late_resources - .iter() - .filter(|(_, r)| r.properties.lock_free) - .map(|(i, _)| i), - ) - .collect(); - - // collect all tasks into a vector - type Task = String; - type Priority = u8; - - let all_tasks: Vec<(Task, Idents, Priority)> = app - .idles - .iter() - .map(|(core, ht)| { - ( - format!("Idle (core {})", core), - ht.args.resources.iter().map(|(v, _)| v).collect::>(), - 0 - - ) - }) - .chain(app.software_tasks.iter().map(|(name, ht)| { - ( - name.to_string(), - ht.args.resources.iter().map(|(v, _)| v).collect::>(), - ht.args.priority - ) - })) - .chain(app.hardware_tasks.iter().map(|(name, ht)| { - ( - name.to_string(), - ht.args.resources.iter().map(|(v, _)| v).collect::>(), - ht.args.priority - ) - })) - .collect(); - - // check that task_local resources is only used once - let mut error = vec![]; - for task_local_id in task_local.iter() { - let mut used = vec![]; - for (task, tr, priority) in all_tasks.iter() { - for r in tr { - if task_local_id == r { - used.push((task, r, priority)); - } - } - } - if used.len() > 1 { - error.push(Error::new( - task_local_id.span(), - format!( - "task local resource {:?} is used by multiple tasks", - task_local_id.to_string() - ), - )); - - used.iter().for_each(|(task, resource, priority)| { - error.push(Error::new( - resource.span(), - format!( - "task local resource {:?} is used by task {:?} with priority {:?}", - resource.to_string(), - task, - priority - ), - )) - }); - } - } - - let mut lf_res_with_error = vec![]; - let mut lf_hash = HashMap::new(); - - for lf_res in lock_free.iter() { - for (task, tr, priority) in all_tasks.iter() { - for r in tr { - // Get all uses of resources annotated lock_free - if lf_res == r { - // HashMap returns the previous existing object if old.key == new.key - if let Some(lf_res) = lf_hash.insert(r.to_string(), (task, r, priority)) { - // Check if priority differ, if it does, append to - // list of resources which will be annotated with errors - if priority != lf_res.2 { - lf_res_with_error.push(lf_res.1); - lf_res_with_error.push(r); - } - // If the resource already violates lock free properties - if lf_res_with_error.contains(&r) { - lf_res_with_error.push(lf_res.1); - lf_res_with_error.push(r); - } - } - } - } - } - } - - // Add error message in the resource struct - for r in lock_free { - if lf_res_with_error.contains(&&r) { - error.push(Error::new( - r.span(), - format!( - "Lock free resource {:?} is used by tasks at different priorities", - r.to_string(), - ), - )); - } - } - - // Add error message for each use of the resource - for resource in lf_res_with_error.clone() { - error.push(Error::new( - resource.span(), - format!( - "Resource {:?} is declared lock free but used by tasks at different priorities", - resource.to_string(), - ), - )); - } - - // collect errors - if error.is_empty() { - Ok(()) - } else { - let mut err = error.iter().next().unwrap().clone(); - error.iter().for_each(|e| err.combine(e.clone())); - Err(err) - } -} \ No newline at end of file diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2c81ede06d..e659559e9b 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -10,7 +10,6 @@ use rtic_syntax::Settings; mod analyze; mod check; mod codegen; -mod custom_local; #[cfg(test)] mod tests; @@ -215,27 +214,13 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { Ok(x) => x, }; - match custom_local::app(&app, &analysis) { - Err(e) => return e.to_compile_error().into(), - Ok(_) => {} - } - let extra = match check::app(&app, &analysis) { Err(e) => return e.to_compile_error().into(), Ok(x) => x, }; - // println!("extra {:?}", extra); - let analysis = analyze::app(analysis, &app); - // println!("after analysis, extra {:?}", extra); - - // match custom_local::app(&app, &analysis) { - // Err(e) => return e.to_compile_error().into(), - // Ok(_) => {} - // } - let ts = codegen::app(&app, &analysis, &extra); // Try to write the expanded code to disk diff --git a/examples/local-cfg-task-local.rs b/ui/single/local-cfg-task-local-err.rs similarity index 91% rename from examples/local-cfg-task-local.rs rename to ui/single/local-cfg-task-local-err.rs index 4906911377..412f614226 100644 --- a/examples/local-cfg-task-local.rs +++ b/ui/single/local-cfg-task-local-err.rs @@ -5,13 +5,14 @@ #![no_main] #![no_std] -use cortex_m_semihosting::hprintln; use cortex_m_semihosting::debug; +use cortex_m_semihosting::hprintln; use lm3s6965::Interrupt; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] struct Resources { // A local (move), early resource #[cfg(feature = "feature_l1")] @@ -26,13 +27,13 @@ const APP: () = { #[init] fn init(_: init::Context) -> init::LateResources { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); init::LateResources { #[cfg(feature = "feature_l2")] l2: 2, #[cfg(not(feature = "feature_l2"))] - l2: 5 + l2: 5, } } @@ -62,4 +63,4 @@ const APP: () = { #[cfg(not(feature = "feature_l2"))] hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap(); } -}; +} diff --git a/ui/single/local-cfg-task-local-err.stderr b/ui/single/local-cfg-task-local-err.stderr new file mode 100644 index 0000000000..9a84ead413 --- /dev/null +++ b/ui/single/local-cfg-task-local-err.stderr @@ -0,0 +1,37 @@ +error: task local resource "l2" is used by multiple tasks + --> $DIR/local-cfg-task-local-err.rs:25:9 + | +25 | l2: u32, + | ^^ + +error: task local resource "l2" is used by task "uart0" with priority 1 + --> $DIR/local-cfg-task-local-err.rs:51:39 + | +51 | #[cfg(feature = "feature_l2")]l2, + | ^^ + +error: task local resource "l2" is used by task "uart1" with priority 1 + --> $DIR/local-cfg-task-local-err.rs:60:44 + | +60 | #[cfg(not(feature = "feature_l2"))]l2 + | ^^ + +warning: unused import: `cortex_m_semihosting::debug` + --> $DIR/local-cfg-task-local-err.rs:8:5 + | +8 | use cortex_m_semihosting::debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +warning: unused import: `cortex_m_semihosting::hprintln` + --> $DIR/local-cfg-task-local-err.rs:9:5 + | +9 | use cortex_m_semihosting::hprintln; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `lm3s6965::Interrupt` + --> $DIR/local-cfg-task-local-err.rs:10:5 + | +10 | use lm3s6965::Interrupt; + | ^^^^^^^^^^^^^^^^^^^ diff --git a/examples/local_err.rs b/ui/single/local-err.rs similarity index 94% rename from examples/local_err.rs rename to ui/single/local-err.rs index 3be593a842..0fe98a4b0c 100644 --- a/examples/local_err.rs +++ b/ui/single/local-err.rs @@ -11,8 +11,9 @@ use cortex_m_semihosting::{debug, hprintln}; use lm3s6965::Interrupt; use panic_semihosting as _; -#[rtfm::app(device = lm3s6965)] -const APP: () = { +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] struct Resources { // An early resource #[init(0)] @@ -39,8 +40,8 @@ const APP: () = { #[init] fn init(_: init::Context) -> init::LateResources { - rtfm::pend(Interrupt::UART0); - rtfm::pend(Interrupt::UART1); + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); init::LateResources { e2: 2, l2: 2 } } @@ -79,4 +80,4 @@ const APP: () = { hprintln!("UART1:l2 = {}", cx.resources.l2).unwrap(); hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap(); } -}; +} diff --git a/ui/single/local-err.stderr b/ui/single/local-err.stderr new file mode 100644 index 0000000000..88369d8e3a --- /dev/null +++ b/ui/single/local-err.stderr @@ -0,0 +1,60 @@ +error: task local resource "l2" is used by multiple tasks + --> $DIR/local-err.rs:34:9 + | +34 | l2: u32, + | ^^ + +error: task local resource "l2" is used by task "idle" with priority 0 + --> $DIR/local-err.rs:52:28 + | +52 | #[idle(resources =[l1, l2, e2])] + | ^^ + +error: task local resource "l2" is used by task "uart0" with priority 1 + --> $DIR/local-err.rs:63:62 + | +63 | #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])] + | ^^ + +error: task local resource "l2" is used by task "uart1" with priority 2 + --> $DIR/local-err.rs:74:62 + | +74 | #[task(priority = 2, binds = UART1, resources = [shared, l2, e1])] + | ^^ + +error: Lock free resource "e1" is used by tasks at different priorities + --> $DIR/local-err.rs:30:9 + | +30 | e1: u32, + | ^^ + +error: Resource "e1" is declared lock free but used by tasks at different priorities + --> $DIR/local-err.rs:63:66 + | +63 | #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])] + | ^^ + +error: Resource "e1" is declared lock free but used by tasks at different priorities + --> $DIR/local-err.rs:74:66 + | +74 | #[task(priority = 2, binds = UART1, resources = [shared, l2, e1])] + | ^^ + +error: unused imports: `debug`, `hprintln` + --> $DIR/local-err.rs:10:28 + | +10 | use cortex_m_semihosting::{debug, hprintln}; + | ^^^^^ ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/local-err.rs:4:9 + | +4 | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]` + +error: unused import: `lm3s6965::Interrupt` + --> $DIR/local-err.rs:11:5 + | +11 | use lm3s6965::Interrupt; + | ^^^^^^^^^^^^^^^^^^^ From 6c1f4a7b5d30502e7d7d66e4a9235c7933cf825d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Thu, 1 Oct 2020 17:15:51 +0000 Subject: [PATCH 6/7] Changed branch for rtic-syntax --- macros/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 4fac48fe41..a9f268fbf8 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -19,8 +19,8 @@ proc-macro = true [dependencies] proc-macro2 = "1" +proc-macro-error = "1" quote = "1" syn = "1" -#rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "task_local_experiment", version = "0.4.1" } -rtic-syntax = { git = "https://github.com/AfoHT/rtic-syntax", branch = "task_local_experiment", version = "0.4.1" } +rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.5.0-alpha.0" } From 37ee3a47afbbbf57751243d6d32aaac78073780c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Wed, 14 Oct 2020 10:15:35 +0000 Subject: [PATCH 7/7] Create Enum containing all tasks --- macros/src/codegen.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index f230d3956d..a44266ad3c 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -126,6 +126,20 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let user_code = app.user_code.clone(); let name = &app.name; let device = extra.device; + + // Get the list of all tasks + // Currently unused, might be useful + let task_list = analysis.tasks.clone(); + + let mut tasks = vec![]; + if !task_list.is_empty() { + tasks.push(quote!( + enum Tasks { + #(#task_list),* + } + )); + } + quote!( #(#user)* @@ -141,6 +155,9 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_software_tasks)* + /// Unused + #(#tasks)* + /// Implementation details mod #name { /// Always include the device crate which contains the vector table