rtic/macros/src/analyze.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

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
2018-11-03 17:02:41 +01:00
pub struct Analysis {
parent: analyze::Analysis,
2023-01-03 15:10:59 +01:00
pub interrupts: BTreeMap<Priority, (Ident, Dispatcher)>,
2018-11-03 17:02:41 +01:00
}
impl ops::Deref for Analysis {
type Target = analyze::Analysis;
fn deref(&self) -> &Self::Target {
&self.parent
}
}
2020-10-23 10:35:56 +02:00
// Assign an interrupt to each priority level
pub fn app(analysis: analyze::Analysis, app: &App) -> Analysis {
let mut available_interrupt = app.args.dispatchers.clone();
2020-10-23 10:35:56 +02:00
// the set of priorities (each priority only once)
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-10-23 10:35:56 +02:00
// map from priorities to interrupts (holding name and attributes)
2023-01-03 15:10:59 +01:00
let interrupts: BTreeMap<Priority, _> = priorities
.iter()
2023-01-08 21:10:06 +01:00
.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,
2023-01-03 15:10:59 +01:00
interrupts,
}
}