From 81275bfa4f41e2066770087f3a33cad4227eab41 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 13 Jun 2019 23:56:59 +0200 Subject: rtfm-syntax refactor + heterogeneous multi-core support --- macros/src/codegen/hardware_tasks.rs | 121 +++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 macros/src/codegen/hardware_tasks.rs (limited to 'macros/src/codegen/hardware_tasks.rs') diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs new file mode 100644 index 0000000..e65bad5 --- /dev/null +++ b/macros/src/codegen/hardware_tasks.rs @@ -0,0 +1,121 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use rtfm_syntax::{ast::App, Context}; + +use crate::{ + analyze::Analysis, + check::Extra, + codegen::{locals, module, resources_struct, util}, +}; + +/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s) +pub fn codegen( + app: &App, + analysis: &Analysis, + extra: &Extra, +) -> ( + // const_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors + Vec, + // root_hardware_tasks -- items that must be placed in the root of the crate: + // - `${task}Locals` structs + // - `${task}Resources` structs + // - `${task}` modules + Vec, + // user_hardware_tasks -- the `#[task]` functions written by the user + Vec, +) { + let mut const_app = vec![]; + let mut root = vec![]; + let mut user_tasks = vec![]; + + for (name, task) in &app.hardware_tasks { + let core = task.args.core; + let cfg_core = util::cfg_core(core, app.args.cores); + + let (let_instant, instant) = if app.uses_schedule(core) { + let m = extra.monotonic(); + + ( + Some(quote!(let instant = <#m as rtfm::Monotonic>::now();)), + Some(quote!(, instant)), + ) + } else { + (None, None) + }; + + let locals_new = if task.locals.is_empty() { + quote!() + } else { + quote!(#name::Locals::new(),) + }; + + let symbol = task.args.binds(name); + let priority = task.args.priority; + + const_app.push(quote!( + #[allow(non_snake_case)] + #[no_mangle] + #cfg_core + unsafe fn #symbol() { + const PRIORITY: u8 = #priority; + + #let_instant + + rtfm::export::run(PRIORITY, || { + crate::#name( + #locals_new + #name::Context::new(&rtfm::export::Priority::new(PRIORITY) #instant) + ) + }); + } + )); + + let mut needs_lt = false; + + // `${task}Resources` + if !task.args.resources.is_empty() { + let (item, constructor) = resources_struct::codegen( + Context::HardwareTask(name), + priority, + &mut needs_lt, + app, + analysis, + ); + + root.push(item); + + const_app.push(constructor); + } + + root.push(module::codegen( + Context::HardwareTask(name), + needs_lt, + app, + extra, + )); + + // `${task}Locals` + let mut locals_pat = None; + if !task.locals.is_empty() { + let (struct_, pat) = locals::codegen(Context::HardwareTask(name), &task.locals, app); + + root.push(struct_); + locals_pat = Some(pat); + } + + let attrs = &task.attrs; + let context = &task.context; + let stmts = &task.stmts; + user_tasks.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + fn #name(#(#locals_pat,)* #context: #name::Context) { + use rtfm::Mutex as _; + + #(#stmts)* + } + )); + } + + (const_app, root, user_tasks) +} -- cgit v1.2.3 From 9897728709528a02545523bea72576abce89dc4c Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 18 Jun 2019 10:31:31 +0200 Subject: add homogeneous multi-core support --- macros/src/codegen/hardware_tasks.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'macros/src/codegen/hardware_tasks.rs') diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index e65bad5..e7f053d 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -49,7 +49,11 @@ pub fn codegen( quote!(#name::Locals::new(),) }; - let symbol = task.args.binds(name); + let symbol = if cfg!(feature = "homogeneous") { + util::suffixed(&task.args.binds(name).to_string(), core) + } else { + task.args.binds(name).clone() + }; let priority = task.args.priority; const_app.push(quote!( -- cgit v1.2.3 From 4e51bb68b976c6bb6a9a989dc560d2a8123a84ca Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 20 Jun 2019 06:19:59 +0200 Subject: RFC #207 --- macros/src/codegen/hardware_tasks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'macros/src/codegen/hardware_tasks.rs') diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index e7f053d..a7af510 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -50,9 +50,9 @@ pub fn codegen( }; let symbol = if cfg!(feature = "homogeneous") { - util::suffixed(&task.args.binds(name).to_string(), core) + util::suffixed(&task.args.binds.to_string(), core) } else { - task.args.binds(name).clone() + task.args.binds.clone() }; let priority = task.args.priority; -- cgit v1.2.3 From be92041a592f65f38cee8475b61d35e7fcee3694 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 29 Jun 2019 09:11:42 +0200 Subject: WIP --- macros/src/codegen/hardware_tasks.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'macros/src/codegen/hardware_tasks.rs') diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index a7af510..cf92e07 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -56,9 +56,11 @@ pub fn codegen( }; let priority = task.args.priority; + let section = util::link_section("text", core); const_app.push(quote!( #[allow(non_snake_case)] #[no_mangle] + #section #cfg_core unsafe fn #symbol() { const PRIORITY: u8 = #priority; @@ -101,7 +103,8 @@ pub fn codegen( // `${task}Locals` let mut locals_pat = None; if !task.locals.is_empty() { - let (struct_, pat) = locals::codegen(Context::HardwareTask(name), &task.locals, app); + let (struct_, pat) = + locals::codegen(Context::HardwareTask(name), &task.locals, core, app); root.push(struct_); locals_pat = Some(pat); @@ -110,9 +113,12 @@ pub fn codegen( let attrs = &task.attrs; let context = &task.context; let stmts = &task.stmts; + let section = util::link_section("text", core); + // XXX shouldn't this have a cfg_core? user_tasks.push(quote!( #(#attrs)* #[allow(non_snake_case)] + #section fn #name(#(#locals_pat,)* #context: #name::Context) { use rtfm::Mutex as _; -- cgit v1.2.3 From 0e146f8d1142672725b6abb38478f503a9261c80 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 20 Aug 2019 15:11:24 +0200 Subject: adapt to changes in rtfm-syntax --- macros/src/codegen/hardware_tasks.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'macros/src/codegen/hardware_tasks.rs') diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index cf92e07..a9c2a2b 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -115,6 +115,7 @@ pub fn codegen( let stmts = &task.stmts; let section = util::link_section("text", core); // XXX shouldn't this have a cfg_core? + let locals_pat = locals_pat.iter(); user_tasks.push(quote!( #(#attrs)* #[allow(non_snake_case)] -- cgit v1.2.3