Add feature flags

This commit is contained in:
Emil Fresk 2023-02-19 14:30:49 +01:00 committed by Henrik Tjäder
parent 60f0342b69
commit b9e0f36aff
12 changed files with 88 additions and 73 deletions

View file

@ -26,10 +26,13 @@ default = []
debugprint = []
# list of supported codegen backends
thumbv6 = []
thumbv7 = []
# riscv-clic = []
# riscv-ch32 = []
cortex_m_source_masking = []
cortex_m_basepri = []
# riscv_clic = []
# riscv_ch32 = []
# backend API test
test_template = []
[dependencies]
indexmap = "1.9.2"

View file

@ -1,5 +1,18 @@
// TODO: Feature gate
#[cfg(not(any(
feature = "cortex_m_source_masking",
feature = "cortex_m_basepri",
feaute = "test_template"
)))]
compile_error!("No backend selected");
#[cfg(any(feature = "cortex_m_source_masking", feature = "cortex_m_basepri"))]
pub use cortex::*;
#[cfg(feature = "test_template")]
pub use cortex::*;
#[cfg(any(feature = "cortex_m_source_masking", feature = "cortex_m_basepri"))]
mod cortex;
// TODO: Feature gate
pub use cortex::*;
#[cfg(feature = "test_template")]
mod template;

View file

@ -8,8 +8,9 @@ use quote::quote;
use std::collections::HashSet;
use syn::{parse, Attribute, Ident};
// TODO: This should be feature gated
// pub use basepri::*;
#[cfg(feature = "cortex_m_basepri")]
pub use basepri::*;
#[cfg(feature = "cortex_m_source_masking")]
pub use source_masking::*;
/// Whether `name` is an exception with configurable priority
@ -29,7 +30,8 @@ fn is_exception(name: &Ident) -> bool {
)
}
pub mod source_masking {
#[cfg(feature = "cortex_m_source_masking")]
mod source_masking {
use super::*;
use std::collections::HashMap;
@ -87,14 +89,6 @@ pub mod source_masking {
));
}
// if uses_exceptions_with_resources {
// mod_app.push(quote!(
// #[doc(hidden)]
// #[allow(non_upper_case_globals)]
// const __rtic_internal_V6_ERROR: () = rtic::export::no_basepri_panic();
// ));
// }
quote!(
#(#cfgs)*
impl<'a> rtic::Mutex for #path<'a> {
@ -121,38 +115,12 @@ pub mod source_masking {
}
pub fn extra_assertions(_: &App, _: &SyntaxAnalysis) -> Vec<TokenStream2> {
// let device = &app.args.device;
// let no_basepri_checks: Vec<_> = app
// .hardware_tasks
// .iter()
// .filter_map(|(_, task)| {
// if !is_exception(&task.args.binds) {
// let interrupt_name = &task.args.binds;
// Some(quote!(
// if (#device::Interrupt::#interrupt_name as usize) >= (#chunks_name * 32) {
// ::core::panic!("An interrupt out of range is used while in armv6 or armv8m.base");
// }
// ))
// } else {
// None
// }
// })
// .collect();
// let const_check = quote! {
// const _CONST_CHECK: () = {
// #(#no_basepri_checks)*
// };
// let _ = _CONST_CHECK;
// };
// vec![const_check]
vec![]
}
}
pub mod basepri {
#[cfg(feature = "cortex_m_basepri")]
mod basepri {
use super::*;
/// Generates a `Mutex` implementation
@ -245,7 +213,7 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
stmts.push(quote!(
core.NVIC.set_priority(
#rt_err::#interrupt::#name,
rtic::export::logical2hw(#priority, #nvic_prio_bits),
rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits),
);
));
@ -272,7 +240,7 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
stmts.push(quote!(core.SCB.set_priority(
rtic::export::SystemHandler::#name,
rtic::export::logical2hw(#priority, #nvic_prio_bits),
rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits),
);));
}

View file

@ -2,7 +2,7 @@ use crate::syntax::{ast::App, Context};
use core::sync::atomic::{AtomicUsize, Ordering};
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::quote;
use syn::{Attribute, Ident, PatType};
use syn::{Ident, PatType};
const RTIC_INTERNAL: &str = "__rtic_internal";