Skip to content

Refactor VectActive to Vector and pass it to DefaultHandler. #437

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions cortex-m-rt/examples/divergent-default-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -13,6 +13,6 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) -> ! {
unsafe fn DefaultHandler(_: Vector) -> ! {
loop {}
}
8 changes: 3 additions & 5 deletions cortex-m-rt/examples/override-exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt as rt;
extern crate panic_halt;

use cortex_m::asm;
use rt::{entry, exception, ExceptionFrame};
use cortex_m::{asm, peripheral::scb::Vector};
use cortex_m_rt::{entry, exception, ExceptionFrame};

#[entry]
fn main() -> ! {
loop {}
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {
unsafe fn DefaultHandler(_: Vector) {
asm::bkpt();
}

Expand Down
4 changes: 2 additions & 2 deletions cortex-m-rt/examples/unsafe-default-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -13,4 +13,4 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_: Vector) {}
4 changes: 2 additions & 2 deletions cortex-m-rt/examples/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception, ExceptionFrame};

#[entry]
Expand All @@ -17,7 +17,7 @@ unsafe fn main() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {
unsafe fn DefaultHandler(_: Vector) {
foo();
}

Expand Down
16 changes: 10 additions & 6 deletions cortex-m-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
&& f.vis == Visibility::Inherited
&& f.sig.abi.is_none()
&& f.sig.inputs.len() == 1
&& match &f.sig.inputs[0] {
FnArg::Typed(arg) => match arg.ty.as_ref() {
Type::Path(_) => true,
_ => false,
},
_ => false,
}
&& f.sig.generics.params.is_empty()
&& f.sig.generics.where_clause.is_none()
&& f.sig.variadic.is_none()
Expand All @@ -202,7 +209,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
if !valid_signature {
return parse::Error::new(
fspan,
"`DefaultHandler` must have signature `unsafe fn(i16) [-> !]`",
"`DefaultHandler` must have signature `unsafe fn(Vector) [-> !]`",
)
.to_compile_error()
.into();
Expand All @@ -222,11 +229,8 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
pub unsafe extern "C" fn #tramp_ident() {
extern crate core;

const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;

let irqn = unsafe { (core::ptr::read_volatile(SCB_ICSR) & 0x1FF) as i16 - 16 };

#ident(irqn)
let vect_active = ::cortex_m::peripheral::SCB::vect_active();
#ident(vect_active)
}

#f
Expand Down
5 changes: 3 additions & 2 deletions cortex-m-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,12 @@ pub use macros::entry;
/// - Setting the default handler
///
/// ```
/// use cortex_m::peripheral::scb::Vector;
/// use cortex_m_rt::exception;
///
/// #[exception]
/// unsafe fn DefaultHandler(irqn: i16) {
/// println!("IRQn = {}", irqn);
/// unsafe fn DefaultHandler(v: Vector) {
/// println!("Unexpected interrupt: {:?}", v);
/// }
///
/// # fn main() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,5 +14,5 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16, undef: u32) {}
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
unsafe fn DefaultHandler(_: Vector, _: u32) {}
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(Vector) [-> !]`
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,7 +14,7 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) -> u32 {
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
unsafe fn DefaultHandler(_: Vector) -> u32 {
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(Vector) [-> !]`
0
}
6 changes: 4 additions & 2 deletions cortex-m-rt/tests/compile-fail/default-handler-hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m_rt::{entry, exception};
use cortex_m_rt::entry;

#[entry]
fn foo() -> ! {
loop {}
}

mod hidden {
use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::exception;

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_: Vector) {}
}
7 changes: 5 additions & 2 deletions cortex-m-rt/tests/compile-fail/default-handler-twice.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,11 +14,12 @@ fn foo() -> ! {
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_: Vector) {}

pub mod reachable {
use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::exception;

#[exception] //~ ERROR symbol `DefaultHandler` is already defined
unsafe fn DefaultHandler(_irqn: i16) {}
unsafe fn DefaultHandler(_: Vector) {}
}
4 changes: 3 additions & 1 deletion cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception};

#[entry]
Expand All @@ -12,7 +14,7 @@ fn foo() -> ! {
}

#[exception]
fn DefaultHandler(_irq: i16) {}
fn DefaultHandler(_: Vector) {}
//~^ ERROR defining a `DefaultHandler` is unsafe and requires an `unsafe fn`

#[exception]
Expand Down
4 changes: 3 additions & 1 deletion cortex-m-rt/tests/compile-fail/unsafe-init-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m::peripheral::scb::Vector;
use cortex_m_rt::{entry, exception, interrupt};

#[allow(non_camel_case_types)]
Expand All @@ -29,7 +31,7 @@ fn SVCall() {
}

#[exception]
unsafe fn DefaultHandler(_irq: i16) {
unsafe fn DefaultHandler(_: Vector) {
static mut X: u32 = init(); //~ ERROR requires unsafe
}

Expand Down
Loading