Skip to content

Commit 814940c

Browse files
committed
Fix for issue #8155 (NRF52832: time stops after 35 minutes)
Low power Timer is used as RTC for platforms that don't have HW RTC capabilities (like NRF52832). `_rtc_lpticker_read(void)` function currently uses `Timer::read()` function to trace elapsed time. `Timer::read()` returns seconds represented as `float` value, but this value is calculated from `int` since `Timer::read_us()` returns `int`. This limits time tracing to ~35 min. To fix this problem we will use `timer::read_high_resolution_us()` (which returns unsigned 64 bit value) instead of `Timer::read()`.
1 parent 3da606e commit 814940c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

platform/mbed_rtc_time.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static void (*_rtc_write)(time_t t) = rtc_write;
3333

3434
#include "drivers/LowPowerTimer.h"
3535

36+
#define US_PER_SEC 1000000
37+
3638
static SingletonPtr<mbed::LowPowerTimer> _rtc_lp_timer;
3739
static uint64_t _rtc_lp_base;
3840
static bool _rtc_enabled;
@@ -50,7 +52,7 @@ static int _rtc_lpticker_isenabled(void)
5052

5153
static time_t _rtc_lpticker_read(void)
5254
{
53-
return (uint64_t)_rtc_lp_timer->read() + _rtc_lp_base;
55+
return _rtc_lp_timer->read_high_resolution_us() / US_PER_SEC + _rtc_lp_base;
5456
}
5557

5658
static void _rtc_lpticker_write(time_t t)

0 commit comments

Comments
 (0)