Skip to content

Commit

Permalink
Fixed tick overflow for different bit-width
Browse files Browse the repository at this point in the history
  • Loading branch information
cyliangtw committed Sep 24, 2020
1 parent d5865bd commit 0ece1ca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mbed/adapters/tickcounter_mbed_os5.cpp
Expand Up @@ -19,13 +19,17 @@ static uint64_t system_tick_counter_read(void)
{
uint64_t result;
uint32_t t;
uint32_t bits;
uint32_t mask;

core_util_critical_section_enter();
t = us_ticker_read();
if (t < last_ticker_us)
{
// overflowed
long_ticker_ms += 0xFFFFFFFF / 1000;
bits = us_ticker_get_info()->bits;
mask = (1 << bits) - 1;
long_ticker_ms += mask / 1000;
}
last_ticker_us = t;

Expand Down

0 comments on commit 0ece1ca

Please sign in to comment.