This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 652abeba1179a0ef358db5f761d9c6d4b8bd36bd
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Wed Jan 28 11:03:01 2026 +0800

    drivers/timers/rpmsg_rtc: resync the server's system time to its RTC
    
    rpmsg_rtc_server_sync() reads the RTC and sends that time to the
    clients, but sends the server's own g_basetime along with it without
    updating it. Once the server's system time has drifted from its RTC,
    the clients get a time and a base time that disagree. Synchronize the
    server's system time to the RTC time first.
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 drivers/timers/rpmsg_rtc.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/timers/rpmsg_rtc.c b/drivers/timers/rpmsg_rtc.c
index 5c23b27c8f2..3288f57ab6d 100644
--- a/drivers/timers/rpmsg_rtc.c
+++ b/drivers/timers/rpmsg_rtc.c
@@ -750,9 +750,20 @@ static void rpmsg_rtc_server_sync(FAR struct 
rpmsg_rtc_server_s *server,
   if (server->lower->ops->rdtime(server->lower, &rtctime) >= 0)
     {
       struct rpmsg_rtc_set_s msg;
+      struct timespec tp;
 
       msg.sec  = timegm((FAR struct tm *)&rtctime);
       msg.nsec = rtctime.tm_nsec;
+
+      /* Synchronize the local g_basetime with the physical
+       * RTC time to ensure that the local time is consistent with
+       * the RTC.
+       */
+
+      tp.tv_sec  = msg.sec;
+      tp.tv_nsec = msg.nsec;
+      clock_synchronize(&tp);
+
       msg.base_sec = g_basetime.tv_sec;
       msg.base_nsec = g_basetime.tv_nsec;
 

Reply via email to