aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Greig <adam@adamgreig.com> 2023-10-16 01:45:58 +0100
committerGravatar Adam Greig <adam@adamgreig.com> 2023-10-16 20:21:40 +0100
commitc058424d2db14dca7b2be8d4fcb496e615e41abe (patch)
tree9c020ac7d45fe36e81c0cb0669fa3dae559de446
parent7f6ff8fb72eb333344c02147c06e7dc6801870c3 (diff)
downloadcortex-m-c-m-in.tar.gz
cortex-m-c-m-in.tar.zst
cortex-m-c-m-in.zip
Add new cortex-m-interrupt-number cratec-m-in
-rw-r--r--Cargo.toml1
-rw-r--r--cortex-m-interrupt-number/Cargo.toml12
-rw-r--r--cortex-m-interrupt-number/README.md10
-rw-r--r--cortex-m-interrupt-number/src/lib.rs22
-rw-r--r--cortex-m/CHANGELOG.md1
-rw-r--r--cortex-m/Cargo.toml1
-rw-r--r--cortex-m/src/interrupt.rs21
-rw-r--r--cortex-m/src/peripheral/nvic.rs2
8 files changed, 48 insertions, 22 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 059853a..4d32d3c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,7 @@ members = [
"cortex-m",
"cortex-m-rt",
"cortex-m-semihosting",
+ "cortex-m-interrupt-number",
"panic-itm",
"panic-semihosting",
"testsuite",
diff --git a/cortex-m-interrupt-number/Cargo.toml b/cortex-m-interrupt-number/Cargo.toml
new file mode 100644
index 0000000..bcc16e5
--- /dev/null
+++ b/cortex-m-interrupt-number/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "cortex-m-interrupt-number"
+version = "1.0.0"
+edition = "2021"
+categories = ["embedded", "hardware-support", "no-std"]
+description = "Shared trait for Cortex-M interrupt numbers"
+keywords = ["arm", "cortex-m", "register", "peripheral"]
+license = "MIT OR Apache-2.0"
+readme = "README.md"
+repository = "https://github.com/rust-embedded/cortex-m"
+
+[dependencies]
diff --git a/cortex-m-interrupt-number/README.md b/cortex-m-interrupt-number/README.md
new file mode 100644
index 0000000..fa5c89b
--- /dev/null
+++ b/cortex-m-interrupt-number/README.md
@@ -0,0 +1,10 @@
+# cortex-m-interrupt-number
+
+This crate provides the definition of a trait that is shared between
+the `cortex-m` crate and all peripheral access crates (PACs) for
+Cortex-M microcontrollers.
+
+The PACs must implement the `InterruptNumber` trait on an enum of possible
+interrupts; refer to the `InterruptNumber` [documentation] for more details.
+
+[documentation]: https://docs.rs/cortex-m-interrupt-number
diff --git a/cortex-m-interrupt-number/src/lib.rs b/cortex-m-interrupt-number/src/lib.rs
new file mode 100644
index 0000000..aa5d099
--- /dev/null
+++ b/cortex-m-interrupt-number/src/lib.rs
@@ -0,0 +1,22 @@
+#![no_std]
+
+/// Trait for enums of external interrupt numbers.
+///
+/// This trait should be implemented by a peripheral access crate (PAC)
+/// on its enum of available external interrupts for a specific device.
+/// Each variant must convert to a u16 of its interrupt number,
+/// which is its exception number - 16.
+///
+/// # Safety
+///
+/// This trait must only be implemented on enums of device interrupts. Each
+/// enum variant must represent a distinct value (no duplicates are permitted),
+/// and must always return the same value (do not change at runtime).
+///
+/// These requirements ensure safe nesting of critical sections.
+pub unsafe trait InterruptNumber: Copy {
+ /// Return the interrupt number associated with this variant.
+ ///
+ /// See trait documentation for safety requirements.
+ fn number(self) -> u16;
+}
diff --git a/cortex-m/CHANGELOG.md b/cortex-m/CHANGELOG.md
index db2827f..74e05cd 100644
--- a/cortex-m/CHANGELOG.md
+++ b/cortex-m/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Breaking changes
- `NVIC::request()` no longer requires `&mut self`.
+- `InterruptNumber` is now provided by the `cortex-m-interrupt-number` trait
### Added
- Updated `SCB.ICSR.VECTACTIVE`/`SCB::vect_active()` to be 9 bits instead of 8.
diff --git a/cortex-m/Cargo.toml b/cortex-m/Cargo.toml
index cdd63bd..74d7fc1 100644
--- a/cortex-m/Cargo.toml
+++ b/cortex-m/Cargo.toml
@@ -17,6 +17,7 @@ rust-version = "1.59"
links = "cortex-m" # prevent multiple versions of this crate to be linked together
[dependencies]
+cortex-m-interrupt-number = { version = "1.0.0", path = "../cortex-m-interrupt-number" }
critical-section = "1.0.0"
volatile-register = "0.2.0"
bitfield = "0.13.2"
diff --git a/cortex-m/src/interrupt.rs b/cortex-m/src/interrupt.rs
index f6ce990..2610bf6 100644
--- a/cortex-m/src/interrupt.rs
+++ b/cortex-m/src/interrupt.rs
@@ -5,27 +5,6 @@ use core::arch::asm;
#[cfg(cortex_m)]
use core::sync::atomic::{compiler_fence, Ordering};
-/// Trait for enums of external interrupt numbers.
-///
-/// This trait should be implemented by a peripheral access crate (PAC)
-/// on its enum of available external interrupts for a specific device.
-/// Each variant must convert to a u16 of its interrupt number,
-/// which is its exception number - 16.
-///
-/// # Safety
-///
-/// This trait must only be implemented on enums of device interrupts. Each
-/// enum variant must represent a distinct value (no duplicates are permitted),
-/// and must always return the same value (do not change at runtime).
-///
-/// These requirements ensure safe nesting of critical sections.
-pub unsafe trait InterruptNumber: Copy {
- /// Return the interrupt number associated with this variant.
- ///
- /// See trait documentation for safety requirements.
- fn number(self) -> u16;
-}
-
/// Disables all interrupts in the current core.
#[cfg(cortex_m)]
#[inline]
diff --git a/cortex-m/src/peripheral/nvic.rs b/cortex-m/src/peripheral/nvic.rs
index fccd6a2..01f53e7 100644
--- a/cortex-m/src/peripheral/nvic.rs
+++ b/cortex-m/src/peripheral/nvic.rs
@@ -4,8 +4,8 @@ use volatile_register::RW;
#[cfg(not(armv6m))]
use volatile_register::{RO, WO};
-use crate::interrupt::InterruptNumber;
use crate::peripheral::NVIC;
+use cortex_m_interrupt_number::InterruptNumber;
/// Register block
#[repr(C)]