2019-06-13 23:56:59 +02:00
|
|
|
use core::ops;
|
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
2017-07-15 01:54:54 +02:00
|
|
|
|
2020-06-11 19:18:29 +02:00
|
|
|
use rtic_syntax::{
|
2019-06-13 23:56:59 +02:00
|
|
|
analyze::{self, Priority},
|
|
|
|
ast::App,
|
2020-08-27 13:21:56 +02:00
|
|
|
P,
|
2019-06-13 23:56:59 +02:00
|
|
|
};
|
|
|
|
use syn::Ident;
|
2017-07-15 01:54:54 +02:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
/// Extend the upstream `Analysis` struct with our field
|
2018-11-03 17:02:41 +01:00
|
|
|
pub struct Analysis {
|
2019-06-13 23:56:59 +02:00
|
|
|
parent: P<analyze::Analysis>,
|
2020-08-27 13:21:56 +02:00
|
|
|
pub interrupts: BTreeMap<Priority, Ident>,
|
2018-11-03 17:02:41 +01:00
|
|
|
}
|
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
impl ops::Deref for Analysis {
|
|
|
|
type Target = analyze::Analysis;
|
2018-11-04 18:50:42 +01:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.parent
|
2018-11-04 18:50:42 +01:00
|
|
|
}
|
2017-07-15 01:54:54 +02:00
|
|
|
}
|
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
// Assign an `extern` interrupt to each priority level
|
|
|
|
pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> {
|
|
|
|
let mut interrupts = BTreeMap::new();
|
|
|
|
let priorities = app
|
|
|
|
.software_tasks
|
|
|
|
.values()
|
|
|
|
.filter_map(|task| {
|
|
|
|
Some(task.args.priority)
|
|
|
|
})
|
2020-08-27 13:21:56 +02:00
|
|
|
.chain(analysis.timer_queues.first().map(|tq| tq.priority))
|
2019-06-13 23:56:59 +02:00
|
|
|
.collect::<BTreeSet<_>>();
|
|
|
|
|
|
|
|
if !priorities.is_empty() {
|
2020-08-27 13:21:56 +02:00
|
|
|
interrupts =
|
2019-06-13 23:56:59 +02:00
|
|
|
priorities
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.rev()
|
2020-08-27 13:21:56 +02:00
|
|
|
.zip(app.extern_interrupts.keys().cloned())
|
|
|
|
.collect();
|
2019-06-13 23:56:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
P::new(Analysis {
|
|
|
|
parent: analysis,
|
|
|
|
interrupts,
|
|
|
|
})
|
2017-07-15 01:54:54 +02:00
|
|
|
}
|