From 3fa6cfc41e8801e9e5ec363e2f2d768023b6d6e2 Mon Sep 17 00:00:00 2001 From: yangguangcai Date: Fri, 3 Nov 2023 15:44:36 +0800 Subject: [PATCH] rpmsg_rtc:Update g_basetime from rpmsg. When ipc is busy, g_basetime may be inconsistent on different cores. Signed-off-by: yangguangcai --- drivers/timers/Kconfig | 7 +++++++ drivers/timers/rpmsg_rtc.c | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index 0fd4074727..3c6586a606 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -388,6 +388,13 @@ config RTC_RPMSG_SERVER_NAME The proc name of RTC server. Client requests time from specified name of remote proc. +config RTC_RPMSG_SYNC_BASETIME + bool "Update g_basetime from rpmsg." + default n + depends on !RTC_RPMSG_SERVER && !CLOCK_TIMEKEEPING + ---help--- + Prevent g_basetime differences in multi-core situations. + endif # RTC menuconfig WATCHDOG diff --git a/drivers/timers/rpmsg_rtc.c b/drivers/timers/rpmsg_rtc.c index 5f1e051f7f..58a25504ec 100644 --- a/drivers/timers/rpmsg_rtc.c +++ b/drivers/timers/rpmsg_rtc.c @@ -36,6 +36,8 @@ #include #include +#include "clock/clock.h" + /**************************************************************************** * Pre-processor definitions ****************************************************************************/ @@ -63,8 +65,10 @@ begin_packed_struct struct rpmsg_rtc_header_s begin_packed_struct struct rpmsg_rtc_set_s { struct rpmsg_rtc_header_s header; + int64_t base_sec; int64_t sec; int32_t nsec; + int32_t base_nsec; } end_packed_struct; #define rpmsg_rtc_get_s rpmsg_rtc_set_s @@ -300,12 +304,18 @@ static int rpmsg_rtc_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data, case RPMSG_RTC_SYNC: { struct rpmsg_rtc_set_s *msg = data; + +#ifdef CONFIG_RTC_RPMSG_SYNC_BASETIME + g_basetime.tv_sec = msg->base_sec; + g_basetime.tv_nsec = msg->base_nsec; +#else struct timespec tp; tp.tv_sec = msg->sec; tp.tv_nsec = msg->nsec; clock_synchronize(&tp); +#endif } break; @@ -488,7 +498,11 @@ static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower, ret = 1; /* Request the upper half skip clock synchronize */ } + msg.base_sec = g_basetime.tv_sec; + msg.base_nsec = g_basetime.tv_nsec; + nxmutex_lock(&server->lock); + list_for_every(&server->list, node) { client = (FAR struct rpmsg_rtc_client_s *)node; @@ -736,6 +750,9 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev, { msg.sec = timegm((FAR struct tm *)&rtctime); msg.nsec = rtctime.tm_nsec; + msg.base_sec = g_basetime.tv_sec; + msg.base_nsec = g_basetime.tv_nsec; + msg.header.command = RPMSG_RTC_SYNC; rpmsg_send(&client->ept, &msg, sizeof(msg)); }