mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-25 03:19:34 +01:00
Handle user hardware and software tasks and some resources
This commit is contained in:
parent
5cfd9b9238
commit
46bf583cc2
4 changed files with 71 additions and 6 deletions
|
@ -89,12 +89,12 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
|||
}
|
||||
));
|
||||
|
||||
let (const_app_resources, mod_resources) = resources::codegen(app, analysis, extra);
|
||||
let (const_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra);
|
||||
|
||||
let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
|
||||
let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports) =
|
||||
hardware_tasks::codegen(app, analysis, extra);
|
||||
|
||||
let (const_app_software_tasks, root_software_tasks, user_software_tasks) =
|
||||
let (const_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports) =
|
||||
software_tasks::codegen(app, analysis, extra);
|
||||
|
||||
let const_app_dispatchers = dispatchers::codegen(app, analysis, extra);
|
||||
|
@ -110,16 +110,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
|||
quote!(
|
||||
#(#user)*
|
||||
|
||||
/// USER_HW_TASKS
|
||||
#(#user_hardware_tasks)*
|
||||
|
||||
/// USER_SW_TASKS
|
||||
#(#user_software_tasks)*
|
||||
|
||||
/// ROOT
|
||||
#(#root)*
|
||||
|
||||
/// MOD_RESOURCES
|
||||
#mod_resources
|
||||
|
||||
/// root_hardware_tasks
|
||||
#(#root_hardware_tasks)*
|
||||
|
||||
/// root_software_tasks
|
||||
#(#root_software_tasks)*
|
||||
|
||||
/// Implementation details
|
||||
|
@ -129,17 +135,33 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
|||
use #device as _;
|
||||
#(#const_app_imports)*
|
||||
|
||||
/// User hardware_tasks
|
||||
#(#user_hardware_tasks_imports)*
|
||||
|
||||
/// User software_tasks
|
||||
#(#user_software_tasks_imports)*
|
||||
|
||||
/// Mod resources imports
|
||||
#(#mod_resources_imports)*
|
||||
|
||||
/// Const app
|
||||
#(#const_app)*
|
||||
|
||||
/// Const app resources
|
||||
#(#const_app_resources)*
|
||||
|
||||
/// Const app hw tasks
|
||||
#(#const_app_hardware_tasks)*
|
||||
|
||||
/// Const app sw tasks
|
||||
#(#const_app_software_tasks)*
|
||||
|
||||
/// Const app dispatchers
|
||||
#(#const_app_dispatchers)*
|
||||
|
||||
/// Const app spawn
|
||||
#(#const_app_spawn)*
|
||||
/// Const app spawn end
|
||||
|
||||
#(#const_app_timer_queue)*
|
||||
|
||||
|
|
|
@ -23,10 +23,13 @@ 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 root = vec![];
|
||||
let mut user_tasks = vec![];
|
||||
let mut hardware_tasks_imports = vec![];
|
||||
|
||||
for (name, task) in &app.hardware_tasks {
|
||||
let (let_instant, instant) = if app.uses_schedule() {
|
||||
|
@ -78,6 +81,13 @@ 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);
|
||||
|
@ -112,7 +122,14 @@ pub fn codegen(
|
|||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
|
||||
hardware_tasks_imports.push(quote!(
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
use super::#name;
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
(const_app, root, user_tasks)
|
||||
(const_app, root, user_tasks, hardware_tasks_imports)
|
||||
}
|
||||
|
|
|
@ -14,9 +14,12 @@ pub fn codegen(
|
|||
Vec<TokenStream2>,
|
||||
// mod_resources -- the `resources` module
|
||||
TokenStream2,
|
||||
// mod_resources_imports -- the `resources` module imports
|
||||
Vec<TokenStream2>,
|
||||
) {
|
||||
let mut const_app = vec![];
|
||||
let mut mod_resources = vec![];
|
||||
let mut mod_resources_imports = vec![];
|
||||
|
||||
for (name, res, expr, _) in app.resources(analysis) {
|
||||
let cfgs = &res.cfgs;
|
||||
|
@ -82,6 +85,13 @@ pub fn codegen(
|
|||
)
|
||||
};
|
||||
|
||||
mod_resources_imports.push(quote!(
|
||||
#[allow(non_camel_case_types)]
|
||||
#(#cfgs)*
|
||||
#cfg_core
|
||||
use super::#name;
|
||||
));
|
||||
|
||||
const_app.push(util::impl_mutex(
|
||||
extra,
|
||||
cfgs,
|
||||
|
@ -104,5 +114,5 @@ pub fn codegen(
|
|||
})
|
||||
};
|
||||
|
||||
(const_app, mod_resources)
|
||||
(const_app, mod_resources, mod_resources_imports)
|
||||
}
|
||||
|
|
|
@ -22,10 +22,13 @@ pub fn codegen(
|
|||
Vec<TokenStream2>,
|
||||
// user_software_tasks -- the `#[task]` functions written by the user
|
||||
Vec<TokenStream2>,
|
||||
// user_software_tasks_imports -- the imports for `#[task]` functions written by the user
|
||||
Vec<TokenStream2>,
|
||||
) {
|
||||
let mut const_app = vec![];
|
||||
let mut root = vec![];
|
||||
let mut user_tasks = vec![];
|
||||
let mut software_tasks_imports = vec![];
|
||||
|
||||
for (name, task) in &app.software_tasks {
|
||||
let inputs = &task.inputs;
|
||||
|
@ -112,6 +115,13 @@ pub fn codegen(
|
|||
analysis,
|
||||
);
|
||||
|
||||
// Add resources to imports
|
||||
let name_res = format_ident!("{}Resources", name);
|
||||
software_tasks_imports.push(quote!(
|
||||
#[allow(non_snake_case)]
|
||||
use super::#name_res;
|
||||
));
|
||||
|
||||
root.push(item);
|
||||
|
||||
const_app.push(constructor);
|
||||
|
@ -141,6 +151,12 @@ pub fn codegen(
|
|||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
software_tasks_imports.push(quote!(
|
||||
#(#attrs)*
|
||||
#(#cfgs)*
|
||||
#[allow(non_snake_case)]
|
||||
use super::#name;
|
||||
));
|
||||
|
||||
root.push(module::codegen(
|
||||
Context::SoftwareTask(name),
|
||||
|
@ -150,5 +166,5 @@ pub fn codegen(
|
|||
));
|
||||
}
|
||||
|
||||
(const_app, root, user_tasks)
|
||||
(const_app, root, user_tasks, software_tasks_imports)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue