aboutsummaryrefslogtreecommitdiff
path: root/macros/src/analyze.rs
blob: e3ed7781db00aedaa21f736b6c90ed66c0f324c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use core::ops;
use std::collections::{BTreeMap, BTreeSet};

use rtfm_syntax::{
    analyze::{self, Priority},
    ast::App,
    Core, P,
};
use syn::Ident;

/// Extend the upstream `Analysis` struct with our field
pub struct Analysis {
    parent: P<analyze::Analysis>,
    pub interrupts: BTreeMap<Core, BTreeMap<Priority, Ident>>,
}

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();
    for core in 0..app.args.cores {
        let priorities = app
            .software_tasks
            .values()
            .filter_map(|task| {
                if task.args.core == core {
                    Some(task.args.priority)
                } else {
                    None
                }
            })
            .chain(analysis.timer_queues.get(&core).map(|tq| tq.priority))
            .collect::<BTreeSet<_>>();

        if !priorities.is_empty() {
            interrupts.insert(
                core,
                priorities
                    .iter()
                    .cloned()
                    .rev()
                    .zip(app.extern_interrupts[&core].keys().cloned())
                    .collect(),
            );
        }
    }

    P::new(Analysis {
        parent: analysis,
        interrupts,
    })
}