@@ -77,7 +77,8 @@ mod tests {
7777 defmt:: trace!( "{}" , state. mono_timer) ;
7878 let freqcyc = state. mono_timer . frequency ( ) . integer ( ) ;
7979
80- let durations: [ duration:: Generic < u32 > ; 5 ] = [
80+ let durations: [ duration:: Generic < u32 > ; 6 ] = [
81+ 100 . nanoseconds ( ) . into ( ) ,
8182 100 . microseconds ( ) . into ( ) ,
8283 1 . milliseconds ( ) . into ( ) ,
8384 100 . milliseconds ( ) . into ( ) ,
@@ -86,11 +87,12 @@ mod tests {
8687 // 100.seconds().into(),
8788 ] ;
8889
89- for dur in durations {
90+ for ( i , dur) in durations. into_iter ( ) . enumerate ( ) {
9091 defmt:: trace!( "Duration: {}" , defmt:: Debug2Format ( & dur) ) ;
9192
9293 timer. start ( dur) ;
93- assert ! ( !timer. is_event_triggered( Event :: Update ) ) ;
94+ // Wait one cycle, so the start function overhead is not that big.
95+ unwrap ! ( nb:: block!( timer. wait( ) ) . ok( ) ) ;
9496 // call instant after start, because starting the timer is the last thing done in the
9597 // start function, and therefor no overhead is added to the timing.
9698 let instant = state. mono_timer . now ( ) ;
@@ -106,8 +108,10 @@ mod tests {
106108 let deviation = ( ratio - 1. ) . abs ( ) ;
107109
108110 // Deviation is high for smaller timer duration. Higher duration are pretty accurate.
109- // TODO: Maybe the allowed deviation should changed depending on the duration?
110- defmt:: assert!( deviation < 11e-02 ) ;
111+ defmt:: trace!( "deviation: {}" , deviation) ;
112+ if i > 0 {
113+ defmt:: assert!( deviation < 1e-02 ) ;
114+ }
111115 }
112116 state. timer = Some ( timer) ;
113117 }
0 commit comments