mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
Don't do 64-bit calculations if accuracy not achievable; Fix compile error in high res RTC mode
This commit is contained in:
@@ -78,63 +78,64 @@
|
|||||||
|
|
||||||
int clock_systimespec(FAR struct timespec *ts)
|
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? */
|
/* Do we have a high-resolution RTC that can provide us with the time? */
|
||||||
|
|
||||||
if (g_rtc_enabled)
|
if (g_rtc_enabled)
|
||||||
{
|
{
|
||||||
/* Get the hi-resolution time from the RTC */
|
/* Get the hi-resolution time from the RTC */
|
||||||
|
|
||||||
ret = up_rtc_gettime(tp);
|
return up_rtc_gettime(tp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
#if defined(CONFIG_SCHED_TICKLESS)
|
#if defined(CONFIG_SCHED_TICKLESS)
|
||||||
{
|
/* In tickless mode, all timing is controlled by platform-specific
|
||||||
/* Let the platform time do the work */
|
* code. Let the platform timer do the work.
|
||||||
|
*/
|
||||||
|
|
||||||
return up_timer_gettime(ts);
|
return up_timer_gettime(ts);
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(CONFIG_HAVE_LONG_LONG)
|
#elif defined(CONFIG_HAVE_LONG_LONG) && (CONFIG_USEC_PER_TICK % 1000) != 0
|
||||||
{
|
/* 64-bit microsecond calculations should improve our accuracy. */
|
||||||
uint64_t usecs;
|
|
||||||
uint64_t secs;
|
|
||||||
uint64_t nsecs;
|
|
||||||
|
|
||||||
/* Get the time since power-on in seconds and milliseconds */
|
uint64_t usecs;
|
||||||
|
uint64_t secs;
|
||||||
|
uint64_t nsecs;
|
||||||
|
|
||||||
usecs = TICK2MSEC(clock_systimer());
|
/* Get the time since power-on in seconds and milliseconds */
|
||||||
secs = usecs / USEC_PER_SEC;
|
|
||||||
|
|
||||||
/* Return the elapsed time in seconds and nanoseconds */
|
usecs = TICK2MSEC(clock_systimer());
|
||||||
|
secs = usecs / USEC_PER_SEC;
|
||||||
|
|
||||||
nsecs = (usecs - (secs * USEC_PER_SEC)) * NSEC_PER_USEC;
|
/* Return the elapsed time in seconds and nanoseconds */
|
||||||
|
|
||||||
ts->tv_sec = (time_t)secs;
|
nsecs = (usecs - (secs * USEC_PER_SEC)) * NSEC_PER_USEC;
|
||||||
ts->tv_nsec = (long)nsecs;
|
|
||||||
return OK;
|
ts->tv_sec = (time_t)secs;
|
||||||
}
|
ts->tv_nsec = (long)nsecs;
|
||||||
|
return OK;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
{
|
/* 32-bit millisecond calculations should be just fine. */
|
||||||
uint32_t msecs;
|
|
||||||
uint32_t secs;
|
|
||||||
uint32_t nsecs;
|
|
||||||
|
|
||||||
/* Get the time since power-on in seconds and milliseconds */
|
uint32_t msecs;
|
||||||
|
uint32_t secs;
|
||||||
|
uint32_t nsecs;
|
||||||
|
|
||||||
msecs = TICK2MSEC(clock_systimer());
|
/* Get the time since power-on in seconds and milliseconds */
|
||||||
secs = msecs / MSEC_PER_SEC;
|
|
||||||
|
|
||||||
/* 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;
|
nsecs = (msecs - (secs * MSEC_PER_SEC)) * NSEC_PER_MSEC;
|
||||||
ts->tv_nsec = (long)nsecs;
|
|
||||||
return OK;
|
ts->tv_sec = (time_t)secs;
|
||||||
}
|
ts->tv_nsec = (long)nsecs;
|
||||||
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user