aboutsummaryrefslogtreecommitdiff
path: root/src/interrupt.rs
diff options
context:
space:
mode:
authorGravatar Adam Greig <adam@adamgreig.com> 2020-07-09 01:44:23 +0100
committerGravatar Adam Greig <adam@adamgreig.com> 2020-07-21 23:13:59 +0100
commitb5ad45c7409da165d4cdd24c7af29dadbe8eb6cb (patch)
tree825bae3028b9fce036166e1166e1425b24dcd760 /src/interrupt.rs
parent9021bcd85dd6364942dc20a7ad2e49c4600693b6 (diff)
downloadcortex-m-b5ad45c7409da165d4cdd24c7af29dadbe8eb6cb.tar.gz
cortex-m-b5ad45c7409da165d4cdd24c7af29dadbe8eb6cb.tar.zst
cortex-m-b5ad45c7409da165d4cdd24c7af29dadbe8eb6cb.zip
Add new InterruptNumber trait
Diffstat (limited to 'src/interrupt.rs')
-rw-r--r--src/interrupt.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/interrupt.rs b/src/interrupt.rs
index 4d5ef0f..c5da48d 100644
--- a/src/interrupt.rs
+++ b/src/interrupt.rs
@@ -1,8 +1,27 @@
//! Interrupts
-// use core::sync::atomic::{self, Ordering};
+pub use bare_metal::{CriticalSection, Mutex};
-pub use bare_metal::{CriticalSection, Mutex, Nr};
+/// 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
#[inline]