Skip to content

Commit

Permalink
Add new cortex-m-interrupt-number crate
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgreig committed Oct 16, 2023
1 parent 7f6ff8f commit c058424
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"cortex-m",
"cortex-m-rt",
"cortex-m-semihosting",
"cortex-m-interrupt-number",
"panic-itm",
"panic-semihosting",
"testsuite",
Expand Down
12 changes: 12 additions & 0 deletions cortex-m-interrupt-number/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
10 changes: 10 additions & 0 deletions cortex-m-interrupt-number/README.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions cortex-m-interrupt-number/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions cortex-m/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cortex-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 0 additions & 21 deletions cortex-m/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion cortex-m/src/peripheral/nvic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit c058424

Please sign in to comment.