mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 12:12:50 +01:00
WIP
This commit is contained in:
parent
df4a7fd3e5
commit
be92041a59
13 changed files with 115 additions and 23 deletions
5
build.rs
5
build.rs
|
@ -7,7 +7,10 @@ fn main() {
|
|||
println!("cargo:rustc-cfg=armv6m")
|
||||
}
|
||||
|
||||
if target.starts_with("thumbv7m") | target.starts_with("thumbv7em") {
|
||||
if target.starts_with("thumbv7m")
|
||||
| target.starts_with("thumbv7em")
|
||||
| target.starts_with("thumbv8m")
|
||||
{
|
||||
println!("cargo:rustc-cfg=armv7m")
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
|||
|
||||
let cfg_core = util::cfg_core(core, app.args.cores);
|
||||
let main = util::suffixed("main", core);
|
||||
let section = util::link_section("text", core);
|
||||
mains.push(quote!(
|
||||
#[no_mangle]
|
||||
#section
|
||||
#cfg_core
|
||||
unsafe extern "C" fn #main() -> ! {
|
||||
#(#assertion_stmts)*
|
||||
|
|
|
@ -46,13 +46,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
|
||||
let n = util::capacity_typenum(channel.capacity, true);
|
||||
let rq = util::rq_ident(receiver, level, sender);
|
||||
let (rq_attr, rq_ty, rq_expr) = if sender == receiver {
|
||||
let (rq_attr, rq_ty, rq_expr, section) = if sender == receiver {
|
||||
(
|
||||
cfg_sender.clone(),
|
||||
quote!(rtfm::export::SCRQ<#t, #n>),
|
||||
quote!(rtfm::export::Queue(unsafe {
|
||||
rtfm::export::iQueue::u8_sc()
|
||||
})),
|
||||
util::link_section("bss", sender),
|
||||
)
|
||||
} else {
|
||||
let shared = if cfg!(feature = "heterogeneous") {
|
||||
|
@ -65,6 +66,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
shared,
|
||||
quote!(rtfm::export::MCRQ<#t, #n>),
|
||||
quote!(rtfm::export::Queue(rtfm::export::iQueue::u8())),
|
||||
None,
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -77,6 +79,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
items.push(quote!(
|
||||
#[doc = #doc]
|
||||
#rq_attr
|
||||
#section
|
||||
static mut #rq: #rq_ty = #rq_expr;
|
||||
));
|
||||
|
||||
|
@ -162,12 +165,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
receiver, level
|
||||
);
|
||||
let cfg_receiver = util::cfg_core(receiver, app.args.cores);
|
||||
let section = util::link_section("text", receiver);
|
||||
let interrupt = util::suffixed(&interrupts[&level].to_string(), receiver);
|
||||
items.push(quote!(
|
||||
#[allow(non_snake_case)]
|
||||
#[doc = #doc]
|
||||
#[no_mangle]
|
||||
#cfg_receiver
|
||||
#section
|
||||
unsafe fn #interrupt() {
|
||||
/// The priority of this interrupt handler
|
||||
const PRIORITY: u8 = #level;
|
||||
|
|
|
@ -56,9 +56,11 @@ 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;
|
||||
|
@ -101,7 +103,8 @@ 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, app);
|
||||
let (struct_, pat) =
|
||||
locals::codegen(Context::HardwareTask(name), &task.locals, core, app);
|
||||
|
||||
root.push(struct_);
|
||||
locals_pat = Some(pat);
|
||||
|
@ -110,9 +113,12 @@ 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?
|
||||
user_tasks.push(quote!(
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
#section
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) {
|
||||
use rtfm::Mutex as _;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn codegen(
|
|||
|
||||
let name = &idle.name;
|
||||
if !idle.locals.is_empty() {
|
||||
let (locals, pat) = locals::codegen(Context::Idle(core), &idle.locals, app);
|
||||
let (locals, pat) = locals::codegen(Context::Idle(core), &idle.locals, core, app);
|
||||
|
||||
locals_new = Some(quote!(#name::Locals::new()));
|
||||
locals_pat = Some(pat);
|
||||
|
@ -57,10 +57,12 @@ pub fn codegen(
|
|||
let attrs = &idle.attrs;
|
||||
let context = &idle.context;
|
||||
let stmts = &idle.stmts;
|
||||
let section = util::link_section("text", core);
|
||||
let user_idle = Some(quote!(
|
||||
#cfg_core
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
#cfg_core
|
||||
#section
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) -> ! {
|
||||
use rtfm::Mutex as _;
|
||||
|
||||
|
@ -73,12 +75,7 @@ pub fn codegen(
|
|||
#name::Context::new(&rtfm::export::Priority::new(0))
|
||||
));
|
||||
|
||||
(
|
||||
const_app,
|
||||
root_idle,
|
||||
user_idle,
|
||||
call_idle,
|
||||
)
|
||||
(const_app, root_idle, user_idle, call_idle)
|
||||
} else {
|
||||
(
|
||||
None,
|
||||
|
|
|
@ -72,7 +72,7 @@ pub fn codegen(
|
|||
let mut locals_pat = None;
|
||||
let mut locals_new = None;
|
||||
if !init.locals.is_empty() {
|
||||
let (struct_, pat) = locals::codegen(Context::Init(core), &init.locals, app);
|
||||
let (struct_, pat) = locals::codegen(Context::Init(core), &init.locals, core, app);
|
||||
|
||||
locals_new = Some(quote!(#name::Locals::new()));
|
||||
locals_pat = Some(pat);
|
||||
|
@ -82,10 +82,12 @@ pub fn codegen(
|
|||
let context = &init.context;
|
||||
let attrs = &init.attrs;
|
||||
let stmts = &init.stmts;
|
||||
let section = util::link_section("text", core);
|
||||
let user_init = Some(quote!(
|
||||
#(#attrs)*
|
||||
#cfg_core
|
||||
#[allow(non_snake_case)]
|
||||
#section
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context) #ret {
|
||||
#(#stmts)*
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||
use quote::quote;
|
||||
use rtfm_syntax::{
|
||||
ast::{App, Local},
|
||||
Context, Map,
|
||||
Context, Core, Map,
|
||||
};
|
||||
|
||||
use crate::codegen::util;
|
||||
|
@ -10,6 +10,7 @@ use crate::codegen::util;
|
|||
pub fn codegen(
|
||||
ctxt: Context,
|
||||
locals: &Map<Local>,
|
||||
core: Core,
|
||||
app: &App,
|
||||
) -> (
|
||||
// locals
|
||||
|
@ -41,6 +42,7 @@ pub fn codegen(
|
|||
let cfgs = &local.cfgs;
|
||||
has_cfgs |= !cfgs.is_empty();
|
||||
|
||||
let section = util::link_section("data", core);
|
||||
let expr = &local.expr;
|
||||
let ty = &local.ty;
|
||||
fields.push(quote!(
|
||||
|
@ -49,6 +51,7 @@ pub fn codegen(
|
|||
));
|
||||
items.push(quote!(
|
||||
#(#cfgs)*
|
||||
#section
|
||||
static mut #name: #ty = #expr
|
||||
));
|
||||
values.push(quote!(
|
||||
|
|
|
@ -26,20 +26,24 @@ pub fn codegen(
|
|||
let ty = &res.ty;
|
||||
|
||||
{
|
||||
let loc_attr = match loc {
|
||||
let (loc_attr, section) = match loc {
|
||||
Location::Owned {
|
||||
core,
|
||||
cross_initialized: false,
|
||||
} => util::cfg_core(*core, app.args.cores),
|
||||
} => (
|
||||
util::cfg_core(*core, app.args.cores),
|
||||
util::link_section("data", *core),
|
||||
),
|
||||
|
||||
// shared `static`s and cross-initialized resources need to be in `.shared` memory
|
||||
_ => {
|
||||
_ => (
|
||||
if cfg!(feature = "heterogeneous") {
|
||||
Some(quote!(#[rtfm::export::shared]))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
},
|
||||
None,
|
||||
),
|
||||
};
|
||||
|
||||
let (ty, expr) = if let Some(expr) = expr {
|
||||
|
@ -53,9 +57,10 @@ pub fn codegen(
|
|||
|
||||
let attrs = &res.attrs;
|
||||
const_app.push(quote!(
|
||||
#loc_attr
|
||||
#(#attrs)*
|
||||
#(#cfgs)*
|
||||
#loc_attr
|
||||
#section
|
||||
static mut #name: #ty = #expr;
|
||||
));
|
||||
}
|
||||
|
|
|
@ -35,8 +35,10 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec<TokenStream2> {
|
|||
|
||||
let body = schedule_body::codegen(scheduler, &name, app);
|
||||
|
||||
let section = util::link_section("text", sender);
|
||||
methods.push(quote!(
|
||||
#(#cfgs)*
|
||||
#section
|
||||
fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> {
|
||||
#body
|
||||
}
|
||||
|
@ -50,9 +52,11 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec<TokenStream2> {
|
|||
|
||||
let body = schedule_body::codegen(scheduler, &name, app);
|
||||
|
||||
let section = util::link_section("text", sender);
|
||||
items.push(quote!(
|
||||
#cfg_sender
|
||||
#(#cfgs)*
|
||||
#section
|
||||
unsafe fn #schedule(
|
||||
priority: &rtfm::export::Priority,
|
||||
instant: #instant
|
||||
|
|
|
@ -43,13 +43,21 @@ pub fn codegen(
|
|||
let cfg_sender = util::cfg_core(sender, app.args.cores);
|
||||
let fq = util::fq_ident(name, sender);
|
||||
|
||||
let (loc, fq_ty, fq_expr) = if receiver == sender {
|
||||
let (loc, fq_ty, fq_expr, bss, mk_uninit): (
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
Box<dyn Fn() -> Option<_>>,
|
||||
) = if receiver == sender {
|
||||
(
|
||||
cfg_sender.clone(),
|
||||
quote!(rtfm::export::SCFQ<#cap_ty>),
|
||||
quote!(rtfm::export::Queue(unsafe {
|
||||
rtfm::export::iQueue::u8_sc()
|
||||
})),
|
||||
util::link_section("bss", sender),
|
||||
Box::new(|| util::link_section_uninit(Some(sender))),
|
||||
)
|
||||
} else {
|
||||
let shared = if cfg!(feature = "heterogeneous") {
|
||||
|
@ -62,6 +70,8 @@ pub fn codegen(
|
|||
shared,
|
||||
quote!(rtfm::export::MCFQ<#cap_ty>),
|
||||
quote!(rtfm::export::Queue(rtfm::export::iQueue::u8())),
|
||||
None,
|
||||
Box::new(|| util::link_section_uninit(None)),
|
||||
)
|
||||
};
|
||||
let loc = &loc;
|
||||
|
@ -70,6 +80,7 @@ pub fn codegen(
|
|||
/// Queue version of a free-list that keeps track of empty slots in
|
||||
/// the following buffers
|
||||
#loc
|
||||
#bss
|
||||
static mut #fq: #fq_ty = #fq_expr;
|
||||
));
|
||||
|
||||
|
@ -102,8 +113,10 @@ pub fn codegen(
|
|||
let m = extra.monotonic();
|
||||
let instants = util::instants_ident(name, sender);
|
||||
|
||||
let uninit = mk_uninit();
|
||||
const_app.push(quote!(
|
||||
#loc
|
||||
#uninit
|
||||
/// Buffer that holds the instants associated to the inputs of a task
|
||||
static mut #instants:
|
||||
[core::mem::MaybeUninit<<#m as rtfm::Monotonic>::Instant>; #cap_lit] =
|
||||
|
@ -111,9 +124,11 @@ pub fn codegen(
|
|||
));
|
||||
}
|
||||
|
||||
let uninit = mk_uninit();
|
||||
let inputs = util::inputs_ident(name, sender);
|
||||
const_app.push(quote!(
|
||||
#loc
|
||||
#uninit
|
||||
/// Buffer that holds the inputs of a task
|
||||
static mut #inputs: [core::mem::MaybeUninit<#input_ty>; #cap_lit] =
|
||||
[#(#elems,)*];
|
||||
|
@ -140,13 +155,15 @@ pub fn codegen(
|
|||
// `${task}Locals`
|
||||
let mut locals_pat = None;
|
||||
if !task.locals.is_empty() {
|
||||
let (struct_, pat) = locals::codegen(Context::SoftwareTask(name), &task.locals, app);
|
||||
let (struct_, pat) =
|
||||
locals::codegen(Context::SoftwareTask(name), &task.locals, receiver, app);
|
||||
|
||||
locals_pat = Some(pat);
|
||||
root.push(struct_);
|
||||
}
|
||||
|
||||
let cfg_receiver = util::cfg_core(receiver, app.args.cores);
|
||||
let section = util::link_section("text", receiver);
|
||||
let context = &task.context;
|
||||
let attrs = &task.attrs;
|
||||
let cfgs = &task.cfgs;
|
||||
|
@ -154,8 +171,9 @@ pub fn codegen(
|
|||
user_tasks.push(quote!(
|
||||
#(#attrs)*
|
||||
#(#cfgs)*
|
||||
#cfg_receiver
|
||||
#[allow(non_snake_case)]
|
||||
#cfg_receiver
|
||||
#section
|
||||
fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
|
||||
use rtfm::Mutex as _;
|
||||
|
||||
|
|
|
@ -42,8 +42,10 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
None
|
||||
};
|
||||
|
||||
let section = util::link_section("text", sender);
|
||||
methods.push(quote!(
|
||||
#(#cfgs)*
|
||||
#section
|
||||
fn #name(&self #(,#args)*) -> Result<(), #ty> {
|
||||
#let_instant
|
||||
#body
|
||||
|
@ -66,9 +68,11 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
|
||||
let body = spawn_body::codegen(spawner, &name, app, analysis, extra);
|
||||
|
||||
let section = util::link_section("text", sender);
|
||||
items.push(quote!(
|
||||
#cfg_sender
|
||||
#(#cfgs)*
|
||||
#section
|
||||
unsafe fn #spawn(
|
||||
priority: &rtfm::export::Priority
|
||||
#instant
|
||||
|
|
|
@ -48,9 +48,11 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
let n = util::capacity_typenum(timer_queue.capacity, false);
|
||||
let tq_ty = quote!(rtfm::export::TimerQueue<#m, #t, #n>);
|
||||
|
||||
let section = util::link_section("bss", sender);
|
||||
items.push(quote!(
|
||||
#cfg_sender
|
||||
#[doc = #doc]
|
||||
#section
|
||||
static mut #tq: #tq_ty = rtfm::export::TimerQueue(
|
||||
rtfm::export::BinaryHeap(
|
||||
rtfm::export::iBinaryHeap::new()
|
||||
|
@ -117,9 +119,11 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
|||
|
||||
let priority = timer_queue.priority;
|
||||
let sys_tick = util::suffixed("SysTick", sender);
|
||||
let section = util::link_section("text", sender);
|
||||
items.push(quote!(
|
||||
#cfg_sender
|
||||
#[no_mangle]
|
||||
#cfg_sender
|
||||
#section
|
||||
unsafe fn #sys_tick() {
|
||||
use rtfm::Mutex as _;
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||
use quote::quote;
|
||||
use rtfm_syntax::{ast::App, Context, Core};
|
||||
|
@ -133,6 +135,43 @@ pub fn late_resources_ident(init: &Ident) -> Ident {
|
|||
)
|
||||
}
|
||||
|
||||
fn link_section_index() -> usize {
|
||||
static INDEX: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
INDEX.fetch_add(1, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub fn link_section(section: &str, core: Core) -> Option<TokenStream2> {
|
||||
if cfg!(feature = "homogeneous") {
|
||||
let section = format!(".{}_{}.rtfm{}", section, core, link_section_index());
|
||||
Some(quote!(#[link_section = #section]))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE `None` means in shared memory
|
||||
pub fn link_section_uninit(core: Option<Core>) -> Option<TokenStream2> {
|
||||
let section = if let Some(core) = core {
|
||||
let index = link_section_index();
|
||||
|
||||
if cfg!(feature = "homogeneous") {
|
||||
format!(".uninit_{}.rtfm{}", core, index)
|
||||
} else {
|
||||
format!(".uninit.rtfm{}", index)
|
||||
}
|
||||
} else {
|
||||
if cfg!(feature = "heterogeneous") {
|
||||
// `#[shared]` attribute sets the linker section
|
||||
return None;
|
||||
}
|
||||
|
||||
format!(".uninit.rtfm{}", link_section_index())
|
||||
};
|
||||
|
||||
Some(quote!(#[link_section = #section]))
|
||||
}
|
||||
|
||||
/// Generates a pre-reexport identifier for the "locals" struct
|
||||
pub fn locals_ident(ctxt: Context, app: &App) -> Ident {
|
||||
let mut s = match ctxt {
|
||||
|
|
Loading…
Reference in a new issue