cortex_m_rtic_macros/
analyze.rs

1use core::ops;
2use std::collections::{BTreeMap, BTreeSet};
3
4use rtic_syntax::{
5    analyze::{self, Priority},
6    ast::{App, ExternInterrupt},
7    P,
8};
9use syn::Ident;
10
11/// Extend the upstream `Analysis` struct with our field
12pub struct Analysis {
13    parent: P<analyze::Analysis>,
14    pub interrupts: BTreeMap<Priority, (Ident, ExternInterrupt)>,
15}
16
17impl ops::Deref for Analysis {
18    type Target = analyze::Analysis;
19
20    fn deref(&self) -> &Self::Target {
21        &self.parent
22    }
23}
24
25// Assign an interrupt to each priority level
26pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> {
27    // the set of priorities (each priority only once)
28    let priorities = app
29        .software_tasks
30        .values()
31        .map(|task| task.args.priority)
32        .collect::<BTreeSet<_>>();
33
34    // map from priorities to interrupts (holding name and attributes)
35    let interrupts: BTreeMap<Priority, _> = priorities
36        .iter()
37        .copied()
38        .rev()
39        .zip(&app.args.extern_interrupts)
40        .map(|(p, (id, ext))| (p, (id.clone(), ext.clone())))
41        .collect();
42
43    P::new(Analysis {
44        parent: analysis,
45        interrupts,
46    })
47}