rtic/macros/src/analyze.rs

48 lines
1 KiB
Rust
Raw Normal View History

use core::ops;
use std::collections::{BTreeMap, BTreeSet};
2020-06-11 19:18:29 +02:00
use rtic_syntax::{
analyze::{self, Priority},
ast::App,
2020-08-27 13:21:56 +02:00
P,
};
use syn::Ident;
/// Extend the upstream `Analysis` struct with our field
2018-11-03 17:02:41 +01:00
pub struct Analysis {
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
}
impl ops::Deref for Analysis {
type Target = analyze::Analysis;
fn deref(&self) -> &Self::Target {
&self.parent
}
}
// Assign an `extern` interrupt to each priority level
pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> {
let mut interrupts = BTreeMap::new();
2020-09-01 16:39:05 +02:00
let priorities = app
.software_tasks
.values()
2020-10-13 16:16:33 +02:00
.map(|task| task.args.priority)
2020-09-01 16:39:05 +02:00
.collect::<BTreeSet<_>>();
2020-09-01 16:39:05 +02:00
if !priorities.is_empty() {
interrupts = priorities
.iter()
.cloned()
.rev()
.zip(app.extern_interrupts.keys().cloned())
.collect();
}
P::new(Analysis {
parent: analysis,
interrupts,
})
}