summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-08-15 17:48:07 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-08-15 17:48:07 -0600
commit6db7b8dcbd90d31329c82bb884d9f2dc5c6da23b (patch)
tree23ec99dfbfc21d227b2a5d02cf9e022bd8609f44
parentd1c4ecb9da0dc7a8e4cba304c60ca6e33595704c (diff)
downloadnuttx-6db7b8dcbd90d31329c82bb884d9f2dc5c6da23b.tar.gz
nuttx-6db7b8dcbd90d31329c82bb884d9f2dc5c6da23b.tar.bz2
nuttx-6db7b8dcbd90d31329c82bb884d9f2dc5c6da23b.zip
Don't do 64-bit calculations if accuracy not achievable; Fix compile error in high res RTC mode
-rw-r--r--nuttx/sched/clock/clock_systimespec.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/nuttx/sched/clock/clock_systimespec.c b/nuttx/sched/clock/clock_systimespec.c
index cacdf0ae9..c24daa70c 100644
--- a/nuttx/sched/clock/clock_systimespec.c
+++ b/nuttx/sched/clock/clock_systimespec.c
@@ -78,63 +78,64 @@
int clock_systimespec(FAR struct timespec *ts)
{
- #ifdef CONFIG_RTC_HIRES
+#ifdef CONFIG_RTC_HIRES
/* Do we have a high-resolution RTC that can provide us with the time? */
if (g_rtc_enabled)
{
/* Get the hi-resolution time from the RTC */
- ret = up_rtc_gettime(tp);
+ return up_rtc_gettime(tp);
}
else
#endif
-
+ {
#if defined(CONFIG_SCHED_TICKLESS)
- {
- /* Let the platform time do the work */
+ /* In tickless mode, all timing is controlled by platform-specific
+ * code. Let the platform timer do the work.
+ */
+
+ return up_timer_gettime(ts);
- return up_timer_gettime(ts);
- }
+#elif defined(CONFIG_HAVE_LONG_LONG) && (CONFIG_USEC_PER_TICK % 1000) != 0
+ /* 64-bit microsecond calculations should improve our accuracy. */
-#elif defined(CONFIG_HAVE_LONG_LONG)
- {
- uint64_t usecs;
- uint64_t secs;
- uint64_t nsecs;
+ uint64_t usecs;
+ uint64_t secs;
+ uint64_t nsecs;
- /* Get the time since power-on in seconds and milliseconds */
+ /* Get the time since power-on in seconds and milliseconds */
- usecs = TICK2MSEC(clock_systimer());
- secs = usecs / USEC_PER_SEC;
+ usecs = TICK2MSEC(clock_systimer());
+ secs = usecs / USEC_PER_SEC;
- /* Return the elapsed time in seconds and nanoseconds */
+ /* Return the elapsed time in seconds and nanoseconds */
- nsecs = (usecs - (secs * USEC_PER_SEC)) * NSEC_PER_USEC;
+ nsecs = (usecs - (secs * USEC_PER_SEC)) * NSEC_PER_USEC;
- ts->tv_sec = (time_t)secs;
- ts->tv_nsec = (long)nsecs;
- return OK;
- }
+ ts->tv_sec = (time_t)secs;
+ ts->tv_nsec = (long)nsecs;
+ return OK;
#else
- {
- uint32_t msecs;
- uint32_t secs;
- uint32_t nsecs;
+ /* 32-bit millisecond calculations should be just fine. */
- /* Get the time since power-on in seconds and milliseconds */
+ uint32_t msecs;
+ uint32_t secs;
+ uint32_t nsecs;
- msecs = TICK2MSEC(clock_systimer());
- secs = msecs / MSEC_PER_SEC;
+ /* Get the time since power-on in seconds and milliseconds */
- /* Return the elapsed time in seconds and nanoseconds */
+ msecs = TICK2MSEC(clock_systimer());
+ secs = msecs / MSEC_PER_SEC;
- nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
+ /* Return the elapsed time in seconds and nanoseconds */
- ts->tv_sec = (time_t)secs;
- ts->tv_nsec = (long)nsecs;
- return OK;
- }
+ nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
+
+ ts->tv_sec = (time_t)secs;
+ ts->tv_nsec = (long)nsecs;
+ return OK;
#endif
+ }
}