@@ -58,7 +58,7 @@ static struct rt_timer alarm_time;
5858
5959/**
6060 * @brief Alarm timeout callback function
61- * @param param Pointer to RTC device
61+ * @param param User data passed to alarm update function
6262 * @return None
6363 *
6464 * This function is called when the alarm timer expires and updates
@@ -144,12 +144,12 @@ static void get_rtc_time(struct timespec *ts)
144144 struct timespec current_ts ;
145145 rt_ktime_boottime_get_ns (& current_ts );
146146
147- ts -> tv_sec = init_ktime_ts .tv_sec + (current_ts .tv_sec - init_ktime_ts .tv_sec );
148- ts -> tv_nsec = init_ktime_ts .tv_nsec + (current_ts .tv_nsec - init_ktime_ts .tv_nsec );
147+ ts -> tv_sec = init_ts .tv_sec + (current_ts .tv_sec - init_ktime_ts .tv_sec );
148+ ts -> tv_nsec = init_ts .tv_nsec + (current_ts .tv_nsec - init_ktime_ts .tv_nsec );
149149#else
150150 rt_tick_t tick = rt_tick_get_delta (init_tick );
151151 ts -> tv_sec = init_ts .tv_sec + tick / RT_TICK_PER_SECOND ;
152- ts -> tv_nsec = init_ts .tv_nsec + ((tick % RT_TICK_PER_SECOND ) * ( 1000000000UL / RT_TICK_PER_SECOND ) );
152+ ts -> tv_nsec = init_ts .tv_nsec + ((tick % RT_TICK_PER_SECOND ) * 1000000000UL / RT_TICK_PER_SECOND );
153153#endif
154154 /* Handle nanosecond overflow/underflow */
155155 if (ts -> tv_nsec >= 1000000000L )
@@ -320,6 +320,7 @@ static int rt_soft_rtc_init(void)
320320 init_tick = rt_tick_get ();
321321#endif
322322 init_ts .tv_sec = timegm (& time_new );
323+ init_ts .tv_nsec = 0 ;
323324
324325 soft_rtc_dev .type = RT_Device_Class_RTC ;
325326
@@ -361,6 +362,12 @@ rt_err_t rt_soft_rtc_sync(void)
361362
362363 rt_device_control (& soft_rtc_dev , RT_DEVICE_CTRL_RTC_GET_TIME , & time );
363364 struct timespec ts = { time , 0 };
365+ /*
366+ * Intentionally reset the soft RTC baseline to the current time.
367+ * This operation updates alarm status and synchronizes the soft RTC
368+ * with the external time source, discarding any accumulated drift.
369+ * This is the intended behavior for synchronization in this context.
370+ */
364371 set_rtc_time (& ts );
365372 return RT_EOK ;
366373}
0 commit comments