Skip to content

Commit ca73dc0

Browse files
committed
Add new cortex-m-interrupt-number crate
1 parent 0a701d6 commit ca73dc0

File tree

8 files changed

+46
-22
lines changed

8 files changed

+46
-22
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"cortex-m",
55
"cortex-m-rt",
66
"cortex-m-semihosting",
7+
"cortex-m-interrupt-number",
78
"panic-itm",
89
"panic-semihosting",
910
"testsuite",

cortex-m-interrupt-number/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "cortex-m-interrupt-number"
3+
version = "1.0.0"
4+
edition = "2021"
5+
categories = ["embedded", "hardware-support", "no-std"]
6+
description = "Shared trait for Cortex-M interrupt numbers"
7+
keywords = ["arm", "cortex-m", "register", "peripheral"]
8+
license = "MIT OR Apache-2.0"
9+
readme = "README.md"
10+
repository = "https://github.com/rust-embedded/cortex-m"
11+
12+
[dependencies]

cortex-m-interrupt-number/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# cortex-m-interrupt-number
2+
3+
This crate provides the definition of a trait that is shared between
4+
the `cortex-m` crate and all peripheral access crates (PACs) for
5+
Cortex-M microcontrollers.
6+
7+
The PACs must implement the `InterruptNumber` trait on an enum of possible
8+
interrupts; refer to the `InterruptNumber` [documentation] for more details.
9+
10+
[documentation]: https://docs.rs/cortex-m-interrupt-number

cortex-m-interrupt-number/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// Trait for enums of external interrupt numbers.
2+
///
3+
/// This trait should be implemented by a peripheral access crate (PAC)
4+
/// on its enum of available external interrupts for a specific device.
5+
/// Each variant must convert to a u16 of its interrupt number,
6+
/// which is its exception number - 16.
7+
///
8+
/// # Safety
9+
///
10+
/// This trait must only be implemented on enums of device interrupts. Each
11+
/// enum variant must represent a distinct value (no duplicates are permitted),
12+
/// and must always return the same value (do not change at runtime).
13+
///
14+
/// These requirements ensure safe nesting of critical sections.
15+
pub unsafe trait InterruptNumber: Copy {
16+
/// Return the interrupt number associated with this variant.
17+
///
18+
/// See trait documentation for safety requirements.
19+
fn number(self) -> u16;
20+
}

cortex-m/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Breaking changes
1111

1212
- `NVIC::request()` no longer requires `&mut self`.
13+
- `InterruptNumber` is now provided by the `cortex-m-interrupt-number` trait
1314

1415
### Added
1516
- Updated `SCB.ICSR.VECTACTIVE`/`SCB::vect_active()` to be 9 bits instead of 8.

cortex-m/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rust-version = "1.59"
1717
links = "cortex-m" # prevent multiple versions of this crate to be linked together
1818

1919
[dependencies]
20+
cortex-m-interrupt-number = "1.0.0"
2021
critical-section = "1.0.0"
2122
volatile-register = "0.2.0"
2223
bitfield = "0.13.2"

cortex-m/src/interrupt.rs

-21
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,6 @@ use core::arch::asm;
55
#[cfg(cortex_m)]
66
use core::sync::atomic::{compiler_fence, Ordering};
77

8-
/// Trait for enums of external interrupt numbers.
9-
///
10-
/// This trait should be implemented by a peripheral access crate (PAC)
11-
/// on its enum of available external interrupts for a specific device.
12-
/// Each variant must convert to a u16 of its interrupt number,
13-
/// which is its exception number - 16.
14-
///
15-
/// # Safety
16-
///
17-
/// This trait must only be implemented on enums of device interrupts. Each
18-
/// enum variant must represent a distinct value (no duplicates are permitted),
19-
/// and must always return the same value (do not change at runtime).
20-
///
21-
/// These requirements ensure safe nesting of critical sections.
22-
pub unsafe trait InterruptNumber: Copy {
23-
/// Return the interrupt number associated with this variant.
24-
///
25-
/// See trait documentation for safety requirements.
26-
fn number(self) -> u16;
27-
}
28-
298
/// Disables all interrupts in the current core.
309
#[cfg(cortex_m)]
3110
#[inline]

cortex-m/src/peripheral/nvic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use volatile_register::RW;
44
#[cfg(not(armv6m))]
55
use volatile_register::{RO, WO};
66

7-
use crate::interrupt::InterruptNumber;
7+
use cortex_m_interrupt_number::InterruptNumber;
88
use crate::peripheral::NVIC;
99

1010
/// Register block

0 commit comments

Comments
 (0)