diff --git a/boards/arm/samv7/samv71-xult/src/sam_bringup.c b/boards/arm/samv7/samv71-xult/src/sam_bringup.c index 9415ee38e61..ea2c20280eb 100644 --- a/boards/arm/samv7/samv71-xult/src/sam_bringup.c +++ b/boards/arm/samv7/samv71-xult/src/sam_bringup.c @@ -221,7 +221,7 @@ int sam_bringup(void) { /* Synchronize the system time to the RTC time */ - clock_synchronize(); + clock_synchronize(NULL); } } @@ -248,7 +248,7 @@ int sam_bringup(void) { /* Synchronize the system time to the RTC time */ - clock_synchronize(); + clock_synchronize(NULL); } } #endif diff --git a/boards/arm/stm32/stm3210e-eval/src/stm32_idle.c b/boards/arm/stm32/stm3210e-eval/src/stm32_idle.c index 5d919022c20..b114650241e 100644 --- a/boards/arm/stm32/stm3210e-eval/src/stm32_idle.c +++ b/boards/arm/stm32/stm3210e-eval/src/stm32_idle.c @@ -316,7 +316,7 @@ static void stm32_idlepm(void) */ #ifdef CONFIG_RTC - clock_synchronize(); + clock_synchronize(NULL); #endif } } diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_ds1307.c b/boards/arm/stm32/stm32f4discovery/src/stm32_ds1307.c index cd54d710c20..c8fa448e97f 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_ds1307.c +++ b/boards/arm/stm32/stm32f4discovery/src/stm32_ds1307.c @@ -100,7 +100,7 @@ int stm32_ds1307_init(void) /* Synchronize the system time to the RTC time */ - clock_synchronize(); + clock_synchronize(NULL); /* Now we are initialized */ diff --git a/drivers/timers/arch_rtc.c b/drivers/timers/arch_rtc.c index c6c3cc10ed5..041d868e147 100644 --- a/drivers/timers/arch_rtc.c +++ b/drivers/timers/arch_rtc.c @@ -58,7 +58,7 @@ void up_rtc_set_lowerhalf(FAR struct rtc_lowerhalf_s *lower, bool sync) #ifdef CONFIG_RTC_EXTERNAL if (sync) { - clock_synchronize(); + clock_synchronize(NULL); } #endif } diff --git a/drivers/timers/rtc.c b/drivers/timers/rtc.c index d92b13009f0..4103f27f667 100644 --- a/drivers/timers/rtc.c +++ b/drivers/timers/rtc.c @@ -401,7 +401,7 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * current system time to match. */ - clock_synchronize(); + clock_synchronize(NULL); } } } diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 55e49c6b297..0e0b4091c73 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -322,7 +322,7 @@ void clock_timespec_subtract(FAR const struct timespec *ts1, * timers and delays. So use this interface with care. * * Input Parameters: - * None + * tp: rtc time should be synced, set NULL to re-get time * * Returned Value: * None @@ -332,7 +332,7 @@ void clock_timespec_subtract(FAR const struct timespec *ts1, ****************************************************************************/ #ifdef CONFIG_RTC -void clock_synchronize(void); +void clock_synchronize(FAR const struct timespec *tp); #endif /**************************************************************************** diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 9afafaa1a6f..090bdb7f081 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -155,14 +155,22 @@ int clock_basetime(FAR struct timespec *tp) ****************************************************************************/ #ifdef CONFIG_RTC -static void clock_inittime(void) +static void clock_inittime(FAR const struct timespec *tp) { /* (Re-)initialize the time value to match the RTC */ #ifndef CONFIG_CLOCK_TIMEKEEPING struct timespec ts; - clock_basetime(&g_basetime); + if (tp) + { + memcpy(&g_basetime, tp, sizeof(struct timespec)); + } + else + { + clock_basetime(&g_basetime); + } + clock_systime_timespec(&ts); /* Adjust base time to hide initial timer ticks. */ @@ -175,7 +183,7 @@ static void clock_inittime(void) g_basetime.tv_sec--; } #else - clock_inittimekeeping(); + clock_inittimekeeping(tp); #endif } #endif @@ -212,7 +220,7 @@ void clock_initialize(void) #if !defined(CONFIG_RTC_EXTERNAL) /* Initialize the time value to match the RTC */ - clock_inittime(); + clock_inittime(NULL); #endif #endif } @@ -236,7 +244,7 @@ void clock_initialize(void) * timers and delays. So use this interface with care. * * Input Parameters: - * None + * tp: rtc time should be synced, set NULL to re-get time * * Returned Value: * None @@ -246,14 +254,14 @@ void clock_initialize(void) ****************************************************************************/ #ifdef CONFIG_RTC -void clock_synchronize(void) +void clock_synchronize(FAR const struct timespec *tp) { irqstate_t flags; /* Re-initialize the time value to match the RTC */ flags = enter_critical_section(); - clock_inittime(); + clock_inittime(tp); leave_critical_section(flags); } #endif diff --git a/sched/clock/clock_timekeeping.c b/sched/clock/clock_timekeeping.c index 38d55e1e402..9d9845ca4fd 100644 --- a/sched/clock/clock_timekeeping.c +++ b/sched/clock/clock_timekeeping.c @@ -129,7 +129,8 @@ int clock_timekeeping_set_wall_time(FAR struct timespec *ts) goto errout_in_critical_section; } - g_clock_wall_time = *ts; + memcpy(&g_clock_wall_time, ts, sizeof(struct timespec)); + g_clock_adjust = 0; g_clock_last_counter = counter; @@ -275,10 +276,19 @@ errout_in_critical_section: * Name: clock_inittimekeeping ****************************************************************************/ -void clock_inittimekeeping(void) +void clock_inittimekeeping(FAR const struct timespec *tp) { up_timer_getmask(&g_clock_mask); - clock_basetime(&g_clock_wall_time); + + if (tp) + { + memcpy(&g_clock_wall_time, tp, sizeof(struct timespec)); + } + else + { + clock_basetime(&g_clock_wall_time); + } + up_timer_getcounter(&g_clock_last_counter); } diff --git a/sched/clock/clock_timekeeping.h b/sched/clock/clock_timekeeping.h index b58e7058ced..e0a627933a2 100644 --- a/sched/clock/clock_timekeeping.h +++ b/sched/clock/clock_timekeeping.h @@ -41,6 +41,6 @@ int clock_timekeeping_set_wall_time(FAR struct timespec *ts); void clock_update_wall_time(void); -void clock_inittimekeeping(void); +void clock_inittimekeeping(FAR const struct timespec *tp); #endif /* __SCHED_CLOCK_CLOCK_TIMEKEEPING_H */