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.
pull/12509/head
Steven Cooreman 2020-02-25 11:44:12 +01:00
parent 1629103fb1
commit 9bc59fe2d7
1 changed files with 3 additions and 9 deletions

View File

@ -56,6 +56,7 @@ void rtc_init(void)
rtcc_init.presc = rtccCntPresc_32768; rtcc_init.presc = rtccCntPresc_32768;
RTCC_Init(&rtcc_init); RTCC_Init(&rtcc_init);
RTCC_Enable(true); RTCC_Enable(true);
RTCC->RET[0].REG = 0;
} }
void rtc_free(void) void rtc_free(void)
@ -71,20 +72,13 @@ int rtc_isenabled(void)
time_t rtc_read(void) time_t rtc_read(void)
{ {
return RTCC_CounterGet(); return RTCC_CounterGet() + RTCC->RET[0].REG;
} }
void rtc_write(time_t t) void rtc_write(time_t t)
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
uint32_t diff = t - RTCC_CounterGet(); RTCC->RET[0].REG = t - RTCC_CounterGet();
lptick_offset += diff;
if(RTCC_IntGetEnabled() & RTCC_IF_CC0) {
RTCC->CC[0].CCV += diff << 15;
}
RTCC_CounterSet(t);
core_util_critical_section_exit(); core_util_critical_section_exit();
} }