summaryrefslogtreecommitdiff
path: root/nuttx/sched/clock_gettime.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-10-02 14:16:30 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-10-02 14:16:30 +0000
commitbbadecee80cf2f48a43097328bb24b73f236934c (patch)
treee3a769b2f63c911bbc57c0e60b863aa996ea9dbb /nuttx/sched/clock_gettime.c
parent078ff53de7f505ba714be768a94c1e52e7261b3e (diff)
downloadpx4-nuttx-bbadecee80cf2f48a43097328bb24b73f236934c.tar.gz
px4-nuttx-bbadecee80cf2f48a43097328bb24b73f236934c.tar.bz2
px4-nuttx-bbadecee80cf2f48a43097328bb24b73f236934c.zip
Remove support for UTC time; add support for 64-bit time
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4006 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/clock_gettime.c')
-rw-r--r--nuttx/sched/clock_gettime.c133
1 files changed, 42 insertions, 91 deletions
diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c
index fc3a1593a..b146949fb 100644
--- a/nuttx/sched/clock_gettime.c
+++ b/nuttx/sched/clock_gettime.c
@@ -91,127 +91,78 @@
int clock_gettime(clockid_t clock_id, struct timespec *tp)
{
-#ifndef CONFIG_SYSTEM_UTC
+#ifdef CONFIG_SYSTEM_TIME64
+ uint64_t msecs;
+ uint64_t secs;
+ uint64_t nsecs;
+#else
uint32_t msecs;
uint32_t secs;
uint32_t nsecs;
-#else
- uint32_t system_utc;
- uint32_t tickcount;
-#endif
-#if defined(CONFIG_RTC) || defined(CONFIG_SYSTEM_UTC)
- irqstate_t flags;
#endif
-
int ret = OK;
sdbg("clock_id=%d\n", clock_id);
+ DEBUGASSERT(tp != NULL);
/* CLOCK_REALTIME - POSIX demands this to be present. This is the wall
* time clock.
*/
- if (clock_id == CLOCK_REALTIME && tp)
+ if (clock_id == CLOCK_REALTIME)
{
- /* If CONFIG_SYSTEM_UTC is not defined, then we have to get the time
- * from g_system_timer.
- */
-
-#ifndef CONFIG_SYSTEM_UTC
-
- /* Get the elapsed time since power up (in milliseconds) biased
- * as appropriate.
- */
-
- msecs = MSEC_PER_TICK * (clock_systimer() - g_tickbias);
-
- sdbg("msecs = %d g_tickbias=%d\n",
- (int)msecs, (int)g_tickbias);
-
- /* Get the elapsed time in seconds and nanoseconds. */
-
- secs = msecs / MSEC_PER_SEC;
- nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
-
- sdbg("secs = %d + %d nsecs = %d + %d\n",
- (int)msecs, (int)g_basetime.tv_sec,
- (int)nsecs, (int)g_basetime.tv_nsec);
-
- /* Add the base time to this. */
-
- secs += (uint32_t)g_basetime.tv_sec;
- nsecs += (uint32_t)g_basetime.tv_nsec;
-
- /* Handle carry to seconds. */
-
- if (nsecs > NSEC_PER_SEC)
- {
- uint32_t dwCarrySecs = nsecs / NSEC_PER_SEC;
- secs += dwCarrySecs;
- nsecs -= (dwCarrySecs * NSEC_PER_SEC);
- }
-
- /* And return the result to the caller. */
-
- tp->tv_sec = (time_t)secs;
- tp->tv_nsec = (long)nsecs;
-
-#else /* CONFIG_SYSTEM_UTC */
-
- /* CONFIG_SYSTEM_UTC is defined. But we might be able to get the time
- * from the hardware if a high resolution RTC is available.
- */
+ /* Do we have a high-resolution RTC that can provie us with the time? */
#ifdef CONFIG_RTC_HIRES
if (g_rtc_enabled)
{
- /* Get the hi-resolution time from the RTC */
+ /* Yes.. Get the hi-resolution time from the RTC */
ret = up_rtc_gettime(tp);
}
else
#endif
{
- /* Disable interrupts while g_system_utc and g_tickcount are sampled
- * so that we can be assured that g_system_utc and g_tickcount are based
- * at the same point in time.
+ /* Get the elapsed time since power up (in milliseconds) biased
+ * as appropriate.
*/
- flags = irqsave();
- system_utc = g_system_utc;
- tickcount = g_tickcount;
- irqrestore(flags);
+ msecs = MSEC_PER_TICK * (g_system_timer - g_tickbias);
- tp->tv_sec = system_utc;
- tp->tv_nsec = tickcount * (1000000000/TICK_PER_SEC);
- }
-#endif /* CONFIG_SYSTEM_UTC */
+ sdbg("msecs = %d g_tickbias=%d\n",
+ (int)msecs, (int)g_tickbias);
- sdbg("Returning tp=(%d,%d)\n", (int)tp->tv_sec, (int)tp->tv_nsec);
- }
+ /* Get the elapsed time in seconds and nanoseconds. */
- /* CLOCK_ACTIVETIME is non-standard. Returns active UTC time, which is
- * disabled during power down modes. Unit is 1 second.
- */
+ secs = msecs / MSEC_PER_SEC;
+ nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
-#ifdef CONFIG_SYSTEM_UTC
- else if (clock_id == CLOCK_ACTIVETIME && g_rtc_enabled && tp)
- {
- /* Disable interrupts while g_system_utc and g_tickcount are sampled
- * so that we can be assured that g_system_utc and g_tickcount are based
- * at the same point in time.
- */
-
- flags = irqsave();
- system_utc = g_system_utc;
- tickcount = g_tickcount;
- irqrestore(flags);
-
- tp->tv_sec = system_utc;
- tp->tv_nsec = tickcount * (1000000000/TICK_PER_SEC);
- }
-#endif
+ sdbg("secs = %d + %d nsecs = %d + %d\n",
+ (int)msecs, (int)g_basetime.tv_sec,
+ (int)nsecs, (int)g_basetime.tv_nsec);
+
+ /* Add the base time to this. */
+ secs += (uint32_t)g_basetime.tv_sec;
+ nsecs += (uint32_t)g_basetime.tv_nsec;
+
+ /* Handle carry to seconds. */
+
+ if (nsecs > NSEC_PER_SEC)
+ {
+ uint32_t dwCarrySecs = nsecs / NSEC_PER_SEC;
+ secs += dwCarrySecs;
+ nsecs -= (dwCarrySecs * NSEC_PER_SEC);
+ }
+
+ /* And return the result to the caller. */
+
+ tp->tv_sec = (time_t)secs;
+ tp->tv_nsec = (long)nsecs;
+ }
+
+ sdbg("Returning tp=(%d,%d)\n", (int)tp->tv_sec, (int)tp->tv_nsec);
+ }
else
{
sdbg("Returning ERROR\n");