mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-30 15:34:33 +01:00
make debug builds reproducible
This commit is contained in:
parent
cf05dc2c4b
commit
2b8e743f35
3 changed files with 161 additions and 107 deletions
|
@ -139,15 +139,15 @@ main() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $ex != types ]; then
|
if [ $ex != types ]; then
|
||||||
# arm_example "build" $ex "debug" "" "2"
|
arm_example "build" $ex "debug" "" "2"
|
||||||
# cmp ci/builds/${ex}_debug_1.hex ci/builds/${ex}_debug_2.hex
|
cmp ci/builds/${ex}_debug_1.hex ci/builds/${ex}_debug_2.hex
|
||||||
arm_example "build" $ex "release" "" "2"
|
arm_example "build" $ex "release" "" "2"
|
||||||
cmp ci/builds/${ex}_release_1.hex ci/builds/${ex}_release_2.hex
|
cmp ci/builds/${ex}_release_1.hex ci/builds/${ex}_release_2.hex
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $TARGET != thumbv6m-none-eabi ]; then
|
if [ $TARGET != thumbv6m-none-eabi ]; then
|
||||||
# arm_example "build" $ex "debug" "timer-queue" "2"
|
arm_example "build" $ex "debug" "timer-queue" "2"
|
||||||
# cmp ci/builds/${ex}_timer-queue_debug_1.hex ci/builds/${ex}_timer-queue_debug_2.hex
|
cmp ci/builds/${ex}_timer-queue_debug_1.hex ci/builds/${ex}_timer-queue_debug_2.hex
|
||||||
arm_example "build" $ex "release" "timer-queue" "2"
|
arm_example "build" $ex "release" "timer-queue" "2"
|
||||||
cmp ci/builds/${ex}_timer-queue_release_1.hex ci/builds/${ex}_timer-queue_release_2.hex
|
cmp ci/builds/${ex}_timer-queue_release_1.hex ci/builds/${ex}_timer-queue_release_2.hex
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -68,17 +68,17 @@ impl Default for Context {
|
||||||
|
|
||||||
Context {
|
Context {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
baseline: ident_gen.mk_ident(None),
|
baseline: ident_gen.mk_ident(None, false),
|
||||||
dispatchers: BTreeMap::new(),
|
dispatchers: BTreeMap::new(),
|
||||||
idle: ident_gen.mk_ident(Some("idle")),
|
idle: ident_gen.mk_ident(Some("idle"), false),
|
||||||
init: ident_gen.mk_ident(Some("init")),
|
init: ident_gen.mk_ident(Some("init"), false),
|
||||||
priority: ident_gen.mk_ident(None),
|
priority: ident_gen.mk_ident(None, false),
|
||||||
statics: Aliases::new(),
|
statics: Aliases::new(),
|
||||||
resources: HashMap::new(),
|
resources: HashMap::new(),
|
||||||
schedule_enum: ident_gen.mk_ident(None),
|
schedule_enum: ident_gen.mk_ident(None, false),
|
||||||
schedule_fn: Aliases::new(),
|
schedule_fn: Aliases::new(),
|
||||||
tasks: BTreeMap::new(),
|
tasks: BTreeMap::new(),
|
||||||
timer_queue: ident_gen.mk_ident(None),
|
timer_queue: ident_gen.mk_ident(None, false),
|
||||||
ident_gen,
|
ident_gen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream {
|
||||||
|
|
||||||
let assertions = assertions(app, analysis);
|
let assertions = assertions(app, analysis);
|
||||||
|
|
||||||
let main = ctxt.ident_gen.mk_ident(None);
|
let main = ctxt.ident_gen.mk_ident(None, false);
|
||||||
quote!(
|
quote!(
|
||||||
#resources
|
#resources
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ fn resources(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2:
|
||||||
pub static #mut_ #name: #ty = #expr;
|
pub static #mut_ #name: #ty = #expr;
|
||||||
));
|
));
|
||||||
|
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, true); // XXX is randomness required?
|
||||||
if let Some(Ownership::Shared { ceiling }) = analysis.ownerships.get(name) {
|
if let Some(Ownership::Shared { ceiling }) = analysis.ownerships.get(name) {
|
||||||
items.push(mk_resource(
|
items.push(mk_resource(
|
||||||
ctxt,
|
ctxt,
|
||||||
|
@ -256,7 +256,7 @@ fn resources(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2:
|
||||||
|
|
||||||
ctxt.statics.insert(name.clone(), alias);
|
ctxt.statics.insert(name.clone(), alias);
|
||||||
} else {
|
} else {
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let symbol = format!("{}::{}", name, alias);
|
let symbol = format!("{}::{}", name, alias);
|
||||||
|
|
||||||
items.push(
|
items.push(
|
||||||
|
@ -409,7 +409,7 @@ fn init(ctxt: &mut Context, app: &App, analysis: &Analysis) -> (proc_macro2::Tok
|
||||||
let baseline = &ctxt.baseline;
|
let baseline = &ctxt.baseline;
|
||||||
let baseline_let = match () {
|
let baseline_let = match () {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => quote!(let #baseline = rtfm::Instant::artificial(0);),
|
() => quote!(let ref #baseline = rtfm::Instant::artificial(0);),
|
||||||
|
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
|
@ -419,7 +419,7 @@ fn init(ctxt: &mut Context, app: &App, analysis: &Analysis) -> (proc_macro2::Tok
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => quote!(
|
() => quote!(
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
let start = #baseline;
|
let start = *#baseline;
|
||||||
),
|
),
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
|
@ -434,8 +434,11 @@ fn init(ctxt: &mut Context, app: &App, analysis: &Analysis) -> (proc_macro2::Tok
|
||||||
|
|
||||||
#module
|
#module
|
||||||
|
|
||||||
|
// unsafe trampoline to deter end-users from calling this non-reentrant function
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#unsafety fn #init(mut core: rtfm::Peripherals) #ret {
|
unsafe fn #init(core: rtfm::Peripherals) #ret {
|
||||||
|
#[inline(always)]
|
||||||
|
#unsafety fn init(mut core: rtfm::Peripherals) #ret {
|
||||||
#(#locals)*
|
#(#locals)*
|
||||||
|
|
||||||
#baseline_let
|
#baseline_let
|
||||||
|
@ -450,6 +453,9 @@ fn init(ctxt: &mut Context, app: &App, analysis: &Analysis) -> (proc_macro2::Tok
|
||||||
|
|
||||||
#(#assigns)*
|
#(#assigns)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init(core)
|
||||||
|
}
|
||||||
),
|
),
|
||||||
has_late_resources,
|
has_late_resources,
|
||||||
)
|
)
|
||||||
|
@ -567,7 +573,7 @@ fn module(
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Schedule<'a> {
|
pub struct Schedule<'a> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub #priority: &'a core::cell::Cell<u8>,
|
pub #priority: &'a rtfm::export::Priority,
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -586,7 +592,7 @@ fn module(
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Spawn<'a> {
|
pub struct Spawn<'a> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub #priority: &'a core::cell::Cell<u8>,
|
pub #priority: &'a rtfm::export::Priority,
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@ -595,8 +601,10 @@ fn module(
|
||||||
() => {
|
() => {
|
||||||
let baseline = &ctxt.baseline;
|
let baseline = &ctxt.baseline;
|
||||||
quote!(
|
quote!(
|
||||||
|
// NOTE this field is visible so we use a shared reference to make it
|
||||||
|
// immutable
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub #baseline: rtfm::Instant,
|
pub #baseline: &'a rtfm::Instant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
|
@ -609,7 +617,7 @@ fn module(
|
||||||
pub struct Spawn<'a> {
|
pub struct Spawn<'a> {
|
||||||
#baseline_field
|
#baseline_field
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub #priority: &'a core::cell::Cell<u8>,
|
pub #priority: &'a rtfm::export::Priority,
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -691,7 +699,7 @@ fn prelude(
|
||||||
let mut exprs = vec![];
|
let mut exprs = vec![];
|
||||||
|
|
||||||
// NOTE This field is just to avoid unused type parameter errors around `'a`
|
// NOTE This field is just to avoid unused type parameter errors around `'a`
|
||||||
defs.push(quote!(#[allow(dead_code)] #priority: &'a core::cell::Cell<u8>));
|
defs.push(quote!(#[allow(dead_code)] pub #priority: &'a rtfm::export::Priority));
|
||||||
exprs.push(parse_quote!(#priority));
|
exprs.push(parse_quote!(#priority));
|
||||||
|
|
||||||
let mut may_call_lock = false;
|
let mut may_call_lock = false;
|
||||||
|
@ -830,7 +838,8 @@ fn prelude(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: &'a #mut_ #name
|
pub #name: &'a #mut_ #name
|
||||||
));
|
));
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
// XXX is randomness required?
|
||||||
|
let alias = ctxt.ident_gen.mk_ident(None, true);
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
let #mut_ #alias = unsafe {
|
let #mut_ #alias = unsafe {
|
||||||
|
@ -847,7 +856,8 @@ fn prelude(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: rtfm::Exclusive<'a, #name>
|
pub #name: rtfm::Exclusive<'a, #name>
|
||||||
));
|
));
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
// XXX is randomness required?
|
||||||
|
let alias = ctxt.ident_gen.mk_ident(None, true);
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
let #mut_ #alias = unsafe {
|
let #mut_ #alias = unsafe {
|
||||||
|
@ -914,7 +924,7 @@ fn prelude(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let unsafety = if needs_unsafe {
|
let unsafety = if needs_unsafe {
|
||||||
Some(quote!(unsafe))
|
Some(quote!(unsafe))
|
||||||
} else {
|
} else {
|
||||||
|
@ -975,7 +985,8 @@ fn prelude(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.schedule_fn.insert(task.clone(), ctxt.ident_gen.mk_ident(None));
|
ctxt.schedule_fn
|
||||||
|
.insert(task.clone(), ctxt.ident_gen.mk_ident(None, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
|
@ -991,7 +1002,7 @@ fn prelude(
|
||||||
quote!()
|
quote!()
|
||||||
} else {
|
} else {
|
||||||
quote!(
|
quote!(
|
||||||
let ref #priority = core::cell::Cell::new(#logical_prio);
|
let ref #priority = unsafe { rtfm::export::Priority::new(#logical_prio) };
|
||||||
|
|
||||||
#(#items)*
|
#(#items)*
|
||||||
)
|
)
|
||||||
|
@ -1035,14 +1046,20 @@ fn idle(
|
||||||
quote!(
|
quote!(
|
||||||
#module
|
#module
|
||||||
|
|
||||||
|
// unsafe trampoline to deter end-users from calling this non-reentrant function
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#unsafety fn #idle() -> ! {
|
unsafe fn #idle() -> ! {
|
||||||
|
#[inline(always)]
|
||||||
|
#unsafety fn idle() -> ! {
|
||||||
#(#locals)*
|
#(#locals)*
|
||||||
|
|
||||||
#prelude
|
#prelude
|
||||||
|
|
||||||
#(#stmts)*
|
#(#stmts)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idle()
|
||||||
|
}
|
||||||
),
|
),
|
||||||
quote!(#idle()),
|
quote!(#idle()),
|
||||||
)
|
)
|
||||||
|
@ -1087,7 +1104,7 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec<proc_ma
|
||||||
let baseline = &ctxt.baseline;
|
let baseline = &ctxt.baseline;
|
||||||
let baseline_let = match () {
|
let baseline_let = match () {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => quote!(let #baseline = rtfm::Instant::now();),
|
() => quote!(let ref #baseline = rtfm::Instant::now();),
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
};
|
};
|
||||||
|
@ -1096,7 +1113,7 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec<proc_ma
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => quote!(
|
() => quote!(
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
let start = #baseline;
|
let start = *#baseline;
|
||||||
),
|
),
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
|
@ -1104,15 +1121,17 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec<proc_ma
|
||||||
|
|
||||||
let locals = mk_locals(&exception.statics, false);
|
let locals = mk_locals(&exception.statics, false);
|
||||||
let symbol = ident.to_string();
|
let symbol = ident.to_string();
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let unsafety = &exception.unsafety;
|
let unsafety = &exception.unsafety;
|
||||||
quote!(
|
quote!(
|
||||||
#module
|
#module
|
||||||
|
|
||||||
#[doc(hidden)]
|
// unsafe trampoline to deter end-users from calling this non-reentrant function
|
||||||
#[export_name = #symbol]
|
#[export_name = #symbol]
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#unsafety fn #alias() {
|
unsafe fn #alias() {
|
||||||
|
#[inline(always)]
|
||||||
|
#unsafety fn exception() {
|
||||||
#(#locals)*
|
#(#locals)*
|
||||||
|
|
||||||
#baseline_let
|
#baseline_let
|
||||||
|
@ -1125,6 +1144,9 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec<proc_ma
|
||||||
#(#stmts)*
|
#(#stmts)*
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exception()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -1167,7 +1189,7 @@ fn interrupts(
|
||||||
let baseline = &ctxt.baseline;
|
let baseline = &ctxt.baseline;
|
||||||
let baseline_let = match () {
|
let baseline_let = match () {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => quote!(let #baseline = rtfm::Instant::now();),
|
() => quote!(let ref #baseline = rtfm::Instant::now();),
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
};
|
};
|
||||||
|
@ -1176,20 +1198,23 @@ fn interrupts(
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => quote!(
|
() => quote!(
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
let start = #baseline;
|
let start = *#baseline;
|
||||||
),
|
),
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let locals = mk_locals(&interrupt.statics, false);
|
let locals = mk_locals(&interrupt.statics, false);
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let symbol = ident.to_string();
|
let symbol = ident.to_string();
|
||||||
let unsafety = &interrupt.unsafety;
|
let unsafety = &interrupt.unsafety;
|
||||||
scoped.push(quote!(
|
scoped.push(quote!(
|
||||||
|
// unsafe trampoline to deter end-users from calling this non-reentrant function
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#[export_name = #symbol]
|
#[export_name = #symbol]
|
||||||
#unsafety fn #alias() {
|
unsafe fn #alias() {
|
||||||
|
#[inline(always)]
|
||||||
|
#unsafety fn interrupt() {
|
||||||
// check that this interrupt exists
|
// check that this interrupt exists
|
||||||
let _ = #device::interrupt::#ident;
|
let _ = #device::interrupt::#ident;
|
||||||
|
|
||||||
|
@ -1205,6 +1230,9 @@ fn interrupts(
|
||||||
#(#stmts)*
|
#(#stmts)*
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interrupt()
|
||||||
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,10 +1245,10 @@ fn tasks(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
||||||
// first pass to generate buffers (statics and resources) and spawn aliases
|
// first pass to generate buffers (statics and resources) and spawn aliases
|
||||||
for (name, task) in &app.tasks {
|
for (name, task) in &app.tasks {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
let scheduleds_alias = ctxt.ident_gen.mk_ident(None);
|
let scheduleds_alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let free_alias = ctxt.ident_gen.mk_ident(None);
|
let free_alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let inputs_alias = ctxt.ident_gen.mk_ident(None);
|
let inputs_alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let task_alias = ctxt.ident_gen.mk_ident(Some(&name.to_string()));
|
let task_alias = ctxt.ident_gen.mk_ident(Some(&name.to_string()), false);
|
||||||
|
|
||||||
let inputs = &task.inputs;
|
let inputs = &task.inputs;
|
||||||
|
|
||||||
|
@ -1281,7 +1309,7 @@ fn tasks(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
||||||
alias: task_alias,
|
alias: task_alias,
|
||||||
free_queue: free_alias,
|
free_queue: free_alias,
|
||||||
inputs: inputs_alias,
|
inputs: inputs_alias,
|
||||||
spawn_fn: ctxt.ident_gen.mk_ident(None),
|
spawn_fn: ctxt.ident_gen.mk_ident(None, false),
|
||||||
|
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
scheduleds: scheduleds_alias,
|
scheduleds: scheduleds_alias,
|
||||||
|
@ -1300,7 +1328,7 @@ fn tasks(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => {
|
() => {
|
||||||
let baseline = &ctxt.baseline;
|
let baseline = &ctxt.baseline;
|
||||||
quote!(let scheduled = #baseline;)
|
quote!(let scheduled = *#baseline;)
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => quote!(),
|
||||||
|
@ -1329,19 +1357,23 @@ fn tasks(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
||||||
let attrs = &task.attrs;
|
let attrs = &task.attrs;
|
||||||
let cfgs = &task.cfgs;
|
let cfgs = &task.cfgs;
|
||||||
let task_alias = &ctxt.tasks[name].alias;
|
let task_alias = &ctxt.tasks[name].alias;
|
||||||
let baseline_arg = match () {
|
let (baseline, baseline_arg) = match () {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
() => {
|
() => {
|
||||||
let baseline = &ctxt.baseline;
|
let baseline = &ctxt.baseline;
|
||||||
quote!(#baseline: rtfm::Instant,)
|
(quote!(#baseline,), quote!(#baseline: &rtfm::Instant,))
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => quote!(),
|
() => (quote!(), quote!()),
|
||||||
};
|
};
|
||||||
|
let pats = tuple_pat(inputs);
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
|
// unsafe trampoline to deter end-users from calling this non-reentrant function
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#unsafety fn #task_alias(#baseline_arg #(#inputs,)*) {
|
unsafe fn #task_alias(#baseline_arg #(#inputs,)*) {
|
||||||
|
#[inline(always)]
|
||||||
|
#unsafety fn task(#baseline_arg #(#inputs,)*) {
|
||||||
#(#locals)*
|
#(#locals)*
|
||||||
|
|
||||||
#prelude
|
#prelude
|
||||||
|
@ -1350,6 +1382,9 @@ fn tasks(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
||||||
|
|
||||||
#(#stmts)*
|
#(#stmts)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task(#baseline #pats)
|
||||||
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1366,8 +1401,8 @@ fn dispatchers(
|
||||||
|
|
||||||
let device = &app.args.device;
|
let device = &app.args.device;
|
||||||
for (level, dispatcher) in &analysis.dispatchers {
|
for (level, dispatcher) in &analysis.dispatchers {
|
||||||
let ready_alias = ctxt.ident_gen.mk_ident(None);
|
let ready_alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let enum_alias = ctxt.ident_gen.mk_ident(None);
|
let enum_alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
let capacity = mk_typenum_capacity(dispatcher.capacity, true);
|
let capacity = mk_typenum_capacity(dispatcher.capacity, true);
|
||||||
|
|
||||||
let variants = dispatcher
|
let variants = dispatcher
|
||||||
|
@ -1431,7 +1466,7 @@ fn dispatchers(
|
||||||
let baseline =
|
let baseline =
|
||||||
ptr::read(#scheduleds.get_ref().get_unchecked(usize::from(index)));
|
ptr::read(#scheduleds.get_ref().get_unchecked(usize::from(index)));
|
||||||
);
|
);
|
||||||
call = quote!(#alias(baseline, #pats));
|
call = quote!(#alias(&baseline, #pats));
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
() => {
|
() => {
|
||||||
|
@ -1456,7 +1491,7 @@ fn dispatchers(
|
||||||
let attrs = &dispatcher.attrs;
|
let attrs = &dispatcher.attrs;
|
||||||
let interrupt = &dispatcher.interrupt;
|
let interrupt = &dispatcher.interrupt;
|
||||||
let symbol = interrupt.to_string();
|
let symbol = interrupt.to_string();
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
dispatchers.push(quote!(
|
dispatchers.push(quote!(
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#[export_name = #symbol]
|
#[export_name = #symbol]
|
||||||
|
@ -1538,7 +1573,7 @@ fn spawn(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::TokenSt
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
unsafe fn #alias(
|
unsafe fn #alias(
|
||||||
#baseline_arg
|
#baseline_arg
|
||||||
#priority: &core::cell::Cell<u8>,
|
#priority: &rtfm::export::Priority,
|
||||||
#(#args,)*
|
#(#args,)*
|
||||||
) -> Result<(), #ty> {
|
) -> Result<(), #ty> {
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
@ -1587,7 +1622,7 @@ fn spawn(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::TokenSt
|
||||||
if is_idle {
|
if is_idle {
|
||||||
quote!(rtfm::Instant::now(),)
|
quote!(rtfm::Instant::now(),)
|
||||||
} else {
|
} else {
|
||||||
quote!(self.#baseline,)
|
quote!(*self.#baseline,)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "timer-queue"))]
|
#[cfg(not(feature = "timer-queue"))]
|
||||||
|
@ -1636,7 +1671,7 @@ fn schedule(ctxt: &Context, app: &App) -> proc_macro2::TokenStream {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
unsafe fn #alias(
|
unsafe fn #alias(
|
||||||
#priority: &core::cell::Cell<u8>,
|
#priority: &rtfm::export::Priority,
|
||||||
instant: rtfm::Instant,
|
instant: rtfm::Instant,
|
||||||
#(#args,)*
|
#(#args,)*
|
||||||
) -> Result<(), #ty> {
|
) -> Result<(), #ty> {
|
||||||
|
@ -1782,14 +1817,14 @@ fn timer_queue(ctxt: &mut Context, app: &App, analysis: &Analysis) -> proc_macro
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let logical_prio = analysis.timer_queue.priority;
|
let logical_prio = analysis.timer_queue.priority;
|
||||||
let alias = ctxt.ident_gen.mk_ident(None);
|
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#[export_name = "SysTick"]
|
#[export_name = "SysTick"]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
unsafe fn #alias() {
|
unsafe fn #alias() {
|
||||||
use rtfm::Mutex;
|
use rtfm::Mutex;
|
||||||
|
|
||||||
let ref #priority = core::cell::Cell::new(#logical_prio);
|
let ref #priority = rtfm::export::Priority::new(#logical_prio);
|
||||||
|
|
||||||
rtfm::export::run(|| {
|
rtfm::export::run(|| {
|
||||||
rtfm::export::sys_tick(#tq { #priority }, |task, index| {
|
rtfm::export::sys_tick(#tq { #priority }, |task, index| {
|
||||||
|
@ -1933,7 +1968,7 @@ fn mk_resource(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub struct #struct_<'a> {
|
pub struct #struct_<'a> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub #priority: &'a core::cell::Cell<u8>,
|
pub #priority: &'a rtfm::export::Priority,
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -1942,7 +1977,7 @@ fn mk_resource(
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
struct #struct_<'a> {
|
struct #struct_<'a> {
|
||||||
#priority: &'a core::cell::Cell<u8>,
|
#priority: &'a rtfm::export::Priority,
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -2017,34 +2052,30 @@ impl IdentGenerator {
|
||||||
|
|
||||||
let rng = rand::rngs::SmallRng::from_seed(seed);
|
let rng = rand::rngs::SmallRng::from_seed(seed);
|
||||||
|
|
||||||
IdentGenerator {
|
IdentGenerator { call_count: 0, rng }
|
||||||
call_count: 0,
|
|
||||||
rng,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_ident(&mut self, name: Option<&str>) -> Ident {
|
fn mk_ident(&mut self, name: Option<&str>, random: bool) -> Ident {
|
||||||
let n;
|
|
||||||
let s = if let Some(name) = name {
|
let s = if let Some(name) = name {
|
||||||
n = 4;
|
|
||||||
format!("{}_", name)
|
format!("{}_", name)
|
||||||
} else {
|
} else {
|
||||||
let crate_name = env!("CARGO_PKG_NAME").replace("-", "_").to_lowercase();
|
"__rtfm_internal_".to_string()
|
||||||
n = 4;
|
|
||||||
format!("{}__internal__", crate_name)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut s = format!("{}{}_", s, self.call_count);
|
let mut s = format!("{}{}", s, self.call_count);
|
||||||
|
self.call_count += 1;
|
||||||
|
|
||||||
for i in 0..n {
|
if random {
|
||||||
|
s.push('_');
|
||||||
|
|
||||||
|
for i in 0..4 {
|
||||||
if i == 0 || self.rng.gen() {
|
if i == 0 || self.rng.gen() {
|
||||||
s.push(('a' as u8 + self.rng.gen::<u8>() % 25) as char)
|
s.push(('a' as u8 + self.rng.gen::<u8>() % 25) as char)
|
||||||
} else {
|
} else {
|
||||||
s.push(('0' as u8 + self.rng.gen::<u8>() % 10) as char)
|
s.push(('0' as u8 + self.rng.gen::<u8>() % 10) as char)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self.call_count += 1;
|
|
||||||
|
|
||||||
Ident::new(&s, Span::call_site())
|
Ident::new(&s, Span::call_site())
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,29 @@ where
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Newtype over `Cell` that forbids mutation through a shared reference
|
||||||
|
pub struct Priority {
|
||||||
|
inner: Cell<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Priority {
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn new(value: u8) -> Self {
|
||||||
|
Priority { inner: Cell::new(value)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// these two methods are used by claim (see below) but can't be used from the RTFM application
|
||||||
|
#[inline(always)]
|
||||||
|
fn set(&self, value: u8) {
|
||||||
|
self.inner.set(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn get(&self) -> u8 {
|
||||||
|
self.inner.get()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(MaybeUninit) Until core::mem::MaybeUninit is stabilized we use our own (inefficient)
|
// TODO(MaybeUninit) Until core::mem::MaybeUninit is stabilized we use our own (inefficient)
|
||||||
// implementation
|
// implementation
|
||||||
pub struct MaybeUninit<T> {
|
pub struct MaybeUninit<T> {
|
||||||
|
@ -102,7 +125,7 @@ where
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn claim<T, R, F>(
|
pub unsafe fn claim<T, R, F>(
|
||||||
ptr: *mut T,
|
ptr: *mut T,
|
||||||
priority: &Cell<u8>,
|
priority: &Priority,
|
||||||
ceiling: u8,
|
ceiling: u8,
|
||||||
nvic_prio_bits: u8,
|
nvic_prio_bits: u8,
|
||||||
f: F,
|
f: F,
|
||||||
|
@ -135,7 +158,7 @@ where
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn claim<T, R, F>(
|
pub unsafe fn claim<T, R, F>(
|
||||||
ptr: *mut T,
|
ptr: *mut T,
|
||||||
priority: &Cell<u8>,
|
priority: &Priority,
|
||||||
ceiling: u8,
|
ceiling: u8,
|
||||||
_nvic_prio_bits: u8,
|
_nvic_prio_bits: u8,
|
||||||
f: F,
|
f: F,
|
||||||
|
|
Loading…
Reference in a new issue