@@ -114,6 +114,7 @@ static unsigned milliseconds_to_ticks(uint32_t timer_freq, unsigned millisecs)
114114{
115115 /* Use 64 bit arithmetic to avoid overflows for high frequencies. */
116116 unsigned result = ((uint64_t )millisecs * US_PER_MS * timer_freq ) / US_PER_SEC ;
117+
117118 /* Never return less than MINIMUM_TICKS ticks */
118119 return (result >= MINIMUM_TICKS ) ? result : MINIMUM_TICKS ;
119120}
@@ -132,7 +133,7 @@ static int test_timer(unsigned num, uint32_t timer_freq)
132133 }
133134
134135 printf (" - Calling timer_init(%u, %" PRIu32 ")\n " ,
135- num , timer_freq );
136+ num , timer_freq );
136137 /* initialize and halt timer */
137138 if (timer_init (TIMER_DEV (num ), timer_freq , cb , (void * )(COOKIE * num )) != 0 ) {
138139 printf ("ERROR: timer_init() failed\n\n" );
@@ -207,6 +208,7 @@ static int test_timer(unsigned num, uint32_t timer_freq)
207208
208209 const unsigned duration = milliseconds_to_ticks (timer_freq , MINIMUM_TIMEOUT_MS );
209210 unsigned target = timer_read (TIMER_DEV (num )) + duration ;
211+
210212 expect (0 == timer_set_absolute (TIMER_DEV (num ), 0 , target ));
211213 expect (0 == timer_clear (TIMER_DEV (num ), 0 ));
212214 atomic_store_u8 (& fired , 0 );
@@ -242,7 +244,7 @@ static int test_timer(unsigned num, uint32_t timer_freq)
242244 * called directly from inside timer_set if the given timeout=0, leading to a
243245 * stack overflow if timer_set is called from within the callback of the same
244246 * timer.
245- *
247+ *
246248 * The test will attempt to initialize each timer in the system and set a non-zero
247249 * timeout at first. The callback function provided will then attempt to set a new
248250 * timeout=0 until we have called the callback TEST_ITERATIONS times (default 10000).
@@ -280,7 +282,7 @@ static int test_timer_timeout(unsigned num, uint32_t timer_freq)
280282 num , TEST_ITERATIONS , ctx .counter );
281283 return 0 ;
282284 }
283- printf (" OK (timer timeout successfull )\n" );
285+ printf (" OK (timer timeout successful )\n" );
284286 return 1 ;
285287}
286288
@@ -316,7 +318,8 @@ static void print_supported_frequencies(tim_t dev)
316318 }
317319
318320 uword_t end = query_freq_numof (dev );
319- printf (" - supported frequencies:\n" );
321+
322+ printf (" - supported frequencies:\n" );
320323 for (uword_t i = 0 ; i < MIN (end , 3 ); i ++ ) {
321324 printf (" %u: %" PRIu32 "\n" , (unsigned )i , timer_query_freqs (dev , i ));
322325 }
@@ -335,10 +338,11 @@ int main(void)
335338 printf ("Available timers: %i\n" , TIMER_NUMOF );
336339
337340 int failed = 0 ;
341+
338342 /* test all configured timers */
339343 for (unsigned i = 0 ; i < TIMER_NUMOF ; i ++ ) {
340344 printf ("\nTIMER %u\n"
341- "=======\n\n" , i );
345+ "=======\n\n" , i );
342346 print_supported_frequencies (TIMER_DEV (i ));
343347 uword_t end = query_freq_numof (TIMER_DEV (i ));
344348
0 commit comments