Skip to content

Commit b581ec7

Browse files
bors[bot]TDHolmes
andauthored
Merge #386
386: deprecate `ptr()` function for the v0.7.x series r=adamgreig a=TDHolmes Deprecating `ptr()` in `v0.7.x` series per #370 Co-authored-by: Tyler Holmes <[email protected]>
2 parents 2e2cb78 + f8e17d8 commit b581ec7

File tree

12 files changed

+96
-74
lines changed

12 files changed

+96
-74
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Deprecated
11+
- the `ptr()` function on all peripherals register blocks in favor of
12+
the associated constant `PTR` (#386).
13+
1014
## [v0.7.4] - 2021-12-31
1115

1216
### Added

panic-itm/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- changed `ITM::ptr()` to `ITM::PTR` as the `ptr()` functions are
11+
deprecated (#386).
12+
1013
## [v0.4.2] - 2020-11-14
1114

1215
- Support cortex-m v0.7.0

panic-itm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use cortex_m::peripheral::ITM;
4646
fn panic(info: &PanicInfo) -> ! {
4747
interrupt::disable();
4848

49-
let itm = unsafe { &mut *ITM::ptr() };
49+
let itm = unsafe { &mut *ITM::PTR };
5050
let stim = &mut itm.stim[0];
5151

5252
iprintln!(stim, "{}", info);

src/itm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub fn write_all(port: &mut Stim, buffer: &[u8]) {
128128
///
129129
/// ```no_run
130130
/// # use cortex_m::{itm::{self, Aligned}, peripheral::ITM};
131-
/// # let port = unsafe { &mut (*ITM::ptr()).stim[0] };
131+
/// # let port = unsafe { &mut (*ITM::PTR).stim[0] };
132132
/// let mut buffer = Aligned([0; 14]);
133133
///
134134
/// buffer.0.copy_from_slice(b"Hello, world!\n");

src/peripheral/cpuid.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl CPUID {
122122
pub fn cache_dminline() -> u32 {
123123
const CTR_DMINLINE_POS: u32 = 16;
124124
const CTR_DMINLINE_MASK: u32 = 0xF << CTR_DMINLINE_POS;
125-
let ctr = unsafe { (*Self::ptr()).ctr.read() };
125+
let ctr = unsafe { (*Self::PTR).ctr.read() };
126126
(ctr & CTR_DMINLINE_MASK) >> CTR_DMINLINE_POS
127127
}
128128

@@ -134,7 +134,7 @@ impl CPUID {
134134
pub fn cache_iminline() -> u32 {
135135
const CTR_IMINLINE_POS: u32 = 0;
136136
const CTR_IMINLINE_MASK: u32 = 0xF << CTR_IMINLINE_POS;
137-
let ctr = unsafe { (*Self::ptr()).ctr.read() };
137+
let ctr = unsafe { (*Self::PTR).ctr.read() };
138138
(ctr & CTR_IMINLINE_MASK) >> CTR_IMINLINE_POS
139139
}
140140
}

src/peripheral/dcb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl DCB {
5353
pub fn is_debugger_attached() -> bool {
5454
unsafe {
5555
// do an 8-bit read of the 32-bit DHCSR register, and get the LSB
56-
let value = ptr::read_volatile(Self::ptr() as *const u8);
56+
let value = ptr::read_volatile(Self::PTR as *const u8);
5757
value & 0x1 == 1
5858
}
5959
}

src/peripheral/dwt.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,39 @@ impl DWT {
7777
#[inline]
7878
pub fn num_comp() -> u8 {
7979
// NOTE(unsafe) atomic read with no side effects
80-
unsafe { ((*Self::ptr()).ctrl.read() >> NUMCOMP_OFFSET) as u8 }
80+
unsafe { ((*Self::PTR).ctrl.read() >> NUMCOMP_OFFSET) as u8 }
8181
}
8282

8383
/// Returns `true` if the the implementation supports sampling and exception tracing
8484
#[cfg(not(armv6m))]
8585
#[inline]
8686
pub fn has_exception_trace() -> bool {
8787
// NOTE(unsafe) atomic read with no side effects
88-
unsafe { (*Self::ptr()).ctrl.read() & NOTRCPKT == 0 }
88+
unsafe { (*Self::PTR).ctrl.read() & NOTRCPKT == 0 }
8989
}
9090

9191
/// Returns `true` if the implementation includes external match signals
9292
#[cfg(not(armv6m))]
9393
#[inline]
9494
pub fn has_external_match() -> bool {
9595
// NOTE(unsafe) atomic read with no side effects
96-
unsafe { (*Self::ptr()).ctrl.read() & NOEXTTRIG == 0 }
96+
unsafe { (*Self::PTR).ctrl.read() & NOEXTTRIG == 0 }
9797
}
9898

9999
/// Returns `true` if the implementation supports a cycle counter
100100
#[cfg(not(armv6m))]
101101
#[inline]
102102
pub fn has_cycle_counter() -> bool {
103103
// NOTE(unsafe) atomic read with no side effects
104-
unsafe { (*Self::ptr()).ctrl.read() & NOCYCCNT == 0 }
104+
unsafe { (*Self::PTR).ctrl.read() & NOCYCCNT == 0 }
105105
}
106106

107107
/// Returns `true` if the implementation the profiling counters
108108
#[cfg(not(armv6m))]
109109
#[inline]
110110
pub fn has_profiling_counter() -> bool {
111111
// NOTE(unsafe) atomic read with no side effects
112-
unsafe { (*Self::ptr()).ctrl.read() & NOPRFCNT == 0 }
112+
unsafe { (*Self::PTR).ctrl.read() & NOPRFCNT == 0 }
113113
}
114114

115115
/// Enables the cycle counter
@@ -138,7 +138,7 @@ impl DWT {
138138
#[inline]
139139
pub fn cycle_counter_enabled() -> bool {
140140
// NOTE(unsafe) atomic read with no side effects
141-
unsafe { (*Self::ptr()).ctrl.read() & CYCCNTENA != 0 }
141+
unsafe { (*Self::PTR).ctrl.read() & CYCCNTENA != 0 }
142142
}
143143

144144
/// Returns the current clock cycle count
@@ -157,7 +157,7 @@ impl DWT {
157157
#[inline]
158158
pub fn cycle_count() -> u32 {
159159
// NOTE(unsafe) atomic read with no side effects
160-
unsafe { (*Self::ptr()).cyccnt.read() }
160+
unsafe { (*Self::PTR).cyccnt.read() }
161161
}
162162

163163
/// Set the cycle count
@@ -174,7 +174,7 @@ impl DWT {
174174
#[inline]
175175
pub fn unlock() {
176176
// NOTE(unsafe) atomic write to a stateless, write-only register
177-
unsafe { (*Self::ptr()).lar.write(0xC5AC_CE55) }
177+
unsafe { (*Self::PTR).lar.write(0xC5AC_CE55) }
178178
}
179179

180180
/// Get the CPI count
@@ -188,7 +188,7 @@ impl DWT {
188188
#[inline]
189189
pub fn cpi_count() -> u8 {
190190
// NOTE(unsafe) atomic read with no side effects
191-
unsafe { (*Self::ptr()).cpicnt.read() as u8 }
191+
unsafe { (*Self::PTR).cpicnt.read() as u8 }
192192
}
193193

194194
/// Set the CPI count
@@ -203,7 +203,7 @@ impl DWT {
203203
#[inline]
204204
pub fn exception_count() -> u8 {
205205
// NOTE(unsafe) atomic read with no side effects
206-
unsafe { (*Self::ptr()).exccnt.read() as u8 }
206+
unsafe { (*Self::PTR).exccnt.read() as u8 }
207207
}
208208

209209
/// Set the exception count
@@ -224,7 +224,7 @@ impl DWT {
224224
#[inline]
225225
pub fn sleep_count() -> u8 {
226226
// NOTE(unsafe) atomic read with no side effects
227-
unsafe { (*Self::ptr()).sleepcnt.read() as u8 }
227+
unsafe { (*Self::PTR).sleepcnt.read() as u8 }
228228
}
229229

230230
/// Set the sleep count
@@ -239,7 +239,7 @@ impl DWT {
239239
#[inline]
240240
pub fn lsu_count() -> u8 {
241241
// NOTE(unsafe) atomic read with no side effects
242-
unsafe { (*Self::ptr()).lsucnt.read() as u8 }
242+
unsafe { (*Self::PTR).lsucnt.read() as u8 }
243243
}
244244

245245
/// Set the lsu count
@@ -256,7 +256,7 @@ impl DWT {
256256
#[inline]
257257
pub fn fold_count() -> u8 {
258258
// NOTE(unsafe) atomic read with no side effects
259-
unsafe { (*Self::ptr()).foldcnt.read() as u8 }
259+
unsafe { (*Self::PTR).foldcnt.read() as u8 }
260260
}
261261

262262
/// Set the folded instruction count

src/peripheral/mod.rs

+31-16
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
//! } // all the peripheral singletons are destroyed here
5151
//!
5252
//! // actually safe because this is an atomic read with no side effects
53-
//! let cyccnt = unsafe { (*DWT::ptr()).cyccnt.read() };
53+
//! let cyccnt = unsafe { (*DWT::PTR).cyccnt.read() };
5454
//! ```
5555
//!
5656
//! # References
@@ -245,8 +245,9 @@ impl AC {
245245
/// Pointer to the register block
246246
pub const PTR: *const self::ac::RegisterBlock = 0xE000_EF90 as *const _;
247247

248-
/// Returns a pointer to the register block (to be deprecated in 0.7)
248+
/// Returns a pointer to the register block
249249
#[inline(always)]
250+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
250251
pub const fn ptr() -> *const self::ac::RegisterBlock {
251252
Self::PTR
252253
}
@@ -271,8 +272,9 @@ impl CBP {
271272
/// Pointer to the register block
272273
pub const PTR: *const self::cbp::RegisterBlock = 0xE000_EF50 as *const _;
273274

274-
/// Returns a pointer to the register block (to be deprecated in 0.7)
275+
/// Returns a pointer to the register block
275276
#[inline(always)]
277+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
276278
pub const fn ptr() -> *const self::cbp::RegisterBlock {
277279
Self::PTR
278280
}
@@ -299,8 +301,9 @@ impl CPUID {
299301
/// Pointer to the register block
300302
pub const PTR: *const self::cpuid::RegisterBlock = 0xE000_ED00 as *const _;
301303

302-
/// Returns a pointer to the register block (to be deprecated in 0.7)
304+
/// Returns a pointer to the register block
303305
#[inline(always)]
306+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
304307
pub const fn ptr() -> *const self::cpuid::RegisterBlock {
305308
Self::PTR
306309
}
@@ -326,8 +329,9 @@ impl DCB {
326329
/// Pointer to the register block
327330
pub const PTR: *const dcb::RegisterBlock = 0xE000_EDF0 as *const _;
328331

329-
/// Returns a pointer to the register block (to be deprecated in 0.7)
332+
/// Returns a pointer to the register block
330333
#[inline(always)]
334+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
331335
pub const fn ptr() -> *const dcb::RegisterBlock {
332336
Self::PTR
333337
}
@@ -353,8 +357,9 @@ impl DWT {
353357
/// Pointer to the register block
354358
pub const PTR: *const dwt::RegisterBlock = 0xE000_1000 as *const _;
355359

356-
/// Returns a pointer to the register block (to be deprecated in 0.7)
360+
/// Returns a pointer to the register block
357361
#[inline(always)]
362+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
358363
pub const fn ptr() -> *const dwt::RegisterBlock {
359364
Self::PTR
360365
}
@@ -381,8 +386,9 @@ impl FPB {
381386
/// Pointer to the register block
382387
pub const PTR: *const fpb::RegisterBlock = 0xE000_2000 as *const _;
383388

384-
/// Returns a pointer to the register block (to be deprecated in 0.7)
389+
/// Returns a pointer to the register block
385390
#[inline(always)]
391+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
386392
pub const fn ptr() -> *const fpb::RegisterBlock {
387393
Self::PTR
388394
}
@@ -410,8 +416,9 @@ impl FPU {
410416
/// Pointer to the register block
411417
pub const PTR: *const fpu::RegisterBlock = 0xE000_EF30 as *const _;
412418

413-
/// Returns a pointer to the register block (to be deprecated in 0.7)
419+
/// Returns a pointer to the register block
414420
#[inline(always)]
421+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
415422
pub const fn ptr() -> *const fpu::RegisterBlock {
416423
Self::PTR
417424
}
@@ -443,8 +450,9 @@ impl ICB {
443450
/// Pointer to the register block
444451
pub const PTR: *mut icb::RegisterBlock = 0xE000_E004 as *mut _;
445452

446-
/// Returns a pointer to the register block (to be deprecated in 0.7)
453+
/// Returns a pointer to the register block
447454
#[inline(always)]
455+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
448456
pub const fn ptr() -> *mut icb::RegisterBlock {
449457
Self::PTR
450458
}
@@ -478,8 +486,9 @@ impl ITM {
478486
/// Pointer to the register block
479487
pub const PTR: *mut itm::RegisterBlock = 0xE000_0000 as *mut _;
480488

481-
/// Returns a pointer to the register block (to be deprecated in 0.7)
489+
/// Returns a pointer to the register block
482490
#[inline(always)]
491+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
483492
pub const fn ptr() -> *mut itm::RegisterBlock {
484493
Self::PTR
485494
}
@@ -514,8 +523,9 @@ impl MPU {
514523
/// Pointer to the register block
515524
pub const PTR: *const mpu::RegisterBlock = 0xE000_ED90 as *const _;
516525

517-
/// Returns a pointer to the register block (to be deprecated in 0.7)
526+
/// Returns a pointer to the register block
518527
#[inline(always)]
528+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
519529
pub const fn ptr() -> *const mpu::RegisterBlock {
520530
Self::PTR
521531
}
@@ -541,8 +551,9 @@ impl NVIC {
541551
/// Pointer to the register block
542552
pub const PTR: *const nvic::RegisterBlock = 0xE000_E100 as *const _;
543553

544-
/// Returns a pointer to the register block (to be deprecated in 0.7)
554+
/// Returns a pointer to the register block
545555
#[inline(always)]
556+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
546557
pub const fn ptr() -> *const nvic::RegisterBlock {
547558
Self::PTR
548559
}
@@ -569,8 +580,9 @@ impl SAU {
569580
/// Pointer to the register block
570581
pub const PTR: *const sau::RegisterBlock = 0xE000_EDD0 as *const _;
571582

572-
/// Returns a pointer to the register block (to be deprecated in 0.7)
583+
/// Returns a pointer to the register block
573584
#[inline(always)]
585+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
574586
pub const fn ptr() -> *const sau::RegisterBlock {
575587
Self::PTR
576588
}
@@ -597,8 +609,9 @@ impl SCB {
597609
/// Pointer to the register block
598610
pub const PTR: *const scb::RegisterBlock = 0xE000_ED04 as *const _;
599611

600-
/// Returns a pointer to the register block (to be deprecated in 0.7)
612+
/// Returns a pointer to the register block
601613
#[inline(always)]
614+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
602615
pub const fn ptr() -> *const scb::RegisterBlock {
603616
Self::PTR
604617
}
@@ -624,8 +637,9 @@ impl SYST {
624637
/// Pointer to the register block
625638
pub const PTR: *const syst::RegisterBlock = 0xE000_E010 as *const _;
626639

627-
/// Returns a pointer to the register block (to be deprecated in 0.7)
640+
/// Returns a pointer to the register block
628641
#[inline(always)]
642+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
629643
pub const fn ptr() -> *const syst::RegisterBlock {
630644
Self::PTR
631645
}
@@ -652,8 +666,9 @@ impl TPIU {
652666
/// Pointer to the register block
653667
pub const PTR: *const tpiu::RegisterBlock = 0xE004_0000 as *const _;
654668

655-
/// Returns a pointer to the register block (to be deprecated in 0.7)
669+
/// Returns a pointer to the register block
656670
#[inline(always)]
671+
#[deprecated(since = "0.7.5", note = "Use the associated constant `PTR` instead")]
657672
pub const fn ptr() -> *const tpiu::RegisterBlock {
658673
Self::PTR
659674
}

0 commit comments

Comments
 (0)