From 9e445b3583c15c7701f3167eaa8dfe4afd541691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= Date: Sat, 4 Feb 2023 16:47:17 +0100 Subject: Move rtic macros to repo root, tune xtask --- rtic-macros/src/analyze.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 rtic-macros/src/analyze.rs (limited to 'rtic-macros/src/analyze.rs') 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, +} + +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::>(); + + // map from priorities to interrupts (holding name and attributes) + + let interrupts: BTreeMap = 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, + } +} -- cgit v1.2.3