summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-08-11 11:14:40 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-08-11 11:14:40 -0600
commit33f3ea3ada8196c7335dc381e053f7ed3d69eb3e (patch)
tree99a0e636a37d70769df079dd24beed6bc6243411
parent734bd055a1fd06fbf2e6645e2ce2c8f0cd82e71b (diff)
downloadnuttx-33f3ea3ada8196c7335dc381e053f7ed3d69eb3e.tar.gz
nuttx-33f3ea3ada8196c7335dc381e053f7ed3d69eb3e.tar.bz2
nuttx-33f3ea3ada8196c7335dc381e053f7ed3d69eb3e.zip
Fix inaccurate time conversion. Remove MSEC_PER_TICK and convert uint32_t to uin64_t.
-rw-r--r--nuttx/sched/sched/sched_timerexpiration.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/nuttx/sched/sched/sched_timerexpiration.c b/nuttx/sched/sched/sched_timerexpiration.c
index 2bc737ecb..0378775c1 100644
--- a/nuttx/sched/sched/sched_timerexpiration.c
+++ b/nuttx/sched/sched/sched_timerexpiration.c
@@ -290,8 +290,13 @@ static unsigned int sched_timer_process(unsigned int ticks, bool noswitches)
static void sched_timer_start(unsigned int ticks)
{
- uint32_t msecs;
- uint32_t secs;
+#ifdef CONFIG_HAVE_LONG_LONG
+ uint64_t usecs;
+ uint64_t secs;
+#else
+ uint64_t usecs;
+ uint64_t secs;
+#endif
uint32_t nsecs;
int ret;
@@ -308,11 +313,18 @@ static void sched_timer_start(unsigned int ticks)
/* Convert ticks to a struct timespec that up_timer_start() can
* understand.
+ *
+ * REVISIT: Calculations may not have acceptable ragne if uint64_t
+ * is not supported(?)
*/
- msecs = TICK2MSEC(ticks);
- secs = msecs / MSEC_PER_SEC;
- nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
+#ifdef CONFIG_HAVE_LONG_LONG
+ usecs = TICK2USEC((uint64_t)ticks);
+#else
+ usecs = TICK2USEC((uint64_t)ticks);
+#endif
+ secs = usecs / USEC_PER_SEC;
+ nsecs = (usecs - (secs * USEC_PER_SEC)) * NSEC_PER_MSEC;
ts.tv_sec = (time_t)secs;
ts.tv_nsec = (long)nsecs;