- clock_get_system_microtime(&sys, µsys);
- if ((int32_t)(microsecs -= microsys) < 0) {
- microsecs += USEC_PER_SEC;
- secs -= 1;
+ if ((int32_t)secs >= (int32_t)rtclock_boottime) {
+ /*
+ * Initialize the boot time based on the platform clock.
+ */
+ if (rtclock_boottime == 0)
+ rtclock_boottime = secs;
+
+ /*
+ * Calculate the new calendar epoch based
+ * on the platform clock and the system
+ * clock.
+ */
+ clock_get_system_microtime(&sys, µsys);
+ TIME_SUB(secs, sys, microsecs, microsys, USEC_PER_SEC);
+
+ /*
+ * Set the new calendar epoch.
+ */
+ rtclock_calend.epoch = secs;
+ rtclock_calend.microepoch = microsecs;
+
+ /*
+ * Cancel any adjustment in progress.
+ */
+ rtclock_calend.epoch1 = 0;
+ rtclock_calend.adjdelta = rtclock_calend.adjtotal = 0;