Skip to content

Commit 7a1dbc8

Browse files
committed
rewrite NVIC to use derive-mmio
1 parent 9bbff92 commit 7a1dbc8

4 files changed

Lines changed: 162 additions & 108 deletions

File tree

‎cortex-m/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rust-version = "1.85"
1515
[dependencies]
1616
bare-metal = { version = "0.2.4", features = ["const-fn"] }
1717
critical-section = "1.0.0"
18+
derive-mmio = "0.8"
1819
volatile-register = "0.2.2"
1920
bitfield = "0.13.2"
2021
eh0 = { package = "embedded-hal", version = "0.2.4" }

‎cortex-m/src/peripheral/mod.rs‎

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub mod tpiu;
8787
#[cfg(test)]
8888
mod test;
8989

90+
pub use nvic::NVIC;
91+
9092
// NOTE the `PhantomData` used in the peripherals proxy is to make them `Send` but *not* `Sync`
9193

9294
/// Core peripherals
@@ -131,7 +133,7 @@ pub struct Peripherals {
131133
pub MPU: MPU,
132134

133135
/// Nested Vector Interrupt Controller
134-
pub NVIC: NVIC,
136+
pub NVIC: nvic::OwnedRegisterBlock<{ nvic::BASE_ADDRESS }>,
135137

136138
/// Security Attribution Unit
137139
pub SAU: SAU,
@@ -213,9 +215,7 @@ impl Peripherals {
213215
MPU: MPU {
214216
_marker: PhantomData,
215217
},
216-
NVIC: NVIC {
217-
_marker: PhantomData,
218-
},
218+
NVIC: nvic::OwnedRegisterBlock::new(),
219219
SAU: SAU {
220220
_marker: PhantomData,
221221
},
@@ -546,34 +546,6 @@ impl ops::Deref for MPU {
546546
}
547547
}
548548

549-
/// Nested Vector Interrupt Controller
550-
pub struct NVIC {
551-
_marker: PhantomData<*const ()>,
552-
}
553-
554-
unsafe impl Send for NVIC {}
555-
556-
impl NVIC {
557-
/// Pointer to the register block
558-
pub const PTR: *const nvic::RegisterBlock = 0xE000_E100 as *const _;
559-
560-
/// Returns a pointer to the register block
561-
#[inline(always)]
562-
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
563-
pub const fn ptr() -> *const nvic::RegisterBlock {
564-
Self::PTR
565-
}
566-
}
567-
568-
impl ops::Deref for NVIC {
569-
type Target = self::nvic::RegisterBlock;
570-
571-
#[inline(always)]
572-
fn deref(&self) -> &Self::Target {
573-
unsafe { &*Self::PTR }
574-
}
575-
}
576-
577549
/// Security Attribution Unit
578550
pub struct SAU {
579551
_marker: PhantomData<*const ()>,

0 commit comments

Comments
 (0)