diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b1f482..6f2ca0b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - Optimize case change/sanitize - Fix dangling implicit derives - Fix escaping <> and & characters in doc attributes +- Add `interrupt_link_section` config parameter for controlling the `#[link_section = "..."]` attribute of `__INTERRUPTS` ## [v0.28.0] - 2022-12-25 diff --git a/src/generate/interrupt.rs b/src/generate/interrupt.rs index 0f826f6a..92439ff7 100644 --- a/src/generate/interrupt.rs +++ b/src/generate/interrupt.rs @@ -118,6 +118,14 @@ pub fn render( writeln!(device_x, "PROVIDE({name} = DefaultHandler);")?; } + let link_section_name = config + .interrupt_link_section + .as_deref() + .unwrap_or(".vector_table.interrupts"); + let link_section_attr = quote! { + #[link_section = #link_section_name] + }; + root.extend(quote! { #[cfg(feature = "rt")] extern "C" { @@ -132,7 +140,7 @@ pub fn render( #[cfg(feature = "rt")] #[doc(hidden)] - #[link_section = ".vector_table.interrupts"] + #link_section_attr #[no_mangle] pub static __INTERRUPTS: [Vector; #n] = [ #elements @@ -144,6 +152,14 @@ pub fn render( writeln!(device_x, "PROVIDE({name} = DefaultHandler);").unwrap(); } + let link_section_name = config + .interrupt_link_section + .as_deref() + .unwrap_or(".vector_table.interrupts"); + let link_section_attr = quote! { + #[link_section = #link_section_name] + }; + root.extend(quote! { #[cfg(feature = "rt")] extern "msp430-interrupt" { @@ -158,7 +174,7 @@ pub fn render( #[cfg(feature = "rt")] #[doc(hidden)] - #[link_section = ".vector_table.interrupts"] + #link_section_attr #[no_mangle] #[used] pub static __INTERRUPTS: @@ -172,6 +188,12 @@ pub fn render( writeln!(device_x, "PROVIDE({name} = DefaultHandler);")?; } + let link_section_attr = config.interrupt_link_section.as_ref().map(|section| { + quote! { + #[link_section = #section] + } + }); + root.extend(quote! { #[cfg(feature = "rt")] extern "C" { @@ -186,6 +208,7 @@ pub fn render( #[cfg(feature = "rt")] #[doc(hidden)] + #link_section_attr #[no_mangle] pub static __EXTERNAL_INTERRUPTS: [Vector; #n] = [ #elements @@ -197,6 +220,12 @@ pub fn render( writeln!(device_x, "PROVIDE({name} = DefaultHandler);")?; } + let link_section_attr = config.interrupt_link_section.as_ref().map(|section| { + quote! { + #[link_section = #section] + } + }); + root.extend(quote! { #[cfg(feature = "rt")] extern "C" { @@ -210,6 +239,7 @@ pub fn render( } #[cfg(feature = "rt")] + #link_section_attr #[doc(hidden)] pub static __INTERRUPTS: [Vector; #n] = [ #elements diff --git a/src/util.rs b/src/util.rs index 1e295a80..fc58314c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -59,6 +59,8 @@ pub struct Config { pub source_type: SourceType, #[cfg_attr(feature = "serde", serde(default))] pub log_level: Option, + #[cfg_attr(feature = "serde", serde(default))] + pub interrupt_link_section: Option, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -120,6 +122,7 @@ impl Default for Config { input: None, source_type: SourceType::default(), log_level: None, + interrupt_link_section: None, } } } @@ -229,7 +232,7 @@ pub trait ToSanitizedCase { impl ToSanitizedCase for str { fn to_sanitized_pascal_case(&self) -> Cow { let s = Case::Pascal.sanitize(self); - if s.as_bytes().get(0).unwrap_or(&0).is_ascii_digit() { + if s.as_bytes().first().unwrap_or(&0).is_ascii_digit() { Cow::from(format!("_{}", s)) } else { s @@ -237,7 +240,7 @@ impl ToSanitizedCase for str { } fn to_sanitized_constant_case(&self) -> Cow { let s = Case::Constant.sanitize(self); - if s.as_bytes().get(0).unwrap_or(&0).is_ascii_digit() { + if s.as_bytes().first().unwrap_or(&0).is_ascii_digit() { Cow::from(format!("_{}", s)) } else { s @@ -247,7 +250,7 @@ impl ToSanitizedCase for str { const INTERNALS: [&str; 4] = ["set_bit", "clear_bit", "bit", "bits"]; let s = Case::Snake.sanitize(self); - if s.as_bytes().get(0).unwrap_or(&0).is_ascii_digit() { + if s.as_bytes().first().unwrap_or(&0).is_ascii_digit() { format!("_{}", s).into() } else if INTERNALS.contains(&s.as_ref()) { s + "_"