mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 13:55:23 +01:00
wip (problem with Pin)
This commit is contained in:
parent
38306389ea
commit
99a45ff28e
8 changed files with 373 additions and 28 deletions
|
|
@ -39,7 +39,8 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
|||
let (const_app_init, root_init, user_init, call_init) =
|
||||
init::codegen(core, app, analysis, extra);
|
||||
|
||||
let (const_app_post_init, post_init_stmts) = post_init::codegen(core, analysis, extra);
|
||||
let (const_app_post_init, post_init_stmts) =
|
||||
post_init::codegen(core, &app, analysis, extra);
|
||||
|
||||
let (const_app_idle, root_idle, user_idle, call_idle) =
|
||||
idle::codegen(core, app, analysis, extra);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ pub fn codegen(
|
|||
let mut user_tasks = vec![];
|
||||
|
||||
for (name, task) in &app.hardware_tasks {
|
||||
// per: debug
|
||||
// println!("// -- name -- {:?}", name);
|
||||
// println!("// -- task -- {:?}", task);
|
||||
let core = task.args.core;
|
||||
let cfg_core = util::cfg_core(core, app.args.cores);
|
||||
|
||||
|
|
@ -57,24 +60,47 @@ 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;
|
||||
if task.is_generator {
|
||||
let gen_static = util::gen_static_ident(&name);
|
||||
let gen_type = util::gen_type_ident(&name);
|
||||
const_app.push(quote!(
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
#section
|
||||
#cfg_core
|
||||
unsafe fn #symbol() {
|
||||
const PRIORITY: u8 = #priority;
|
||||
|
||||
#let_instant
|
||||
#let_instant
|
||||
|
||||
rtfm::export::run(PRIORITY, || {
|
||||
crate::#name(
|
||||
#locals_new
|
||||
#name::Context::new(&rtfm::export::Priority::new(PRIORITY) #instant)
|
||||
)
|
||||
});
|
||||
}
|
||||
));
|
||||
rtfm::export::run(PRIORITY, || {
|
||||
hprintln!("here").unwrap();
|
||||
// core::pin::Pin::new(crate::#gen_static.assume_init()).resume();
|
||||
// let stat = &mut core::mem::transmute::<_,#gen_type>(crate::#gen_static);
|
||||
core::pin::Pin::new(#gen_static.as_mut_ptr()).resume();
|
||||
});
|
||||
}
|
||||
));
|
||||
} else {
|
||||
const_app.push(quote!(
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
#section
|
||||
#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;
|
||||
|
||||
|
|
@ -116,16 +142,51 @@ pub fn codegen(
|
|||
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 rtfm::Mutex as _;
|
||||
|
||||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
if task.is_generator {
|
||||
// exapmle expansion
|
||||
// type GeneratorFoo = impl Generator<Yield = (), Return = !>;
|
||||
// static mut GENERATOR_FOO: MaybeUninit<GeneratorFoo> = MaybeUninit::uninit();
|
||||
// #[allow(non_snake_case)]
|
||||
// fn foo(ctx: foo::Context) -> GeneratorFoo {
|
||||
// use rtfm::Mutex as _;
|
||||
// move || loop { yield }
|
||||
// }
|
||||
|
||||
let gen_type = util::gen_type_ident(&name);
|
||||
let gen_static = util::gen_static_ident(&name);
|
||||
|
||||
user_tasks.push(quote!(
|
||||
type #gen_type = impl Generator<Yield = (), Return = !>;
|
||||
));
|
||||
|
||||
user_tasks.push(quote!(
|
||||
static mut #gen_static : core::mem::MaybeUninit<#gen_type> = core::mem::MaybeUninit::uninit();
|
||||
));
|
||||
|
||||
user_tasks.push(quote!(
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
#section
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) -> #gen_type {
|
||||
use rtfm::Mutex as _;
|
||||
|
||||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
} else {
|
||||
// generate ordinary task
|
||||
user_tasks.push(quote!(
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
#section
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) {
|
||||
use rtfm::Mutex as _;
|
||||
|
||||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
(const_app, root, user_tasks)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
use rtfm_syntax::ast::App;
|
||||
|
||||
use crate::{analyze::Analysis, check::Extra, codegen::util};
|
||||
|
||||
/// Generates code that runs after `#[init]` returns
|
||||
pub fn codegen(
|
||||
core: u8,
|
||||
app: &App,
|
||||
analysis: &Analysis,
|
||||
extra: &Extra,
|
||||
) -> (Vec<TokenStream2>, Vec<TokenStream2>) {
|
||||
|
|
@ -148,6 +150,29 @@ pub fn codegen(
|
|||
}
|
||||
}
|
||||
|
||||
// initialize generators
|
||||
for (name, task) in &app.hardware_tasks {
|
||||
if task.is_generator {
|
||||
// example expansion
|
||||
// const PRIORITY: u8 = 1;
|
||||
// unsafe {
|
||||
// GeneratorFoo.as_mut_ptr().write(foo(foo::Context::new(PRIORITY)));
|
||||
// }
|
||||
let gen_static = util::gen_static_ident(&name);
|
||||
let priority = task.args.priority;
|
||||
|
||||
stmts.push(quote!(
|
||||
const PRIORITY: u8 = #priority;
|
||||
|
||||
unsafe {
|
||||
#gen_static.as_mut_ptr().write(
|
||||
#name(#name::Context::new(&rtfm::export::Priority::new(PRIORITY)))
|
||||
);
|
||||
};
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// enable the interrupts -- this completes the `init`-ialization phase
|
||||
stmts.push(quote!(rtfm::export::interrupt::enable();));
|
||||
|
||||
|
|
|
|||
|
|
@ -323,3 +323,17 @@ pub fn suffixed(name: &str, core: u8) -> Ident {
|
|||
pub fn tq_ident(core: Core) -> Ident {
|
||||
Ident::new(&format!("TQ{}", core), Span::call_site())
|
||||
}
|
||||
|
||||
/// Generates the generator type
|
||||
/// TODO: Should be CamelCase
|
||||
pub fn gen_type_ident(name: &Ident) -> Ident {
|
||||
Ident::new(&format!("Generator{}", name), Span::call_site())
|
||||
}
|
||||
|
||||
/// Generates the generator type
|
||||
pub fn gen_static_ident(name: &Ident) -> Ident {
|
||||
Ident::new(
|
||||
&format!("GENERATOR_{}", name).to_uppercase(),
|
||||
Span::call_site(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#![deny(warnings)]
|
||||
// Per : remove comment
|
||||
// #![deny(warnings)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue