mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-24 04:32:52 +01:00
Masks take 3
This commit is contained in:
parent
8707418003
commit
9f38a39377
4 changed files with 62 additions and 17 deletions
|
@ -7,6 +7,14 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Generation of masks for the source masking scheduling for thumbv6
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
## [v1.1.1] - 2022-04-13
|
## [v1.1.1] - 2022-04-13
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
use crate::{analyze::Analysis, check::Extra, codegen::util};
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use rtic_syntax::{analyze::Ownership, ast::App};
|
use rtic_syntax::{analyze::Ownership, ast::App};
|
||||||
|
use std::collections::HashMap;
|
||||||
use crate::{analyze::Analysis, check::Extra, codegen::util};
|
|
||||||
|
|
||||||
/// Generates `static` variables and shared resource proxies
|
/// Generates `static` variables and shared resource proxies
|
||||||
pub fn codegen(
|
pub fn codegen(
|
||||||
|
@ -108,14 +108,9 @@ pub fn codegen(
|
||||||
// Computing mapping of used interrupts to masks
|
// Computing mapping of used interrupts to masks
|
||||||
let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));
|
let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));
|
||||||
|
|
||||||
use std::collections::HashMap;
|
let mut prio_to_masks = HashMap::new();
|
||||||
let mut masks: HashMap<u8, _> = std::collections::HashMap::new();
|
|
||||||
let device = &extra.device;
|
let device = &extra.device;
|
||||||
|
|
||||||
for p in 0..3 {
|
|
||||||
masks.insert(p, quote!(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().flat_map(|task| {
|
for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().flat_map(|task| {
|
||||||
if !util::is_exception(&task.args.binds) {
|
if !util::is_exception(&task.args.binds) {
|
||||||
Some((&task.args.priority, &task.args.binds))
|
Some((&task.args.priority, &task.args.binds))
|
||||||
|
@ -124,18 +119,31 @@ pub fn codegen(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})) {
|
})) {
|
||||||
let name = quote!(#device::Interrupt::#name as u32);
|
let v = prio_to_masks.entry(priority - 1).or_insert(Vec::new());
|
||||||
if let Some(v) = masks.get_mut(&(priority - 1)) {
|
v.push(quote!(#device::Interrupt::#name as u32));
|
||||||
*v = quote!(#v | 1 << #name);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut mask_arr: Vec<(_, _)> = masks.iter().collect();
|
// Call rtic::export::create_mask([u32; N]), where the array is the list of shifts
|
||||||
mask_arr.sort_by_key(|(k, _v)| *k);
|
|
||||||
let mask_arr: Vec<_> = mask_arr.iter().map(|(_, v)| v).collect();
|
|
||||||
|
|
||||||
|
let mut mask_arr = Vec::new();
|
||||||
|
// NOTE: 0..3 assumes max 4 priority levels according to M0 spec
|
||||||
|
for i in 0..3 {
|
||||||
|
let v = if let Some(v) = prio_to_masks.get(&i) {
|
||||||
|
v.clone()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
mask_arr.push(quote!(
|
||||||
|
rtic::export::create_mask([#(#v),*])
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let masks_name = util::priority_masks_ident();
|
||||||
mod_app.push(quote!(
|
mod_app.push(quote!(
|
||||||
const MASKS: [u32; 3] = [#(#mask_arr),*];
|
#[doc(hidden)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
const #masks_name: [u32; 3] = [#(#mask_arr),*];
|
||||||
));
|
));
|
||||||
|
|
||||||
(mod_app, mod_resources)
|
(mod_app, mod_resources)
|
||||||
|
|
|
@ -36,6 +36,7 @@ pub fn impl_mutex(
|
||||||
};
|
};
|
||||||
|
|
||||||
let device = &extra.device;
|
let device = &extra.device;
|
||||||
|
let masks_name = priority_masks_ident();
|
||||||
quote!(
|
quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
impl<'a> rtic::Mutex for #path<'a> {
|
impl<'a> rtic::Mutex for #path<'a> {
|
||||||
|
@ -52,7 +53,7 @@ pub fn impl_mutex(
|
||||||
#priority,
|
#priority,
|
||||||
CEILING,
|
CEILING,
|
||||||
#device::NVIC_PRIO_BITS,
|
#device::NVIC_PRIO_BITS,
|
||||||
&MASKS,
|
&#masks_name,
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -252,6 +253,10 @@ pub fn static_shared_resource_ident(name: &Ident) -> Ident {
|
||||||
mark_internal_name(&format!("shared_resource_{}", name))
|
mark_internal_name(&format!("shared_resource_{}", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn priority_masks_ident() -> Ident {
|
||||||
|
mark_internal_name("MASKS")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn static_local_resource_ident(name: &Ident) -> Ident {
|
pub fn static_local_resource_ident(name: &Ident) -> Ident {
|
||||||
mark_internal_name(&format!("local_resource_{}", name))
|
mark_internal_name(&format!("local_resource_{}", name))
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,3 +315,27 @@ unsafe fn clear_enable_mask(mask: u32) {
|
||||||
pub fn logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 {
|
pub fn logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 {
|
||||||
((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits)
|
((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(armv6m))]
|
||||||
|
pub const fn create_mask<const N: usize>(_: [u32; N]) -> u32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(armv6m)]
|
||||||
|
pub const fn create_mask<const N: usize>(list_of_shifts: [u32; N]) -> u32 {
|
||||||
|
let mut mask = 0;
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
while i < N {
|
||||||
|
let shift = list_of_shifts[i];
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
if shift > 31 {
|
||||||
|
panic!("Generating masks for thumbv6 failed! Are you compiling for thumbv6 on an thumbv7 MCU?");
|
||||||
|
}
|
||||||
|
|
||||||
|
mask |= 1 << shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
mask
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue