Why does RTC_SetUnixTime call RTC_UnixToDateTime | Cypress Semiconductor
Why does RTC_SetUnixTime call RTC_UnixToDateTime
Hey all, I was digging into the RTC component (v1.10) because I managed to freeze my app by passing in a bad unix time (I flipped little and big endian, and I basically was stuck in a while loop until I gave up.
While breakpointing in for the problem, I saw that it was caused here:
void RTC_SetUnixTime(uint64 unixTime)
RTC_unixTime = unixTime;
RTC_UnixToDateTime(&tmpDateTime, unixTime, (uint32)RTC_24_HOURS_FORMAT);
So, since it seems to be that the unixTime is the internal accumulator, and the important public GET methods first call RTC_UnixToDateTime anyways, why are also running it in here? It seems a bit inefficient, as the UnixToDateTime is internally a ton of while loops - when this could just be a 1 line assignement.
For example, RTC_UnixToDateTime is internally called by the following methods:
RTC_GetTime, RTC_GetDate, RTC_GetDateAndTime, RTC_SetUnixTime
Disclaimer: I am nicely cheaping out by using only set and get UnixTime in my app :)