@@ -21,6 +21,7 @@ impl DwtExt for DWT {
21
21
}
22
22
}
23
23
24
+ /// DWT (Data Watchpoint and Trace) unit
24
25
pub struct Dwt {
25
26
dwt : DWT ,
26
27
dcb : DCB ,
@@ -45,7 +46,11 @@ impl Dwt {
45
46
pub fn stopwatch < ' i > ( & self , times : & ' i mut [ u32 ] ) -> StopWatch < ' i > {
46
47
StopWatch :: new ( times, self . clocks . hclk ( ) )
47
48
}
48
- /// Measure cycles it takes to execute f
49
+ /// Measure cycles it takes to execute closure `f`.
50
+ ///
51
+ /// Since DWT Cycle Counter is a 32-bit counter that wraps around to 0 on overflow,
52
+ /// users should be aware that `Dwt::measure` cannot correctly measure running time of
53
+ /// closures which take longer than `u32::MAX` cycles
49
54
pub fn measure < F : FnOnce ( ) > ( & self , f : F ) -> ClockDuration {
50
55
let mut times: [ u32 ; 2 ] = [ 0 ; 2 ] ;
51
56
let mut sw = self . stopwatch ( & mut times) ;
@@ -59,7 +64,7 @@ pub struct Delay {
59
64
clock : Hertz ,
60
65
}
61
66
impl Delay {
62
- /// Delay for ClockDuration::ticks
67
+ /// Delay for ` ClockDuration::ticks`
63
68
pub fn delay ( duration : ClockDuration ) {
64
69
let ticks = duration. ticks as u64 ;
65
70
Delay :: delay_ticks ( DWT :: get_cycle_count ( ) , ticks) ;
@@ -112,7 +117,11 @@ impl<T: Into<u64>> DelayMs<T> for Delay {
112
117
}
113
118
}
114
119
115
- /// Very simple stopwatch
120
+ /// Very simple stopwatch which reads from DWT Cycle Counter to record timing.
121
+ ///
122
+ /// Since DWT Cycle Counter is a 32-bit counter that wraps around to 0 on overflow,
123
+ /// users should be aware that `StopWatch` cannot correctly measure laps
124
+ /// which take longer than `u32::MAX` cycles
116
125
pub struct StopWatch < ' l > {
117
126
times : & ' l mut [ u32 ] ,
118
127
timei : usize ,
@@ -142,8 +151,9 @@ impl<'l> StopWatch<'l> {
142
151
self . timei = 0 ;
143
152
self . times [ 0 ] = DWT :: get_cycle_count ( ) ;
144
153
}
145
- /// Record a new lap
146
- /// NOTE If lap count exceeds maximum, the last lap is updated
154
+ /// Record a new lap.
155
+ ///
156
+ /// If lap count exceeds maximum, the last lap is updated
147
157
pub fn lap ( & mut self ) -> & mut Self {
148
158
let c = DWT :: get_cycle_count ( ) ;
149
159
if self . timei < self . times . len ( ) {
@@ -152,8 +162,9 @@ impl<'l> StopWatch<'l> {
152
162
self . times [ self . timei ] = c;
153
163
self
154
164
}
155
- /// Calculate the time of lap n (n starting with 1)
156
- /// NOTE Returns None if 'n' is out of range
165
+ /// Calculate the time of lap n (n starting with 1).
166
+ ///
167
+ /// Returns None if `n` is out of range
157
168
pub fn lap_time ( & self , n : usize ) -> Option < ClockDuration > {
158
169
if ( n < 1 ) || ( self . timei < n) {
159
170
None
0 commit comments