Skip to content

re-export the interrupt attribute #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
if *target == Target::CortexM {
out.push(quote! {
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
#[cfg(feature = "rt")]
pub use cortex_m_rt::interrupt;
pub use self::Interrupt as interrupt;
});

if fpu_present {
Expand Down
72 changes: 7 additions & 65 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,64 +100,6 @@ pub fn render(
pub static __INTERRUPTS: [Vector; #n] = [
#(#elements,)*
];

/// Macro to override a device specific interrupt handler
///
/// # Syntax
///
/// ``` ignore
/// interrupt!(
/// // Name of the interrupt
/// $Name:ident,
///
/// // Path to the interrupt handler (a function)
/// $handler:path,
///
/// // Optional, state preserved across invocations of the handler
/// state: $State:ty = $initial_state:expr,
/// );
/// ```
///
/// Where `$Name` must match the name of one of the variants of the `Interrupt`
/// enum.
///
/// The handler must have signature `fn()` is no state was associated to it;
/// otherwise its signature must be `fn(&mut $State)`.
#[cfg(feature = "rt")]
#[macro_export]
macro_rules! interrupt {
($Name:ident, $handler:path,state: $State:ty = $initial_state:expr) => {
#[allow(unsafe_code)]
#[deny(private_no_mangle_fns)] // raise an error if this item is not accessible
#[no_mangle]
pub unsafe extern "C" fn $Name() {
static mut STATE: $State = $initial_state;

// check that this interrupt exists
let _ = $crate::Interrupt::$Name;

// validate the signature of the user provided handler
let f: fn(&mut $State) = $handler;

f(&mut STATE)
}
};

($Name:ident, $handler:path) => {
#[allow(unsafe_code)]
#[deny(private_no_mangle_fns)] // raise an error if this item is not accessible
#[no_mangle]
pub unsafe extern "C" fn $Name() {
// check that this interrupt exists
let _ = $crate::Interrupt::$Name;

// validate the signature of the user provided handler
let f: fn() = $handler;

f()
}
};
}
});
}
Target::Msp430 => {
Expand Down Expand Up @@ -313,14 +255,14 @@ pub fn render(
}

if !interrupts.is_empty() {
root.push(quote! {
#[doc(hidden)]
pub mod interrupt {
#(#mod_items)*
}
});

if *target != Target::CortexM {
root.push(quote! {
#[doc(hidden)]
pub mod interrupt {
#(#mod_items)*
}
});

root.push(quote! {
pub use self::interrupt::Interrupt;
});
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@
//! ```
//!
//! The resulting crate must provide an opt-in "rt" feature and depend on these crates:
//! `bare-metal` v0.2.x, `cortex-m` v0.5.x, `cortex-m-rt` v0.5.x and `vcell` v0.1.x. Furthermore the
//! "device" feature of `cortex-m-rt` must be enabled when the "rt" feature is enabled. The
//! `bare-metal` v0.2.x, `cortex-m` v0.5.x, `cortex-m-rt` >=v0.6.5 and `vcell` v0.1.x. Furthermore
//! the "device" feature of `cortex-m-rt` must be enabled when the "rt" feature is enabled. The
//! `Cargo.toml` of the device crate will look like this:
//!
//! ``` toml
//! [dependencies]
//! bare-metal = "0.2.0"
//! cortex-m = "0.5.0"
//! cortex-m = "0.6.4"
//! vcell = "0.1.0"
//!
//! [dependencies.cortex-m-rt]
//! optional = true
//! version = "0.5.0"
//! version = "0.6.5"
//!
//! [features]
//! rt = ["cortex-m-rt/device"]
Expand Down Expand Up @@ -420,7 +420,10 @@
//!
//! If the "rt" Cargo feature of the svd2rust generated crate is enabled the crate will populate the
//! part of the vector table that contains the interrupt vectors and provide an
//! [`interrupt!`](macro.interrupt.html) macro that can be used to register interrupt handlers.
//! [`interrupt!`](macro.interrupt.html) macro (non Cortex-M targets) or [`interrupt`] attribute
//! (Cortex-M) that can be used to register interrupt handlers.
//!
//! [`interrupt`]: https://docs.rs/cortex-m-rt-macros/0.1/cortex_m_rt_macros/attr.interrupt.html
//!
//! ## the `--nightly` flag
//!
Expand Down