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 8fffc058e4109c03a2b8a89cb66cbbbcb2cef3c0
Author: wangshaoxin <[email protected]>
AuthorDate: Mon Mar 23 10:18:22 2026 +0800

    drivers/timers/rpmsg_rtc: bind the client to one server only
    
    When the client reaches the server over more than one rpmsg channel,
    each channel announces rpmsg-rtc and the client created its endpoint
    again for every announcement, on the same struct. The endpoint ended up
    linked into two devices and the endpoint lists were corrupted (rpmsg
    dump loops, the next commands hang).
    
    Ignore further announcements once bound, and add
    CONFIG_RTC_RPMSG_SERVER_CPUNAME to pick the server's CPU explicitly.
    RTC_RPMSG_SYNC_BASETIME now also depends on RTC_RPMSG, the client it
    applies to.
    
    Signed-off-by: wangshaoxin <[email protected]>
---
 drivers/timers/Kconfig     | 12 +++++++++++-
 drivers/timers/rpmsg_rtc.c | 23 +++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig
index 7caa450c75a..c2bd1d60b0f 100644
--- a/drivers/timers/Kconfig
+++ b/drivers/timers/Kconfig
@@ -593,10 +593,20 @@ config RTC_RPMSG_SERVER
        bool "The RTC RPMSG Role"
        depends on RPMSG
 
+config RTC_RPMSG_SERVER_CPUNAME
+       string "RPMSG RTC Server CPU Name"
+       default ""
+       depends on RTC_RPMSG && !RTC_RPMSG_SERVER
+       ---help---
+               Specify the CPU name of the RTC RPMSG server to connect to.
+               When set, the RTC client will only match the rpmsg-rtc service
+               from the specified CPU, avoiding conflicts when multiple rpmsg
+               channels are available. Leave empty to match any CPU.
+
 config RTC_RPMSG_SYNC_BASETIME
        bool "Update g_basetime from rpmsg."
        default n
-       depends on !RTC_RPMSG_SERVER && !CLOCK_TIMEKEEPING
+       depends on RTC_RPMSG && !RTC_RPMSG_SERVER && !CLOCK_TIMEKEEPING
        ---help---
                Prevent g_basetime differences in multi-core situations.
 
diff --git a/drivers/timers/rpmsg_rtc.c b/drivers/timers/rpmsg_rtc.c
index 3288f57ab6d..645367f6f6e 100644
--- a/drivers/timers/rpmsg_rtc.c
+++ b/drivers/timers/rpmsg_rtc.c
@@ -258,6 +258,29 @@ static bool rpmsg_rtc_device_ns_match(FAR struct 
rpmsg_device *rdev,
                                       FAR void *priv, FAR const char *name,
                                       uint32_t dest)
 {
+  FAR struct rpmsg_rtc_lowerhalf_s *lower = priv;
+
+  /* Already bound to a remote, reject further announcements.
+   * This prevents duplicate binding in multi-channel scenarios.
+   */
+
+  if (lower->ept.rdev)
+    {
+      return false;
+    }
+
+  /* If a specific server CPU is configured, match both endpoint
+   * name and CPU name. Otherwise accept any CPU that announces
+   * the rpmsg-rtc service (first come, first served).
+   */
+
+  if (CONFIG_RTC_RPMSG_SERVER_CPUNAME[0] != '\0')
+    {
+      return !strcmp(name, RPMSG_RTC_EPT_NAME) &&
+             !strcmp(rpmsg_get_cpuname(rdev),
+                     CONFIG_RTC_RPMSG_SERVER_CPUNAME);
+    }
+
   return !strcmp(name, RPMSG_RTC_EPT_NAME);
 }
 

Reply via email to