Fixes to clock bias logic. Remove vestiges of g_tickbias; apply bias instead to g_basetime
This commit is contained in:
parent
c99c9ccb03
commit
c19659d7d2
@ -78,12 +78,6 @@ extern volatile uint32_t g_system_timer;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYSTEM_TIME64
|
||||
extern uint64_t g_tickbias;
|
||||
#else
|
||||
extern uint32_t g_tickbias;
|
||||
#endif
|
||||
|
||||
extern struct timespec g_basetime;
|
||||
|
||||
/********************************************************************************
|
||||
|
@ -88,12 +88,6 @@ volatile uint32_t g_system_timer;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYSTEM_TIME64
|
||||
uint64_t g_tickbias;
|
||||
#else
|
||||
uint32_t g_tickbias;
|
||||
#endif
|
||||
|
||||
struct timespec g_basetime;
|
||||
|
||||
/**************************************************************************
|
||||
@ -191,7 +185,6 @@ static void clock_inittime(void)
|
||||
#ifndef CONFIG_SCHED_TICKLESS
|
||||
g_system_timer = 0;
|
||||
#endif
|
||||
g_tickbias = 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -90,6 +90,7 @@
|
||||
|
||||
int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
|
||||
{
|
||||
struct timespec bias;
|
||||
irqstate_t flags;
|
||||
int ret = OK;
|
||||
|
||||
@ -114,11 +115,27 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
|
||||
g_basetime.tv_sec = tp->tv_sec;
|
||||
g_basetime.tv_nsec = tp->tv_nsec;
|
||||
|
||||
/* Get the elapsed time since power up (in milliseconds) biased
|
||||
* as appropriate.
|
||||
/* Get the elapsed time since power up (in milliseconds). This is a
|
||||
* bias value that we need to use to correct the base time.
|
||||
*/
|
||||
|
||||
g_tickbias = clock_systimer();
|
||||
(void)clock_systimespec(&bias);
|
||||
|
||||
/* Subtract that bias from the basetime so that when the system
|
||||
* timer is again added to the base time, the result is the current
|
||||
* time relative to basetime.
|
||||
*/
|
||||
|
||||
if (g_basetime.tv_nsec < bias.tv_nsec)
|
||||
{
|
||||
g_basetime.tv_nsec += NSEC_PER_SEC;
|
||||
g_basetime.tv_sec--;
|
||||
}
|
||||
|
||||
/* Result could be negative seconds */
|
||||
|
||||
g_basetime.tv_nsec -= bias.tv_nsec;
|
||||
g_basetime.tv_sec -= bias.tv_sec;
|
||||
|
||||
/* Setup the RTC (lo- or high-res) */
|
||||
|
||||
@ -130,9 +147,9 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
|
||||
#endif
|
||||
irqrestore(flags);
|
||||
|
||||
sdbg("basetime=(%d,%d) tickbias=%d\n",
|
||||
(int)g_basetime.tv_sec, (int)g_basetime.tv_nsec,
|
||||
(int)g_tickbias);
|
||||
sdbg("basetime=(%ld,%lu) bias=(%ld,%lu)\n",
|
||||
(long)g_basetime.tv_sec, (unsigned long)g_basetime.tv_nsec,
|
||||
(long)bias.tv_sec, (unsigned long)bias.tv_nsec);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user