Fix-Point commented on code in PR #15044: URL: https://github.com/apache/nuttx/pull/15044#discussion_r1877939827
########## drivers/timers/arch_alarm.c: ########## @@ -46,6 +46,7 @@ static FAR struct oneshot_lowerhalf_s *g_oneshot_lower; #ifndef CONFIG_SCHED_TICKLESS static clock_t g_current_tick; +static clock_t g_base_tick; Review Comment: In order to sync `CLOCK_REALTIME` timer with the `g_system_ticks`, we can record the base time, like this: ```c int clock_systime_timespec(FAR struct timespec *ts) { #ifdef CONFIG_RTC_HIRES if (g_rtc_enabled) { irqstate_t flags; up_rtc_gettime(ts); flags = spin_lock_irqsave(NULL); clock_timespec_subtract(ts, &g_basetime, ts); spin_unlock_irqrestore(NULL, flags); } else { ts->tv_sec = 0; ts->tv_nsec = 0; } #elif defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT) clock_t ticks = 0; up_timer_gettick(&ticks); clock_ticks2time(ts, ticks); #elif defined(CONFIG_SCHED_TICKLESS) up_timer_gettime(ts); #elif defined(CONFIG_TIMER_ARCH) || \ defined(CONFIG_ALARM_ARCH) static struct timespec base = {0}; if (!base.tv_sec && !base.tv_nsec) { up_timer_gettime(&base); } up_timer_gettime(ts); clock_timespec_subtract(ts, &base, ts); #else clock_ticks2time(ts, g_system_ticks); #endif return 0; } ``` I think it might be better to add this base time initialization in the `clock_initialize`(sched/clock/clock_initialize.c). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org