Skip to content
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

Add new cortex-m-interrupt-number crate #488

Open
wants to merge 1 commit 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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change? What does cargo-semver-checks say? I'd have assumed it was the same trait exported with the same name, so it was OK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'll try and do some tests to check. The main scenarios I'm interested in are:

  • We release c-m-im and use/re-export it in cortex-m 0.7.8. A user updates to c-m 0.7.8 but keeps using their old PAC, which implements c-m's InterruptNumber. Does the PAC now actually implement c-m-im's trait (since it's re-exported) and therefore still work with c-m 0.7.8's NVIC?
  • We release c-m-im and a PAC updates to implement it directly, but a user's still using c-m 0.7.7 which requires the old trait, alongside the new version of the PAC. The PAC doesn't depend on a new c-m, so nothing would drive the user to update their lock file. Does the build now fail with the new PAC because the PAC's enum doesn't implement the trait that c-m wants for NVIC? Is a fix as simple as "cargo update", which might happen anyway when PAC is updated?


### 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
Loading