From 0863e771a99553e83bdbf5bdf4b8fe71fc7cf6b0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 26 Apr 2019 07:24:57 -0600 Subject: [PATCH] Revert "sched/clock/clock_initialize.c: clock_inittime() needs to be done with CONFIG_SCHED_TICKLESS and clock_initialize should skip clock_inittime() for external RTC case since the RTC isn't ready yet." This reverts commit 2bc709d4b99447f8decdc7580fdabab6dd8939b1. Commit 2bc709d4b99447f8decdc7580fdabab6dd8939b1 was intended to handle the case where up_timer_gettime may not start from zero case. However, this change has the side-effect of breaking every implementation of tickless mode: After this change the tickless timer structures are used before they are initialized in clock_inittime(). Initialization happens later when up_initialize is called() when arm_timer_initialize(). Since the tickless mode timer is very special, one solution might be to 1. Rename xxx_timer_initialize to up_timer_initialize 2 Move up_timer_initialize to include/nuttx/arch.h 3. Call it from clock subsystem instead up_initialize Basically, this change make timer initialization almost same as rtc initialization(up_rtc_initialize). For now, however, we just need to revert the change. --- sched/clock/clock_initialize.c | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 1034fc2c5f1..8d770e388a1 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -65,9 +65,9 @@ #ifndef CONFIG_SCHED_TICKLESS #ifdef CONFIG_SYSTEM_TIME64 -volatile uint64_t g_system_timer = INITIAL_SYSTEM_TIMER_TICKS; +volatile uint64_t g_system_timer; #else -volatile uint32_t g_system_timer = INITIAL_SYSTEM_TIMER_TICKS; +volatile uint32_t g_system_timer; #endif #endif @@ -170,31 +170,37 @@ int clock_basetime(FAR struct timespec *tp) * ****************************************************************************/ -#ifdef CONFIG_RTC static void clock_inittime(void) { /* (Re-)initialize the time value to match the RTC */ #ifndef CONFIG_CLOCK_TIMEKEEPING - struct timespec ts; - +#ifndef CONFIG_RTC_HIRES clock_basetime(&g_basetime); - clock_systimespec(&ts); +#endif +#ifndef CONFIG_SCHED_TICKLESS + g_system_timer = INITIAL_SYSTEM_TIMER_TICKS; + if (g_system_timer > 0) + { + struct timespec ts; - /* Adjust base time to hide initial timer ticks. */ + (void)clock_ticks2time((sclock_t)g_system_timer, &ts); - g_basetime.tv_sec -= ts.tv_sec; - g_basetime.tv_nsec -= ts.tv_nsec; - while (g_basetime.tv_nsec < 0) - { - g_basetime.tv_nsec += NSEC_PER_SEC; - g_basetime.tv_sec--; + /* Adjust base time to hide initial timer ticks. */ + + g_basetime.tv_sec -= ts.tv_sec; + g_basetime.tv_nsec -= ts.tv_nsec; + while (g_basetime.tv_nsec < 0) + { + g_basetime.tv_nsec += NSEC_PER_SEC; + g_basetime.tv_sec--; + } } +#endif /* !CONFIG_SCHED_TICKLESS */ #else clock_inittimekeeping(); #endif } -#endif /**************************************************************************** * Public Functions @@ -216,11 +222,11 @@ void clock_initialize(void) */ up_rtc_initialize(); +#endif /* Initialize the time value to match the RTC */ clock_inittime(); -#endif } /****************************************************************************