diff options
author | 2018-10-09 20:48:49 +0000 | |
---|---|---|
committer | 2018-10-09 20:48:49 +0000 | |
commit | 777d73402600ebb6498255493cc04bc2fad4c864 (patch) | |
tree | 1c21d49626d101f90fe9a89b48a2a0220b05d5e2 /cortex-m-rt/tests/compile-fail/interrupt-invalid.rs | |
parent | 0423076f192a07d1aeba2721d549c4359ff283ae (diff) | |
parent | 7e583e2abf261910ed1a7778b07b72c1a7d97e3b (diff) | |
download | cortex-m-777d73402600ebb6498255493cc04bc2fad4c864.tar.gz cortex-m-777d73402600ebb6498255493cc04bc2fad4c864.tar.zst cortex-m-777d73402600ebb6498255493cc04bc2fad4c864.zip |
Merge #122
122: [RFC] `#[interrupt]` r=therealprof a=japaric
this PR adds an `interrupt` attribute that's similar to the existing `exception`
except that it's used to override device-specific interrupt handlers.
The other big difference is that `cortex_m_rt::interrupt` can't be directly
used; it must first be imported from a device crate, which re-exports
`cortex_m_rt::interrupt`. This is required to check at compile time that the
interrupt is valid for the target device.
Safe `static mut` variables can be used with `#[interrupt]` handlers. The syntax
is the same as `#[exception]`s.
More background information can be found in #109.
The companion svd2rust PR is rust-embedded/svd2rust#235
r? @rust-embedded/cortex-m
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Co-authored-by: Adam Greig <adam@adamgreig.com>
Diffstat (limited to 'cortex-m-rt/tests/compile-fail/interrupt-invalid.rs')
-rw-r--r-- | cortex-m-rt/tests/compile-fail/interrupt-invalid.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs b/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs new file mode 100644 index 0000000..4e79e7d --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs @@ -0,0 +1,21 @@ +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_halt; + +use cortex_m_rt::{entry, interrupt}; + +#[entry] +fn foo() -> ! { + loop {} +} + +enum interrupt { + USART1, +} + +// NOTE this looks a bit better when using a device crate: +// "no variant named `foo` found for type `stm32f30x::Interrupt` in the current scope" +#[interrupt] //~ ERROR no variant named `foo` found for type `interrupt` in the current scope +fn foo() {} |