mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
clock: update clock_synchronize() to support with time
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
0a51f13ca5
commit
cb502a869c
9 changed files with 37 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -316,7 +316,7 @@ static void stm32_idlepm(void)
|
|||
*/
|
||||
|
||||
#ifdef CONFIG_RTC
|
||||
clock_synchronize();
|
||||
clock_synchronize(NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue