mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
codegen: merge dictionaries related to task dispatchers
This commit is contained in:
parent
77de15f468
commit
f7ac71ab22
1 changed files with 23 additions and 14 deletions
|
@ -24,16 +24,13 @@ struct Context {
|
||||||
// Alias
|
// Alias
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
baseline: Ident,
|
baseline: Ident,
|
||||||
// Dispatcher -> Alias (`enum`)
|
dispatchers: HashMap<u8, Dispatcher>,
|
||||||
enums: HashMap<u8, Ident>,
|
|
||||||
// Alias (`fn`)
|
// Alias (`fn`)
|
||||||
idle: Ident,
|
idle: Ident,
|
||||||
// Alias (`fn`)
|
// Alias (`fn`)
|
||||||
init: Ident,
|
init: Ident,
|
||||||
// Alias
|
// Alias
|
||||||
priority: Ident,
|
priority: Ident,
|
||||||
// Dispatcher -> Alias (`static` / resource)
|
|
||||||
ready_queues: HashMap<u8, Ident>,
|
|
||||||
// For non-singletons this maps the resource name to its `static mut` variable name
|
// For non-singletons this maps the resource name to its `static mut` variable name
|
||||||
statics: Aliases,
|
statics: Aliases,
|
||||||
/// Task -> Alias (`struct`)
|
/// Task -> Alias (`struct`)
|
||||||
|
@ -47,6 +44,11 @@ struct Context {
|
||||||
timer_queue: Ident,
|
timer_queue: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Dispatcher {
|
||||||
|
enum_: Ident,
|
||||||
|
ready_queue: Ident,
|
||||||
|
}
|
||||||
|
|
||||||
struct Task {
|
struct Task {
|
||||||
alias: Ident,
|
alias: Ident,
|
||||||
free_queue: Ident,
|
free_queue: Ident,
|
||||||
|
@ -62,11 +64,10 @@ impl Default for Context {
|
||||||
Context {
|
Context {
|
||||||
#[cfg(feature = "timer-queue")]
|
#[cfg(feature = "timer-queue")]
|
||||||
baseline: mk_ident(None),
|
baseline: mk_ident(None),
|
||||||
enums: HashMap::new(),
|
dispatchers: HashMap::new(),
|
||||||
idle: mk_ident(Some("idle")),
|
idle: mk_ident(Some("idle")),
|
||||||
init: mk_ident(Some("init")),
|
init: mk_ident(Some("init")),
|
||||||
priority: mk_ident(None),
|
priority: mk_ident(None),
|
||||||
ready_queues: HashMap::new(),
|
|
||||||
statics: Aliases::new(),
|
statics: Aliases::new(),
|
||||||
resources: HashMap::new(),
|
resources: HashMap::new(),
|
||||||
schedule_enum: mk_ident(None),
|
schedule_enum: mk_ident(None),
|
||||||
|
@ -1289,8 +1290,13 @@ fn dispatchers(
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
ctxt.ready_queues.insert(*level, ready_alias);
|
ctxt.dispatchers.insert(
|
||||||
ctxt.enums.insert(*level, enum_alias);
|
*level,
|
||||||
|
Dispatcher {
|
||||||
|
ready_queue: ready_alias,
|
||||||
|
enum_: enum_alias,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(quote!(#(#data)*), quote!(#(#dispatchers)*))
|
(quote!(#(#data)*), quote!(#(#dispatchers)*))
|
||||||
|
@ -1309,8 +1315,9 @@ fn spawn(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::TokenSt
|
||||||
let task_ = &app.tasks[name];
|
let task_ = &app.tasks[name];
|
||||||
let free = &task.free_queue;
|
let free = &task.free_queue;
|
||||||
let level = task_.args.priority;
|
let level = task_.args.priority;
|
||||||
let ready = &ctxt.ready_queues[&level];
|
let dispatcher = &ctxt.dispatchers[&level];
|
||||||
let enum_ = &ctxt.enums[&level];
|
let ready = &dispatcher.ready_queue;
|
||||||
|
let enum_ = &dispatcher.enum_;
|
||||||
let dispatcher = &analysis.dispatchers[&level].interrupt;
|
let dispatcher = &analysis.dispatchers[&level].interrupt;
|
||||||
let inputs = &task.inputs;
|
let inputs = &task.inputs;
|
||||||
let args = &task_.inputs;
|
let args = &task_.inputs;
|
||||||
|
@ -1546,8 +1553,9 @@ fn timer_queue(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::T
|
||||||
.iter()
|
.iter()
|
||||||
.map(|task| {
|
.map(|task| {
|
||||||
let level = app.tasks[task].args.priority;
|
let level = app.tasks[task].args.priority;
|
||||||
let tenum = &ctxt.enums[&level];
|
let dispatcher_ = &ctxt.dispatchers[&level];
|
||||||
let ready = &ctxt.ready_queues[&level];
|
let tenum = &dispatcher_.enum_;
|
||||||
|
let ready = &dispatcher_.ready_queue;
|
||||||
let dispatcher = &analysis.dispatchers[&level].interrupt;
|
let dispatcher = &analysis.dispatchers[&level].interrupt;
|
||||||
|
|
||||||
quote!(
|
quote!(
|
||||||
|
@ -1604,8 +1612,9 @@ fn pre_init(ctxt: &Context, analysis: &Analysis) -> proc_macro2::TokenStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are `MaybeUninit` `ReadyQueue`s
|
// these are `MaybeUninit` `ReadyQueue`s
|
||||||
for queue in ctxt.ready_queues.values() {
|
for dispatcher in ctxt.dispatchers.values() {
|
||||||
exprs.push(quote!(#queue.set(rtfm::export::ReadyQueue::new());))
|
let rq = &dispatcher.ready_queue;
|
||||||
|
exprs.push(quote!(#rq.set(rtfm::export::ReadyQueue::new());))
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are `MaybeUninit` `FreeQueue`s
|
// these are `MaybeUninit` `FreeQueue`s
|
||||||
|
|
Loading…
Reference in a new issue