mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 07:12:54 +08:00
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:
@@ -87,6 +87,8 @@ extern struct timespec g_basetime;
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
int clock_basetime(FAR struct timespec *tp);
|
||||||
|
|
||||||
void weak_function clock_initialize(void);
|
void weak_function clock_initialize(void);
|
||||||
#ifndef CONFIG_SCHED_TICKLESS
|
#ifndef CONFIG_SCHED_TICKLESS
|
||||||
void weak_function clock_timer(void);
|
void weak_function clock_timer(void);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ struct timespec g_basetime;
|
|||||||
#if defined(CONFIG_RTC_DATETIME)
|
#if defined(CONFIG_RTC_DATETIME)
|
||||||
/* Initialize the system time using a broken out date/time structure */
|
/* 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;
|
struct tm rtctime;
|
||||||
long nsecs = 0;
|
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 */
|
/* 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. */
|
/* 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 */
|
/* 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 */
|
/* 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 */
|
#endif /* CONFIG_RTC_HIRES */
|
||||||
#else /* CONFIG_RTC */
|
#else /* CONFIG_RTC */
|
||||||
|
|
||||||
static inline int clock_basetime(FAR struct timespec *tp)
|
int clock_basetime(FAR struct timespec *tp)
|
||||||
{
|
{
|
||||||
time_t jdn = 0;
|
time_t jdn = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -292,20 +292,9 @@ errout_in_critical_section:
|
|||||||
|
|
||||||
void clock_inittimekeeping(void)
|
void clock_inittimekeeping(void)
|
||||||
{
|
{
|
||||||
struct tm rtctime;
|
|
||||||
|
|
||||||
up_timer_getmask(&g_clock_mask);
|
up_timer_getmask(&g_clock_mask);
|
||||||
|
clock_basetime(&g_clock_wall_time);
|
||||||
/* Get the broken-errout_in_critical_section time from the date/time RTC. */
|
up_timer_getcounter(&g_clock_last_counter);
|
||||||
|
|
||||||
(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_CLOCK_TIMEKEEPING */
|
#endif /* CONFIG_CLOCK_TIMEKEEPING */
|
||||||
|
|||||||
Reference in New Issue
Block a user