aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/hardware_tasks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/codegen/hardware_tasks.rs')
-rw-r--r--macros/src/codegen/hardware_tasks.rs50
1 files changed, 26 insertions, 24 deletions
diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs
index 453dbcc..25f1df4 100644
--- a/macros/src/codegen/hardware_tasks.rs
+++ b/macros/src/codegen/hardware_tasks.rs
@@ -1,11 +1,11 @@
use proc_macro2::TokenStream as TokenStream2;
-use quote::quote;
+use quote::{format_ident, quote};
use rtic_syntax::{ast::App, Context};
use crate::{
analyze::Analysis,
check::Extra,
- codegen::{locals, module, resources_struct, util},
+ codegen::{locals, module, resources_struct},
};
/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s)
@@ -14,7 +14,7 @@ pub fn codegen(
analysis: &Analysis,
extra: &Extra,
) -> (
- // const_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors
+ // mod_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors
Vec<TokenStream2>,
// root_hardware_tasks -- items that must be placed in the root of the crate:
// - `${task}Locals` structs
@@ -23,16 +23,16 @@ pub fn codegen(
Vec<TokenStream2>,
// user_hardware_tasks -- the `#[task]` functions written by the user
Vec<TokenStream2>,
+ // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user
+ Vec<TokenStream2>,
) {
- let mut const_app = vec![];
+ let mut mod_app = vec![];
let mut root = vec![];
let mut user_tasks = vec![];
+ let mut hardware_tasks_imports = 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 (let_instant, instant) = if app.uses_schedule() {
let m = extra.monotonic();
(
@@ -49,19 +49,12 @@ pub fn codegen(
quote!(#name::Locals::new(),)
};
- let symbol = if cfg!(feature = "homogeneous") {
- util::suffixed(&task.args.binds.to_string(), core)
- } else {
- task.args.binds.clone()
- };
+ let symbol = task.args.binds.clone();
let priority = task.args.priority;
- let section = util::link_section("text", core);
- const_app.push(quote!(
+ mod_app.push(quote!(
#[allow(non_snake_case)]
#[no_mangle]
- #section
- #cfg_core
unsafe fn #symbol() {
const PRIORITY: u8 = #priority;
@@ -88,9 +81,16 @@ pub fn codegen(
analysis,
);
+ // Add resources to imports
+ let name_res = format_ident!("{}Resources", name);
+ hardware_tasks_imports.push(quote!(
+ #[allow(non_snake_case)]
+ use super::#name_res;
+ ));
+
root.push(item);
- const_app.push(constructor);
+ mod_app.push(constructor);
}
root.push(module::codegen(
@@ -103,8 +103,7 @@ 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, core, app);
+ let (struct_, pat) = locals::codegen(Context::HardwareTask(name), &task.locals, app);
root.push(struct_);
locals_pat = Some(pat);
@@ -113,20 +112,23 @@ 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?
let locals_pat = locals_pat.iter();
user_tasks.push(quote!(
#(#attrs)*
#[allow(non_snake_case)]
- #section
fn #name(#(#locals_pat,)* #context: #name::Context) {
use rtic::Mutex as _;
#(#stmts)*
}
));
+
+ hardware_tasks_imports.push(quote!(
+ #(#attrs)*
+ #[allow(non_snake_case)]
+ use super::#name;
+ ));
}
- (const_app, root, user_tasks)
+ (mod_app, root, user_tasks, hardware_tasks_imports)
}