Skip to content

Commit 9bc59fe

Browse files
committed
Bugfix for #12374
Use an RTCC retention register to keep track of user timebase for RTC API. RTC and LP Ticker implementations use the same counter, but they shouldn't share timebases.
1 parent 1629103 commit 9bc59fe

File tree

1 file changed

+3
-9
lines changed
  • targets/TARGET_Silicon_Labs/TARGET_EFM32

1 file changed

+3
-9
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/rtcc.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void rtc_init(void)
5656
rtcc_init.presc = rtccCntPresc_32768;
5757
RTCC_Init(&rtcc_init);
5858
RTCC_Enable(true);
59+
RTCC->RET[0].REG = 0;
5960
}
6061

6162
void rtc_free(void)
@@ -71,20 +72,13 @@ int rtc_isenabled(void)
7172

7273
time_t rtc_read(void)
7374
{
74-
return RTCC_CounterGet();
75+
return RTCC_CounterGet() + RTCC->RET[0].REG;
7576
}
7677

7778
void rtc_write(time_t t)
7879
{
7980
core_util_critical_section_enter();
80-
uint32_t diff = t - RTCC_CounterGet();
81-
lptick_offset += diff;
82-
83-
if(RTCC_IntGetEnabled() & RTCC_IF_CC0) {
84-
RTCC->CC[0].CCV += diff << 15;
85-
}
86-
87-
RTCC_CounterSet(t);
81+
RTCC->RET[0].REG = t - RTCC_CounterGet();
8882
core_util_critical_section_exit();
8983
}
9084

0 commit comments

Comments
 (0)