Skip to content

Commit 1992346

Browse files
committed
use cortex-m-types in NVIC
1 parent d232aaf commit 1992346

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

cortex-m/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ bitfield = "0.13.2"
2020
eh0 = { package = "embedded-hal", version = "0.2.4" }
2121
eh1 = { package = "embedded-hal", version = "1.0.0" }
2222
cortex-m-macros = { path = "macros", version = "=0.1.0" }
23+
cortex-m-types = { path = "../cortex-m-types", version = "0.1" }
2324

2425
[dependencies.serde]
2526
version = "1"

cortex-m/src/interrupt.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ use cortex_m_macros::asm_cfg;
2121
/// and must always return the same value (do not change at runtime).
2222
///
2323
/// These requirements ensure safe nesting of critical sections.
24+
#[deprecated(
25+
since = "0.7.8",
26+
note = "Implement the cortex_m_types::InterruptNumber trait instead"
27+
)]
2428
pub unsafe trait InterruptNumber: Copy {
2529
/// Return the interrupt number associated with this variant.
2630
///
2731
/// See trait documentation for safety requirements.
2832
fn number(self) -> u16;
2933
}
3034

31-
/// Implement InterruptNumber for the old bare_metal::Nr trait.
32-
/// This implementation is for backwards compatibility only and will be removed in cortex-m 0.8.
33-
unsafe impl<T: Nr + Copy> InterruptNumber for T {
35+
// This trait is only here for backwards compatibility.
36+
#[allow(deprecated)]
37+
unsafe impl<T: cortex_m_types::InterruptNumber> InterruptNumber for T {
3438
#[inline]
3539
fn number(self) -> u16 {
36-
self.nr() as u16
40+
<Self as cortex_m_types::InterruptNumber>::number(self) as u16
3741
}
3842
}
3943

cortex-m/src/peripheral/nvic.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Nested Vector Interrupt Controller
22
3+
use cortex_m_types::InterruptNumber;
34
use volatile_register::RW;
45
#[cfg(not(armv6m))]
56
use volatile_register::{RO, WO};
67

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

1010
/// Register block
@@ -101,7 +101,7 @@ impl NVIC {
101101
let nr = interrupt.number();
102102

103103
unsafe {
104-
self.stir.write(u32::from(nr));
104+
self.stir.write(nr as u32);
105105
}
106106
}
107107

@@ -113,7 +113,7 @@ impl NVIC {
113113
{
114114
let nr = interrupt.number();
115115
// NOTE(unsafe) this is a write to a stateless register
116-
unsafe { (*Self::PTR).icer[usize::from(nr / 32)].write(1 << (nr % 32)) }
116+
unsafe { (*Self::PTR).icer[nr / 32].write(1 << (nr % 32)) }
117117
}
118118

119119
/// Enables `interrupt`
@@ -127,7 +127,7 @@ impl NVIC {
127127
unsafe {
128128
let nr = interrupt.number();
129129
// NOTE(ptr) this is a write to a stateless register
130-
(*Self::PTR).iser[usize::from(nr / 32)].write(1 << (nr % 32))
130+
(*Self::PTR).iser[nr / 32].write(1 << (nr % 32))
131131
}
132132
}
133133

@@ -145,7 +145,7 @@ impl NVIC {
145145
{
146146
let nr = interrupt.number();
147147
// NOTE(unsafe) atomic read with no side effects
148-
unsafe { (*Self::PTR).ipr[usize::from(nr)].read() }
148+
unsafe { (*Self::PTR).ipr[nr].read() }
149149
}
150150

151151
#[cfg(armv6m)]
@@ -168,7 +168,7 @@ impl NVIC {
168168
let mask = 1 << (nr % 32);
169169

170170
// NOTE(unsafe) atomic read with no side effects
171-
unsafe { ((*Self::PTR).iabr[usize::from(nr / 32)].read() & mask) == mask }
171+
unsafe { ((*Self::PTR).iabr[nr / 32].read() & mask) == mask }
172172
}
173173

174174
/// Checks if `interrupt` is enabled
@@ -181,7 +181,7 @@ impl NVIC {
181181
let mask = 1 << (nr % 32);
182182

183183
// NOTE(unsafe) atomic read with no side effects
184-
unsafe { ((*Self::PTR).iser[usize::from(nr / 32)].read() & mask) == mask }
184+
unsafe { ((*Self::PTR).iser[nr / 32].read() & mask) == mask }
185185
}
186186

187187
/// Checks if `interrupt` is pending
@@ -194,7 +194,7 @@ impl NVIC {
194194
let mask = 1 << (nr % 32);
195195

196196
// NOTE(unsafe) atomic read with no side effects
197-
unsafe { ((*Self::PTR).ispr[usize::from(nr / 32)].read() & mask) == mask }
197+
unsafe { ((*Self::PTR).ispr[nr / 32].read() & mask) == mask }
198198
}
199199

200200
/// Forces `interrupt` into pending state
@@ -206,7 +206,7 @@ impl NVIC {
206206
let nr = interrupt.number();
207207

208208
// NOTE(unsafe) atomic stateless write; ICPR doesn't store any state
209-
unsafe { (*Self::PTR).ispr[usize::from(nr / 32)].write(1 << (nr % 32)) }
209+
unsafe { (*Self::PTR).ispr[nr / 32].write(1 << (nr % 32)) }
210210
}
211211

212212
/// Sets the "priority" of `interrupt` to `prio`
@@ -230,7 +230,7 @@ impl NVIC {
230230
#[cfg(not(armv6m))]
231231
{
232232
let nr = interrupt.number();
233-
self.ipr[usize::from(nr)].write(prio)
233+
self.ipr[nr].write(prio)
234234
}
235235

236236
#[cfg(armv6m)]
@@ -254,7 +254,7 @@ impl NVIC {
254254
let nr = interrupt.number();
255255

256256
// NOTE(unsafe) atomic stateless write; ICPR doesn't store any state
257-
unsafe { (*Self::PTR).icpr[usize::from(nr / 32)].write(1 << (nr % 32)) }
257+
unsafe { (*Self::PTR).icpr[nr / 32].write(1 << (nr % 32)) }
258258
}
259259

260260
#[cfg(armv6m)]
@@ -263,7 +263,7 @@ impl NVIC {
263263
where
264264
I: InterruptNumber,
265265
{
266-
usize::from(interrupt.number()) / 4
266+
interrupt.number() / 4
267267
}
268268

269269
#[cfg(armv6m)]
@@ -272,6 +272,6 @@ impl NVIC {
272272
where
273273
I: InterruptNumber,
274274
{
275-
(usize::from(interrupt.number()) % 4) * 8
275+
(interrupt.number() % 4) * 8
276276
}
277277
}

0 commit comments

Comments
 (0)