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 e75a1618269d9c7b0cb891759322421d222f860d
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Mon Jun 29 15:53:27 2026 +0800

    sched/clock: Convert watchdog to hrtimer in adjtime
    
    Replace wdog-based timer with hrtimer in clock_adjtime:
    - Replace struct wdog_s g_adjtime_wdog with hrtimer_t g_adjtime_timer
    - Convert adjtime_wdog_callback to hrtimer_entry_t signature
    - Use hrtimer_gettime with NSEC_PER_MSEC for remaining time query
    - Use NSEC_PER_MSEC constant for millisecond to nanosecond conversion
    
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 sched/clock/clock_adjtime.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/sched/clock/clock_adjtime.c b/sched/clock/clock_adjtime.c
index 5b970474fd0..c6241ee9594 100644
--- a/sched/clock/clock_adjtime.c
+++ b/sched/clock/clock_adjtime.c
@@ -38,6 +38,7 @@
 #include <nuttx/arch.h>
 #include <nuttx/spinlock.h>
 #include <nuttx/fs/fs.h>
+#include <nuttx/hrtimer.h>
 #include <nuttx/timers/ptp_clock.h>
 
 #include "clock/clock.h"
@@ -53,7 +54,7 @@
 /* CLOCK_TIMEKEEPING provides its own software-based adjtime(). */
 
 #ifndef CONFIG_CLOCK_TIMEKEEPING
-static struct wdog_s g_adjtime_wdog;
+static hrtimer_t g_adjtime_timer;
 static long g_adjtime_ppb;
 static spinlock_t g_adjtime_lock = SP_UNLOCKED;
 
@@ -63,24 +64,26 @@ static spinlock_t g_adjtime_lock = SP_UNLOCKED;
 
 /* Restore default rate after adjustment period expires */
 
-static void adjtime_wdog_callback(wdparm_t arg)
+static uint64_t adjtime_timer_callback(FAR const hrtimer_t *timer,
+                                       uint64_t expired)
 {
-  irqstate_t flags;
-
-  UNUSED(arg);
-
-  flags = spin_lock_irqsave(&g_adjtime_lock);
+  irqstate_t flags = spin_lock_irqsave(&g_adjtime_lock);
 
+  if (g_adjtime_ppb != 0)
+    {
 #ifdef CONFIG_ARCH_HAVE_ADJTIME
-  up_adjtime(0);
+      up_adjtime(0);
 #endif
 
 #ifdef CONFIG_RTC_ADJTIME
-  up_rtc_adjtime(0);
+      up_rtc_adjtime(0);
 #endif
 
-  g_adjtime_ppb = 0;
+      g_adjtime_ppb = 0;
+    }
+
   spin_unlock_irqrestore(&g_adjtime_lock, flags);
+  return 0;
 }
 
 /* Query remaining adjustment in microseconds */
@@ -88,8 +91,7 @@ static void adjtime_wdog_callback(wdparm_t arg)
 static long long adjtime_remaining_usec(void)
 {
   return (long long)g_adjtime_ppb
-    * TICK2MSEC(wd_gettime(&g_adjtime_wdog))
-    / (MSEC_PER_SEC * NSEC_PER_USEC);
+    * (hrtimer_gettime(&g_adjtime_timer) / NSEC_PER_USEC);
 }
 
 /* Start new adjustment period */
@@ -138,12 +140,13 @@ static int adjtime_start(long long adjust_usec)
 
   if (g_adjtime_ppb != 0)
     {
-      wd_start(&g_adjtime_wdog, MSEC2TICK(CONFIG_CLOCK_ADJTIME_PERIOD_MS),
-               adjtime_wdog_callback, 0);
+      hrtimer_start(&g_adjtime_timer, adjtime_timer_callback,
+                    (uint64_t)CONFIG_CLOCK_ADJTIME_PERIOD_MS *
+                    (uint64_t)NSEC_PER_MSEC, HRTIMER_MODE_REL);
     }
   else
     {
-      wd_cancel(&g_adjtime_wdog);
+      hrtimer_cancel(&g_adjtime_timer);
     }
 
   spin_unlock_irqrestore_nopreempt(&g_adjtime_lock, flags);

Reply via email to