mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
Added software task codegen back
This commit is contained in:
parent
f8352122a3
commit
d27d0fe33f
2 changed files with 111 additions and 1 deletions
|
@ -18,7 +18,7 @@ mod post_init;
|
||||||
mod pre_init;
|
mod pre_init;
|
||||||
mod shared_resources;
|
mod shared_resources;
|
||||||
mod shared_resources_struct;
|
mod shared_resources_struct;
|
||||||
// mod software_tasks;
|
mod software_tasks;
|
||||||
// mod timer_queue;
|
// mod timer_queue;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
@ -92,6 +92,9 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||||
let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
|
let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
|
||||||
hardware_tasks::codegen(app, analysis);
|
hardware_tasks::codegen(app, analysis);
|
||||||
|
|
||||||
|
let (mod_app_software_tasks, root_software_tasks, user_software_tasks) =
|
||||||
|
software_tasks::codegen(app, analysis);
|
||||||
|
|
||||||
let mod_app_async_dispatchers = async_dispatchers::codegen(app, analysis);
|
let mod_app_async_dispatchers = async_dispatchers::codegen(app, analysis);
|
||||||
let user_imports = &app.user_imports;
|
let user_imports = &app.user_imports;
|
||||||
let user_code = &app.user_code;
|
let user_code = &app.user_code;
|
||||||
|
@ -116,6 +119,8 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||||
|
|
||||||
#(#user_hardware_tasks)*
|
#(#user_hardware_tasks)*
|
||||||
|
|
||||||
|
#(#user_software_tasks)*
|
||||||
|
|
||||||
#(#root)*
|
#(#root)*
|
||||||
|
|
||||||
#mod_shared_resources
|
#mod_shared_resources
|
||||||
|
@ -124,6 +129,8 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||||
|
|
||||||
#(#root_hardware_tasks)*
|
#(#root_hardware_tasks)*
|
||||||
|
|
||||||
|
#(#root_software_tasks)*
|
||||||
|
|
||||||
/// app module
|
/// app module
|
||||||
#(#mod_app)*
|
#(#mod_app)*
|
||||||
|
|
||||||
|
@ -133,6 +140,8 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream2 {
|
||||||
|
|
||||||
#(#mod_app_hardware_tasks)*
|
#(#mod_app_hardware_tasks)*
|
||||||
|
|
||||||
|
#(#mod_app_software_tasks)*
|
||||||
|
|
||||||
#(#mod_app_async_dispatchers)*
|
#(#mod_app_async_dispatchers)*
|
||||||
|
|
||||||
#(#mains)*
|
#(#mains)*
|
||||||
|
|
101
macros/src/codegen/software_tasks.rs
Normal file
101
macros/src/codegen/software_tasks.rs
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
use crate::syntax::{ast::App, Context};
|
||||||
|
use crate::{
|
||||||
|
analyze::Analysis,
|
||||||
|
codegen::{local_resources_struct, module, shared_resources_struct, util},
|
||||||
|
};
|
||||||
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
|
pub fn codegen(
|
||||||
|
app: &App,
|
||||||
|
analysis: &Analysis,
|
||||||
|
) -> (
|
||||||
|
// mod_app_software_tasks -- free queues, buffers and `${task}Resources` constructors
|
||||||
|
Vec<TokenStream2>,
|
||||||
|
// root_software_tasks -- items that must be placed in the root of the crate:
|
||||||
|
// - `${task}Locals` structs
|
||||||
|
// - `${task}Resources` structs
|
||||||
|
// - `${task}` modules
|
||||||
|
Vec<TokenStream2>,
|
||||||
|
// user_software_tasks -- the `#[task]` functions written by the user
|
||||||
|
Vec<TokenStream2>,
|
||||||
|
) {
|
||||||
|
let mut mod_app = vec![];
|
||||||
|
let mut root = vec![];
|
||||||
|
let mut user_tasks = vec![];
|
||||||
|
|
||||||
|
// Any task
|
||||||
|
for (name, task) in app.software_tasks.iter() {
|
||||||
|
let executor_ident = util::executor_run_ident(name);
|
||||||
|
mod_app.push(quote!(
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
static #executor_ident: core::sync::atomic::AtomicBool =
|
||||||
|
core::sync::atomic::AtomicBool::new(false);
|
||||||
|
));
|
||||||
|
|
||||||
|
// `${task}Resources`
|
||||||
|
let mut shared_needs_lt = false;
|
||||||
|
let mut local_needs_lt = false;
|
||||||
|
|
||||||
|
// `${task}Locals`
|
||||||
|
if !task.args.local_resources.is_empty() {
|
||||||
|
let (item, constructor) = local_resources_struct::codegen(
|
||||||
|
Context::SoftwareTask(name),
|
||||||
|
&mut local_needs_lt,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
|
root.push(item);
|
||||||
|
|
||||||
|
mod_app.push(constructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !task.args.shared_resources.is_empty() {
|
||||||
|
let (item, constructor) = shared_resources_struct::codegen(
|
||||||
|
Context::SoftwareTask(name),
|
||||||
|
&mut shared_needs_lt,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
|
root.push(item);
|
||||||
|
|
||||||
|
mod_app.push(constructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !&task.is_extern {
|
||||||
|
let context = &task.context;
|
||||||
|
let attrs = &task.attrs;
|
||||||
|
let cfgs = &task.cfgs;
|
||||||
|
let stmts = &task.stmts;
|
||||||
|
let context_lifetime = if shared_needs_lt || local_needs_lt {
|
||||||
|
quote!(<'static>)
|
||||||
|
} else {
|
||||||
|
quote!()
|
||||||
|
};
|
||||||
|
|
||||||
|
user_tasks.push(quote!(
|
||||||
|
#(#attrs)*
|
||||||
|
#(#cfgs)*
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
async fn #name(#context: #name::Context #context_lifetime) {
|
||||||
|
use rtic::Mutex as _;
|
||||||
|
use rtic::mutex::prelude::*;
|
||||||
|
|
||||||
|
#(#stmts)*
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
root.push(module::codegen(
|
||||||
|
Context::SoftwareTask(name),
|
||||||
|
shared_needs_lt,
|
||||||
|
local_needs_lt,
|
||||||
|
app,
|
||||||
|
analysis,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
(mod_app, root, user_tasks)
|
||||||
|
}
|
Loading…
Reference in a new issue