Skip to content

Commit 51d76e6

Browse files
bors[bot]japaric
andcommitted
Merge #235
235: re-export the `interrupt` attribute r=therealprof a=japaric this is a breaking change because - it bumps the cortex-m-rt version requirement to v0.6.4 - it changes the behavior of the `<device>::interrupt` item. This item was a bang macro and now has become an attribute. Co-authored-by: Jorge Aparicio <[email protected]>
2 parents ad49671 + 347abeb commit 51d76e6

File tree

3 files changed

+18
-70
lines changed

3 files changed

+18
-70
lines changed

src/generate/device.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
117117
if *target == Target::CortexM {
118118
out.push(quote! {
119119
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
120+
#[cfg(feature = "rt")]
121+
pub use cortex_m_rt::interrupt;
122+
pub use self::Interrupt as interrupt;
120123
});
121124

122125
if fpu_present {

src/generate/interrupt.rs

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -100,64 +100,6 @@ pub fn render(
100100
pub static __INTERRUPTS: [Vector; #n] = [
101101
#(#elements,)*
102102
];
103-
104-
/// Macro to override a device specific interrupt handler
105-
///
106-
/// # Syntax
107-
///
108-
/// ``` ignore
109-
/// interrupt!(
110-
/// // Name of the interrupt
111-
/// $Name:ident,
112-
///
113-
/// // Path to the interrupt handler (a function)
114-
/// $handler:path,
115-
///
116-
/// // Optional, state preserved across invocations of the handler
117-
/// state: $State:ty = $initial_state:expr,
118-
/// );
119-
/// ```
120-
///
121-
/// Where `$Name` must match the name of one of the variants of the `Interrupt`
122-
/// enum.
123-
///
124-
/// The handler must have signature `fn()` is no state was associated to it;
125-
/// otherwise its signature must be `fn(&mut $State)`.
126-
#[cfg(feature = "rt")]
127-
#[macro_export]
128-
macro_rules! interrupt {
129-
($Name:ident, $handler:path,state: $State:ty = $initial_state:expr) => {
130-
#[allow(unsafe_code)]
131-
#[deny(private_no_mangle_fns)] // raise an error if this item is not accessible
132-
#[no_mangle]
133-
pub unsafe extern "C" fn $Name() {
134-
static mut STATE: $State = $initial_state;
135-
136-
// check that this interrupt exists
137-
let _ = $crate::Interrupt::$Name;
138-
139-
// validate the signature of the user provided handler
140-
let f: fn(&mut $State) = $handler;
141-
142-
f(&mut STATE)
143-
}
144-
};
145-
146-
($Name:ident, $handler:path) => {
147-
#[allow(unsafe_code)]
148-
#[deny(private_no_mangle_fns)] // raise an error if this item is not accessible
149-
#[no_mangle]
150-
pub unsafe extern "C" fn $Name() {
151-
// check that this interrupt exists
152-
let _ = $crate::Interrupt::$Name;
153-
154-
// validate the signature of the user provided handler
155-
let f: fn() = $handler;
156-
157-
f()
158-
}
159-
};
160-
}
161103
});
162104
}
163105
Target::Msp430 => {
@@ -309,14 +251,14 @@ pub fn render(
309251
}
310252

311253
if !interrupts.is_empty() {
312-
root.push(quote! {
313-
#[doc(hidden)]
314-
pub mod interrupt {
315-
#(#mod_items)*
316-
}
317-
});
318-
319254
if *target != Target::CortexM {
255+
root.push(quote! {
256+
#[doc(hidden)]
257+
pub mod interrupt {
258+
#(#mod_items)*
259+
}
260+
});
261+
320262
root.push(quote! {
321263
pub use self::interrupt::Interrupt;
322264
});

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@
5353
//! ```
5454
//!
5555
//! The resulting crate must provide an opt-in "rt" feature and depend on these crates:
56-
//! `bare-metal` v0.2.x, `cortex-m` v0.5.x, `cortex-m-rt` v0.5.x and `vcell` v0.1.x. Furthermore the
57-
//! "device" feature of `cortex-m-rt` must be enabled when the "rt" feature is enabled. The
56+
//! `bare-metal` v0.2.x, `cortex-m` v0.5.x, `cortex-m-rt` >=v0.6.5 and `vcell` v0.1.x. Furthermore
57+
//! the "device" feature of `cortex-m-rt` must be enabled when the "rt" feature is enabled. The
5858
//! `Cargo.toml` of the device crate will look like this:
5959
//!
6060
//! ``` toml
6161
//! [dependencies]
6262
//! bare-metal = "0.2.0"
63-
//! cortex-m = "0.5.0"
63+
//! cortex-m = "0.6.4"
6464
//! vcell = "0.1.0"
6565
//!
6666
//! [dependencies.cortex-m-rt]
6767
//! optional = true
68-
//! version = "0.5.0"
68+
//! version = "0.6.5"
6969
//!
7070
//! [features]
7171
//! rt = ["cortex-m-rt/device"]
@@ -420,7 +420,10 @@
420420
//!
421421
//! If the "rt" Cargo feature of the svd2rust generated crate is enabled the crate will populate the
422422
//! part of the vector table that contains the interrupt vectors and provide an
423-
//! [`interrupt!`](macro.interrupt.html) macro that can be used to register interrupt handlers.
423+
//! [`interrupt!`](macro.interrupt.html) macro (non Cortex-M targets) or [`interrupt`] attribute
424+
//! (Cortex-M) that can be used to register interrupt handlers.
425+
//!
426+
//! [`interrupt`]: https://docs.rs/cortex-m-rt-macros/0.1/cortex_m_rt_macros/attr.interrupt.html
424427
//!
425428
//! ## the `--nightly` flag
426429
//!

0 commit comments

Comments
 (0)