sched/clock/ timekeeping: Use clock_basetime() to initialize g_clock_wall_time to get the best initial RTC value and initialize g_clock_last_counter too since the hardware may not start counting from zero.

This commit is contained in:
Xiang Xiao 2018-11-12 07:00:41 -06:00 committed by Gregory Nutt
parent 2bc709d4b9
commit f337cc1380
3 changed files with 8 additions and 17 deletions

View File

@ -87,6 +87,8 @@ extern struct timespec g_basetime;
* Public Function Prototypes
****************************************************************************/
int clock_basetime(FAR struct timespec *tp);
void weak_function clock_initialize(void);
#ifndef CONFIG_SCHED_TICKLESS
void weak_function clock_timer(void);

View File

@ -91,7 +91,7 @@ struct timespec g_basetime;
#if defined(CONFIG_RTC_DATETIME)
/* Initialize the system time using a broken out date/time structure */
static inline int clock_basetime(FAR struct timespec *tp)
int clock_basetime(FAR struct timespec *tp)
{
struct tm rtctime;
long nsecs = 0;
@ -119,7 +119,7 @@ static inline int clock_basetime(FAR struct timespec *tp)
/* Initialize the system time using a high-resolution structure */
static inline int clock_basetime(FAR struct timespec *tp)
int clock_basetime(FAR struct timespec *tp)
{
/* Get the complete time from the hi-res RTC. */
@ -130,7 +130,7 @@ static inline int clock_basetime(FAR struct timespec *tp)
/* Initialize the system time using seconds only */
static inline int clock_basetime(FAR struct timespec *tp)
int clock_basetime(FAR struct timespec *tp)
{
/* Get the seconds (only) from the lo-resolution RTC */
@ -142,7 +142,7 @@ static inline int clock_basetime(FAR struct timespec *tp)
#endif /* CONFIG_RTC_HIRES */
#else /* CONFIG_RTC */
static inline int clock_basetime(FAR struct timespec *tp)
int clock_basetime(FAR struct timespec *tp)
{
time_t jdn = 0;

View File

@ -292,20 +292,9 @@ errout_in_critical_section:
void clock_inittimekeeping(void)
{
struct tm rtctime;
up_timer_getmask(&g_clock_mask);
/* Get the broken-errout_in_critical_section time from the date/time RTC. */
(void)up_rtc_getdatetime(&rtctime);
/* And use the broken-errout_in_critical_section time to initialize the
* system time.
*/
g_clock_wall_time.tv_sec = mktime(&rtctime);
g_clock_wall_time.tv_nsec = 0;
clock_basetime(&g_clock_wall_time);
up_timer_getcounter(&g_clock_last_counter);
}
#endif /* CONFIG_CLOCK_TIMEKEEPING */