aboutsummaryrefslogtreecommitdiff
path: root/rtic-macros/src/analyze.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-03-04 21:10:24 +0000
committerGitHub <noreply@github.com>2023-03-04 21:10:24 +0000
commit7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b (patch)
tree80a47f0dc40059014e9448c4c2eb34c54dff45fe /rtic-macros/src/analyze.rs
parent1c5db277e4161470136dbd2a11e914ff1d383581 (diff)
parent98c5490d94950608d31cd5ad9dd260f2f853735c (diff)
Merge #694
694: RTIC 2 r=AfoHT a=korken89 Co-authored-by: Emil Fresk <emil.fresk@gmail.com> Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
Diffstat (limited to 'rtic-macros/src/analyze.rs')
-rw-r--r--rtic-macros/src/analyze.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/rtic-macros/src/analyze.rs b/rtic-macros/src/analyze.rs
new file mode 100644
index 0000000..65774f6
--- /dev/null
+++ b/rtic-macros/src/analyze.rs
@@ -0,0 +1,49 @@
+use core::ops;
+use std::collections::{BTreeMap, BTreeSet};
+
+use crate::syntax::{
+ analyze::{self, Priority},
+ ast::{App, Dispatcher},
+};
+use syn::Ident;
+
+/// Extend the upstream `Analysis` struct with our field
+pub struct Analysis {
+ parent: analyze::Analysis,
+ pub interrupts: BTreeMap<Priority, (Ident, Dispatcher)>,
+}
+
+impl ops::Deref for Analysis {
+ type Target = analyze::Analysis;
+
+ fn deref(&self) -> &Self::Target {
+ &self.parent
+ }
+}
+
+// Assign an interrupt to each priority level
+pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis {
+ let mut available_interrupt = app.args.dispatchers.clone();
+
+ // the set of priorities (each priority only once)
+ let priorities = app
+ .software_tasks
+ .values()
+ .map(|task| task.args.priority)
+ .collect::<BTreeSet<_>>();
+
+ // map from priorities to interrupts (holding name and attributes)
+
+ let interrupts: BTreeMap<Priority, _> = priorities
+ .iter()
+ .filter(|prio| **prio > 0) // 0 prio tasks are run in main
+ .copied()
+ .rev()
+ .map(|p| (p, available_interrupt.pop().expect("UNREACHABLE")))
+ .collect();
+
+ Analysis {
+ parent: analysis,
+ interrupts,
+ }
+}