Skip to content

Commit 8bddb6b

Browse files
committed
NCS36510: Make RTC driver to operate on seconds instead of us.
In current implementation `rtc_read` function returns number of elapsed us and `rtc_write` function sets RTC time to specified value in us. Mbed HAL API expects that these functions operate on seconds. Since lp ticker is also based on RTC provide mechanism to trace elapsed seconds without modifying RTC registers.
1 parent 68ad00f commit 8bddb6b

File tree

1 file changed

+18
-2
lines changed
  • targets/TARGET_ONSEMI/TARGET_NCS36510

1 file changed

+18
-2
lines changed

targets/TARGET_ONSEMI/TARGET_NCS36510/rtc_api.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
#include "rtc.h"
4040
#include "cmsis_nvic.h"
4141

42+
#define US_PER_SEC 1000000
43+
44+
static time_t m_time_base;
45+
46+
static uint32_t rtc_seconds_get()
47+
{
48+
return (uint32_t)((fRtcRead() / US_PER_SEC) & 0xFFFFFFFF);
49+
}
50+
4251
/* See rtc_apc.h for description */
4352

4453
void rtc_init(void)
@@ -61,13 +70,20 @@ int rtc_isenabled(void)
6170
/* See rtc_apc.h for description */
6271
time_t rtc_read(void)
6372
{
64-
return (uint32_t)(fRtcRead() & 0xFFFFFFFF); /* TODO Truncating 64 bit value to 32 bit */
73+
return m_time_base + rtc_seconds_get();
6574
}
6675

6776
/* See rtc_apc.h for description */
6877
void rtc_write(time_t t)
6978
{
70-
fRtcWrite(t);
79+
uint32_t seconds;
80+
do {
81+
seconds = rtc_seconds_get();
82+
m_time_base = t - seconds;
83+
/* If the number of seconds indicated by the counter changed during the
84+
update of the time base, just repeat the update, now using the new
85+
number of seconds. */
86+
} while (seconds != rtc_seconds_get());
7187
}
7288

7389
#endif /* DEVICE_RTC */

0 commit comments

Comments
 (0)