This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c02024b45dc6bb2d9b5a59b9d0e200f3c970abf1 Author: yushuailong <[email protected]> AuthorDate: Sat Sep 12 15:39:49 2026 +0800 sched/clock: Keep RTC synchronized with timekeeping. Move RTC synchronization outside the non-timekeeping branch so setting CLOCK_REALTIME also updates the RTC when CONFIG_CLOCK_TIMEKEEPING is enabled. This prevents corrected wall time from reverting to an older RTC value after restart. Preserve the existing low-priority work queue path for RTC drivers that may block while updating hardware. Assisted-by: OpenAI Codex Signed-off-by: yushuailong <[email protected]> --- sched/clock/clock_settime.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sched/clock/clock_settime.c b/sched/clock/clock_settime.c index d0890f1b706..e028c39a163 100644 --- a/sched/clock/clock_settime.c +++ b/sched/clock/clock_settime.c @@ -89,12 +89,16 @@ static void nxclock_set_realtime(FAR const struct timespec *tp) spin_unlock_irqrestore(&g_basetime_lock, flags); +#else + clock_timekeeping_set_wall_time(tp); +#endif + /* Setup the RTC (lo- or high-res) */ -# ifdef CONFIG_RTC +#ifdef CONFIG_RTC if (g_rtc_enabled) { -# ifdef CONFIG_SCHED_LPWORK +# ifdef CONFIG_SCHED_LPWORK /* Setting the current time in RTC may be a blocking operation (driver * needs to wait for oscillator stabilization after reset and so on). * This may cause the unwanted effect of clock_settime blocking the @@ -109,19 +113,16 @@ static void nxclock_set_realtime(FAR const struct timespec *tp) g_rtc_to_set = *tp; work_queue(LPWORK, &g_rtc_work, rtc_worker, (FAR void *)&g_rtc_to_set, 0); -# else +# else up_rtc_settime(tp); -# endif - } # endif + } +#endif -# ifdef CONFIG_CLOCK_ADJTIME +#if defined(CONFIG_CLOCK_ADJTIME) && !defined(CONFIG_CLOCK_TIMEKEEPING) /* Cancel any ongoing adjustment */ adjtime(&zerodelta, NULL); -# endif -#else - clock_timekeeping_set_wall_time(tp); #endif }
