thanks for the RTC driver. Works fine for me
Just some curious questions though:
Couldn't it happen that seconds wrap just after the ms are read? Also, the same problem applies for the DIVH register. Could rtc_lld_get_time be adapted to handle such problems like
Code: Select all
void rtc_lld_get_time(RTCDriver *rtcp, RTCTime *timespec) {
uint32_t time_frac;
uint16_t second_guard;
(void)rtcp;
do{
second_guard = RTC->CNTL;
time_frac = (((uint32_t)RTC->DIVH) << 16) + (uint32_t)RTC->DIVL;
timespec->tv_msec = (uint16_t)(((STM32_LSECLK - time_frac) * 1000) /
STM32_LSECLK);
timespec->tv_sec = (RTC->CNTH << 16) + RTC->CNTL;
}while(second_guard != RTC->CNTL);
}
On a related note: What about the year 2038 problem? I know that none of our hardware will probably be around by then, but you never now... Could there be a build switch added which increases the seconds counter to uint64_t and increase it by 2^16 when RTC_EVENT_OVERFLOW is called?
Also, i think with an addition GPT one could increase the precision of rtc_lld_set_time to also include milliseconds. Could be worth a build switch too?