2019-06-13 23:56:59 +02:00
|
|
|
use core::ops;
|
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
2017-07-15 01:54:54 +02:00
|
|
|
|
2022-12-31 14:45:13 +01:00
|
|
|
use crate::syntax::{
|
2019-06-13 23:56:59 +02:00
|
|
|
analyze::{self, Priority},
|
2022-12-31 14:45:13 +01:00
|
|
|
ast::{App, Dispatcher},
|
2019-06-13 23:56:59 +02:00
|
|
|
};
|
|
|
|
use syn::Ident;
|
2017-07-15 01:54:54 +02:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
/// Extend the upstream `Analysis` struct with our field
|
2018-11-03 17:02:41 +01:00
|
|
|
pub struct Analysis {
|
2022-12-31 14:45:13 +01:00
|
|
|
parent: analyze::Analysis,
|
|
|
|
pub interrupts_normal: BTreeMap<Priority, (Ident, Dispatcher)>,
|
|
|
|
pub interrupts_async: BTreeMap<Priority, (Ident, Dispatcher)>,
|
2018-11-03 17:02:41 +01:00
|
|
|
}
|
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
impl ops::Deref for Analysis {
|
|
|
|
type Target = analyze::Analysis;
|
2018-11-04 18:50:42 +01:00
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.parent
|
2018-11-04 18:50:42 +01:00
|
|
|
}
|
2017-07-15 01:54:54 +02:00
|
|
|
}
|
|
|
|
|
2020-10-23 10:35:56 +02:00
|
|
|
// Assign an interrupt to each priority level
|
2022-12-31 14:45:13 +01:00
|
|
|
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()
|
2022-12-31 14:45:13 +01:00
|
|
|
.filter(|task| !task.is_async)
|
|
|
|
.map(|task| task.args.priority)
|
|
|
|
.collect::<BTreeSet<_>>();
|
|
|
|
|
|
|
|
let priorities_async = app
|
|
|
|
.software_tasks
|
|
|
|
.values()
|
|
|
|
.filter(|task| task.is_async)
|
2020-10-13 16:16:33 +02:00
|
|
|
.map(|task| task.args.priority)
|
2020-09-01 16:39:05 +02:00
|
|
|
.collect::<BTreeSet<_>>();
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2020-10-23 10:35:56 +02:00
|
|
|
// map from priorities to interrupts (holding name and attributes)
|
2022-12-31 14:45:13 +01:00
|
|
|
|
|
|
|
let interrupts_normal: BTreeMap<Priority, _> = priorities
|
2020-10-23 10:35:56 +02:00
|
|
|
.iter()
|
2022-02-18 19:38:48 +01:00
|
|
|
.copied()
|
2020-10-23 10:35:56 +02:00
|
|
|
.rev()
|
2022-12-31 14:45:13 +01:00
|
|
|
.map(|p| (p, available_interrupt.pop().expect("UNREACHABLE")))
|
2020-10-23 10:35:56 +02:00
|
|
|
.collect();
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2022-12-31 14:45:13 +01:00
|
|
|
let interrupts_async: BTreeMap<Priority, _> = priorities_async
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.rev()
|
|
|
|
.map(|p| (p, available_interrupt.pop().expect("UNREACHABLE")))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Analysis {
|
2019-06-13 23:56:59 +02:00
|
|
|
parent: analysis,
|
2022-12-31 14:45:13 +01:00
|
|
|
interrupts_normal,
|
|
|
|
interrupts_async,
|
|
|
|
}
|
2017-07-15 01:54:54 +02:00
|
|
|
}
|