From 1c342328de298deb029bfc5c1c91ec30a31f0958 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Sat, 2 Apr 2022 14:27:20 +0800 Subject: [PATCH] rtc/rpmsg: when a client connection, server initiates time sync Signed-off-by: Jiuzhu Dong --- drivers/timers/rpmsg_rtc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/timers/rpmsg_rtc.c b/drivers/timers/rpmsg_rtc.c index 2c1baf60a1..233c19a18c 100644 --- a/drivers/timers/rpmsg_rtc.c +++ b/drivers/timers/rpmsg_rtc.c @@ -703,6 +703,8 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev, { FAR struct rpmsg_rtc_server_s *server = priv; FAR struct rpmsg_rtc_client_s *client; + struct rpmsg_rtc_set_s msg; + struct rtc_time rtctime; if (strcmp(name, RPMSG_RTC_EPT_NAME)) { @@ -725,6 +727,14 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev, return; } + if (server->lower->ops->rdtime(server->lower, &rtctime) >= 0) + { + msg.sec = timegm((FAR struct tm *)&rtctime); + msg.nsec = rtctime.tm_nsec; + msg.header.command = RPMSG_RTC_SYNC; + rpmsg_send(&client->ept, &msg, sizeof(msg)); + } + nxsem_wait_uninterruptible(&server->exclsem); list_add_tail(&server->list, &client->node); nxsem_post(&server->exclsem);