Skip to content

Commit 278083a

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 08ef293 commit 278083a

File tree

3 files changed

+17
-69
lines changed

3 files changed

+17
-69
lines changed

src/generate/device.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
124124
if *target == Target::CortexM {
125125
out.push(quote! {
126126
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
127+
#[cfg(feature = "rt")]
128+
pub use cortex_m_rt::interrupt;
129+
pub use Interrupt as interrupt;
127130
});
128131

129132
if fpu_present {

src/generate/interrupt.rs

Lines changed: 8 additions & 66 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 => {
@@ -313,16 +255,16 @@ pub fn render(
313255
}
314256

315257
if !interrupts.is_empty() {
316-
root.push(quote! {
317-
#[doc(hidden)]
318-
pub mod interrupt {
319-
#(#mod_items)*
320-
}
321-
});
322-
323258
if *target != Target::CortexM {
324259
root.push(quote! {
325-
pub use self::interrupt::Interrupt;
260+
#[doc(hidden)]
261+
pub mod interrupt {
262+
#(#mod_items)*
263+
}
264+
});
265+
266+
root.push(quote! {
267+
pub use interrupt::Interrupt;
326268
});
327269
}
328270
}

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)