RTC Validity check

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

RTC Validity check

Postby steved » Mon Mar 27, 2023 12:23 pm

At present, there is no way of testing whether the RTC time is valid. (without battery backup, the RTC powers up at 00-00-0000 00:00:00.0)

For backwards compatibility, I suggest that rtcGetTime() and rtc_lld_get_time() be given a return code to indicate this.

The ST RTC has a flag INITS in RTC_ISR which is set if the year > 0 (or it would be possible to test the year directly). [N.B. it's not possible to test the year outside rtcGetTime(), since it may have an offset added]. (This is true of 32F767, which uses rtc2 driver; not checked others).

So I propose:
1. Change rtcGetTime() and rtc_lld_get_time() to return a msg_t result of MSG_OK or MSG_RESET (.src and .h file change)
2. Add the following at the bottom of rtc_lld_get_time() (or similar to reflect RTC capabilities)

Code: Select all

  return (rtcp->rtc->ISR & RTC_ISR_INITS) ? MSG_OK : MSG_RESET;

3. Modify rtcGetTime() in hal_rtc.h to return the value

I've attached my update for RTCv2
Attachments
RTCv2.7z
(6.72 KiB) Downloaded 140 times

Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 14 guests