Tool/software:
Hello,
I am reading my RTC seconds and subseconds as follows:
// process rtc if(!rtc_semaphore) { // check if rtc is being accessed rtc_semaphore = true; // set rtc semaphore true g_rtc_mark = HWREG(HIB_RTCC); // mark rtc seconds g_rtc_sub_mark = (HWREG(HIB_RTCSS) & HIB_RTCSS_RTCSSC_M); // mark rtc subseconds valid_timing = (g_rtc_mark == HWREG(HIB_RTCC)); // if seconds are not the same timing is valid } else { valid_timing = false; // rtc is being accessed } rtc_semaphore = false; // set rtc semaphore false as soon as we are done with RTC
This runs inside a loop triggered periodically. As instructed in the datasheet, i am reading RTCC, and then RTCSS, and reading RTCC again comparing to first read, and only if both are equal I am processing that read via a valid_timing flag. There is also a rtc_semaphore that will skip packet if rtc is being read by another part of code, such as inside usb_handler.h, which measures incoming sync packet differences with RTC.
Below is a log of RTC and Host time stamps, and their differenes in nanos:
[node-1] [INFO] [1748355072.989121466] [node]: nanos_diff 769990 rtc 1748355072.32386 host 1748355072.989112275 [node-1] [INFO] [1748355072.992817739] [node]: nanos_diff 559546 rtc 1748355072.32514 host 1748355072.992808081 [node-1] [INFO] [1748355072.996931401] [node]: nanos_diff 767505 rtc 1748355072.32642 host 1748355072.996922290 [node-1] [INFO] [1748355073.000778899] [node]: nanos_diff -999196287 rtc 1748355073.32767 host 1748355073.773195 [node-1] [INFO] [1748355073.004645475] [node]: nanos_diff 761379 rtc 1748355073.127 host 1748355073.4637111 [node-1] [INFO] [1748355073.008656346] [node]: nanos_diff 865244 rtc 1748355073.255 host 1748355073.8647226 [node-1] [INFO] [1748355073.012311718] [node]: nanos_diff 614277 rtc 1748355073.383 host 1748355073.12302509 [node-1] [INFO] [1748355073.016466674] [node]: nanos_diff 865056 rtc 1748355073.511 host 1748355073.16459538
What happens is that near the end of the second, the rtc is at 1748355072.32642 - next reading is at rtc 1748355073.32767 - and next reading is 1748355073.127
The second skips to the new second, but the subseconds belong in the old second. If I were reading RTCSS first, and then RTCC, RTCC could increment by +1. But I am reading RTCC first, reading the subseconds, then reading rtcc again, to see if they are equal. And they always are, but the second is +1 from expected.
Any ideas recomendations help greatly appreciated.
Best Regards,
C.