Skip to content

Commit 2dab852

Browse files
committed
re-export the interrupt attribute
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 have become an attribute.
1 parent 77ce4d5 commit 2dab852

File tree

3 files changed

+16
-68
lines changed

3 files changed

+16
-68
lines changed

src/generate/device.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
111111
if *target == Target::CortexM {
112112
out.push(quote! {
113113
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
114+
#[cfg(feature = "rt")]
115+
pub use cortex_m_rt::interrupt;
116+
pub use Interrupt as interrupt;
114117
});
115118

116119
out.push(quote! {

src/generate/interrupt.rs

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

311253
if interrupts.len() > 0 {
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 interrupt::Interrupt;
322264
});

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
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
56+
//! `bare-metal` v0.2.x, `cortex-m` v0.5.x, `cortex-m-rt` v0.6.x and `vcell` v0.1.x. Furthermore the
5757
//! "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]
@@ -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`]: TODO(add link here)
424427
//!
425428
//! ## the `--nightly` flag
426429
//!

0 commit comments

Comments
 (0)