From 0f8e17361408a704a63995ce9e52fbdeaf34de0b Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 24 Oct 2020 19:38:49 +0200 Subject: [PATCH] extern examples added --- macros/Cargo.toml | 3 ++- macros/src/codegen/hardware_tasks.rs | 26 +++++++++++++----------- macros/src/codegen/software_tasks.rs | 30 +++++++++++++++------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/macros/Cargo.toml b/macros/Cargo.toml index a9f268fbf8..ffa353c5af 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -22,5 +22,6 @@ proc-macro2 = "1" proc-macro-error = "1" quote = "1" syn = "1" -rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.5.0-alpha.0" } +#rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "master", version = "0.5.0-alpha.0" } +rtic-syntax = { git = "https://github.com/rtic-rs/rtic-syntax", branch = "extern_task", version = "0.5.0-alpha.0" } diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index e5a8deb9e8..c9d0297ea1 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -95,19 +95,21 @@ pub fn codegen( locals_pat = Some(pat); } - let attrs = &task.attrs; - let context = &task.context; - let stmts = &task.stmts; - let locals_pat = locals_pat.iter(); - user_tasks.push(quote!( - #(#attrs)* - #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context) { - use rtic::Mutex as _; + if !&task.is_extern { + let attrs = &task.attrs; + let context = &task.context; + let stmts = &task.stmts; + let locals_pat = locals_pat.iter(); + user_tasks.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + fn #name(#(#locals_pat,)* #context: #name::Context) { + use rtic::Mutex as _; - #(#stmts)* - } - )); + #(#stmts)* + } + )); + } } (mod_app, root, user_tasks) diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index dfba193bc8..833e338dd5 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -99,21 +99,23 @@ pub fn codegen( root.push(struct_); } - let context = &task.context; - let attrs = &task.attrs; - let cfgs = &task.cfgs; - let stmts = &task.stmts; - let locals_pat = locals_pat.iter(); - user_tasks.push(quote!( - #(#attrs)* - #(#cfgs)* - #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { - use rtic::Mutex as _; + if !&task.is_extern { + let context = &task.context; + let attrs = &task.attrs; + let cfgs = &task.cfgs; + let stmts = &task.stmts; + let locals_pat = locals_pat.iter(); + user_tasks.push(quote!( + #(#attrs)* + #(#cfgs)* + #[allow(non_snake_case)] + fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { + use rtic::Mutex as _; - #(#stmts)* - } - )); + #(#stmts)* + } + )); + } root.push(module::codegen( Context::SoftwareTask(name),