Skip to content

Commit ce8755a

Browse files
committed
move the has_* DWT methods to associated functions
1 parent 7c729e9 commit ce8755a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/peripheral/dwt.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,33 @@ impl DWT {
127127
///
128128
/// A value of zero indicates no comparator support.
129129
#[inline]
130-
pub fn num_comp(&self) -> u8 {
131-
self.ctrl.read().numcomp()
130+
pub fn num_comp() -> u8 {
131+
// NOTE(unsafe) atomic read with no side effects
132+
unsafe { (*DWT::PTR).ctrl.read().numcomp() }
132133
}
133134

134135
/// Returns `true` if the the implementation supports sampling and exception tracing
135136
#[cfg(not(armv6m))]
136137
#[inline]
137-
pub fn has_exception_trace(&self) -> bool {
138-
!self.ctrl.read().notrcpkt()
138+
pub fn has_exception_trace() -> bool {
139+
// NOTE(unsafe) atomic read with no side effects
140+
unsafe { !(*DWT::PTR).ctrl.read().notrcpkt() }
139141
}
140142

141143
/// Returns `true` if the implementation includes external match signals
142144
#[cfg(not(armv6m))]
143145
#[inline]
144-
pub fn has_external_match(&self) -> bool {
145-
!self.ctrl.read().noexttrig()
146+
pub fn has_external_match() -> bool {
147+
// NOTE(unsafe) atomic read with no side effects
148+
unsafe { !(*DWT::PTR).ctrl.read().noexttrig() }
146149
}
147150

148151
/// Returns `true` if the implementation supports a cycle counter
149152
#[inline]
150-
pub fn has_cycle_counter(&self) -> bool {
153+
pub fn has_cycle_counter() -> bool {
151154
#[cfg(not(armv6m))]
152-
return !self.ctrl.read().nocyccnt();
155+
// NOTE(unsafe) atomic read with no side effects
156+
return !unsafe { (*DWT::PTR).ctrl.read().nocyccnt() };
153157

154158
#[cfg(armv6m)]
155159
return false;
@@ -158,8 +162,9 @@ impl DWT {
158162
/// Returns `true` if the implementation the profiling counters
159163
#[cfg(not(armv6m))]
160164
#[inline]
161-
pub fn has_profiling_counter(&self) -> bool {
162-
!self.ctrl.read().noprfcnt()
165+
pub fn has_profiling_counter() -> bool {
166+
// NOTE(unsafe) atomic read with no side effects
167+
!unsafe { (*DWT::PTR).ctrl.read().noprfcnt() }
163168
}
164169

165170
/// Enables the cycle counter

0 commit comments

Comments
 (0)