mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
clock: update clock_synchronize() to support with time
Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
@@ -221,7 +221,7 @@ int sam_bringup(void)
|
|||||||
{
|
{
|
||||||
/* Synchronize the system time to the RTC time */
|
/* 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 */
|
/* Synchronize the system time to the RTC time */
|
||||||
|
|
||||||
clock_synchronize();
|
clock_synchronize(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ static void stm32_idlepm(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC
|
#ifdef CONFIG_RTC
|
||||||
clock_synchronize();
|
clock_synchronize(NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ int stm32_ds1307_init(void)
|
|||||||
|
|
||||||
/* Synchronize the system time to the RTC time */
|
/* Synchronize the system time to the RTC time */
|
||||||
|
|
||||||
clock_synchronize();
|
clock_synchronize(NULL);
|
||||||
|
|
||||||
/* Now we are initialized */
|
/* 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
|
#ifdef CONFIG_RTC_EXTERNAL
|
||||||
if (sync)
|
if (sync)
|
||||||
{
|
{
|
||||||
clock_synchronize();
|
clock_synchronize(NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
* current system time to match.
|
* 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.
|
* timers and delays. So use this interface with care.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None
|
* tp: rtc time should be synced, set NULL to re-get time
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
@@ -332,7 +332,7 @@ void clock_timespec_subtract(FAR const struct timespec *ts1,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC
|
#ifdef CONFIG_RTC
|
||||||
void clock_synchronize(void);
|
void clock_synchronize(FAR const struct timespec *tp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -155,14 +155,22 @@ int clock_basetime(FAR struct timespec *tp)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC
|
#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 */
|
/* (Re-)initialize the time value to match the RTC */
|
||||||
|
|
||||||
#ifndef CONFIG_CLOCK_TIMEKEEPING
|
#ifndef CONFIG_CLOCK_TIMEKEEPING
|
||||||
struct timespec ts;
|
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);
|
clock_systime_timespec(&ts);
|
||||||
|
|
||||||
/* Adjust base time to hide initial timer ticks. */
|
/* Adjust base time to hide initial timer ticks. */
|
||||||
@@ -175,7 +183,7 @@ static void clock_inittime(void)
|
|||||||
g_basetime.tv_sec--;
|
g_basetime.tv_sec--;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
clock_inittimekeeping();
|
clock_inittimekeeping(tp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -212,7 +220,7 @@ void clock_initialize(void)
|
|||||||
#if !defined(CONFIG_RTC_EXTERNAL)
|
#if !defined(CONFIG_RTC_EXTERNAL)
|
||||||
/* Initialize the time value to match the RTC */
|
/* Initialize the time value to match the RTC */
|
||||||
|
|
||||||
clock_inittime();
|
clock_inittime(NULL);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -236,7 +244,7 @@ void clock_initialize(void)
|
|||||||
* timers and delays. So use this interface with care.
|
* timers and delays. So use this interface with care.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None
|
* tp: rtc time should be synced, set NULL to re-get time
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
@@ -246,14 +254,14 @@ void clock_initialize(void)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC
|
#ifdef CONFIG_RTC
|
||||||
void clock_synchronize(void)
|
void clock_synchronize(FAR const struct timespec *tp)
|
||||||
{
|
{
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
|
||||||
/* Re-initialize the time value to match the RTC */
|
/* Re-initialize the time value to match the RTC */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
clock_inittime();
|
clock_inittime(tp);
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ int clock_timekeeping_set_wall_time(FAR struct timespec *ts)
|
|||||||
goto errout_in_critical_section;
|
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_adjust = 0;
|
||||||
g_clock_last_counter = counter;
|
g_clock_last_counter = counter;
|
||||||
|
|
||||||
@@ -275,10 +276,19 @@ errout_in_critical_section:
|
|||||||
* Name: clock_inittimekeeping
|
* Name: clock_inittimekeeping
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void clock_inittimekeeping(void)
|
void clock_inittimekeeping(FAR const struct timespec *tp)
|
||||||
{
|
{
|
||||||
up_timer_getmask(&g_clock_mask);
|
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);
|
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_update_wall_time(void);
|
||||||
|
|
||||||
void clock_inittimekeeping(void);
|
void clock_inittimekeeping(FAR const struct timespec *tp);
|
||||||
|
|
||||||
#endif /* __SCHED_CLOCK_CLOCK_TIMEKEEPING_H */
|
#endif /* __SCHED_CLOCK_CLOCK_TIMEKEEPING_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user