Fixes to clock bias logic. Remove vestiges of g_tickbias; apply bias instead to g_basetime

This commit is contained in:
Gregory Nutt 2014-09-10 16:36:25 -06:00
parent c99c9ccb03
commit c19659d7d2
3 changed files with 23 additions and 19 deletions

View File

@ -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;
/********************************************************************************

View File

@ -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;
}
/****************************************************************************

View File

@ -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
{