Skip to content

Commit b2aa2dd

Browse files
committed
TESTS: common_tickers handle wrap-around case
it seems that count_ticks function does not consider the case of a 16 its counter wrap-around - proposal added here.
1 parent 458e726 commit b2aa2dd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

TESTS/mbed_hal/common_tickers/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ unsigned int ticker_overflow_delta;
5252
uint32_t count_ticks(uint32_t cycles, uint32_t step)
5353
{
5454
register uint32_t reg_cycles = cycles;
55+
const ticker_info_t* p_ticker_info = intf->get_info();
5556

5657
core_util_critical_section_enter();
5758

@@ -65,7 +66,10 @@ uint32_t count_ticks(uint32_t cycles, uint32_t step)
6566

6667
core_util_critical_section_exit();
6768

68-
return (stop - start);
69+
if ( stop > start)
70+
return (stop - start);
71+
else
72+
return (((1 << p_ticker_info->bits) - start) + stop);
6973
}
7074

7175
void ticker_event_handler_stub(const ticker_data_t * const ticker)

0 commit comments

Comments
 (0)