// RTC initialization
if (RTC_SR & RTC_SR_TIF) {
// this code will normally run on a power-up reset
// when VBAT has detected a power-up. Normally our
// compiled-in time will be stale. Write a special
// flag into the VBAT register file indicating the
// RTC is set with known-stale time and should be
// updated when fresh time is known.
#if ARDUINO >= 10600
rtc_set((uint32_t)&__rtc_localtime);
#else
rtc_set(TIME_T);
#endif
*(uint32_t *)0x4003E01C = 0x5A94C3A5;
}
if ((RCM_SRS0 & RCM_SRS0_PIN) && (*(uint32_t *)0x4003E01C == 0x5A94C3A5)) {
// this code should run immediately after an upload
// where the Teensy Loader causes the Mini54 to reset.
// Our compiled-in time will be very fresh, so set
// the RTC with this, and clear the VBAT resister file
// data so we don't mess with the time after it's been
// set well.
#if ARDUINO >= 10600
rtc_set((uint32_t)&__rtc_localtime);
#else
rtc_set(TIME_T);
#endif
*(uint32_t *)0x4003E01C = 0;
}