Skip to content

Commit 1108cf9

Browse files
author
Rohit Grover
committed
going back to the previously successful logic to create a 64-bit timestamp.
1 parent 543e8c8 commit 1108cf9

File tree

1 file changed

+6
-3
lines changed
  • libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822

1 file changed

+6
-3
lines changed

libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,12 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
228228
* additional 32 bits. RTC_UNITS_TO_MICROSECONDS() converts this into
229229
* microsecond units (in 64-bits).
230230
*/
231-
const uint64_t currentTime64 = RTC_UNITS_TO_MICROSECONDS(rtc1_getCounter64());
232-
const uint64_t timestamp64 = currentTime64 + (timestamp_t)(timestamp - (timestamp_t)currentTime64);
233-
uint32_t newCallbackTime = MICROSECONDS_TO_RTC_UNITS(timestamp64);
231+
const uint64_t currentTime64 = RTC_UNITS_TO_MICROSECONDS(rtc1_getCounter64());
232+
uint64_t timestamp64 = (currentTime64 & ~(uint64_t)0xFFFFFFFFULL) + timestamp;
233+
if (((uint32_t)currentTime64 > 0x80000000) && (timestamp < 0x80000000)) {
234+
timestamp64 += (uint64_t)0x100000000ULL;
235+
}
236+
uint32_t newCallbackTime = MICROSECONDS_TO_RTC_UNITS(timestamp64);
234237

235238
/* Check for repeat setup of an existing callback. This is actually not
236239
* important; the following code should work even without this check. */

0 commit comments

Comments
 (0)