diff --git a/drivers/timers/arch_alarm.c b/drivers/timers/arch_alarm.c index f77cec97e63..8c73d5591c7 100644 --- a/drivers/timers/arch_alarm.c +++ b/drivers/timers/arch_alarm.c @@ -36,8 +36,8 @@ #define CONFIG_BOARD_LOOPSPER10USEC ((CONFIG_BOARD_LOOPSPERMSEC+50)/100) #define CONFIG_BOARD_LOOPSPERUSEC ((CONFIG_BOARD_LOOPSPERMSEC+500)/1000) -#define timespec_to_usec(ts) \ - ((uint64_t)(ts)->tv_sec * USEC_PER_SEC + (ts)->tv_nsec / NSEC_PER_USEC) +#define timespec_to_nsec(ts) \ + ((uint64_t)(ts)->tv_sec * NSEC_PER_SEC + (ts)->tv_nsec) /**************************************************************************** * Private Data @@ -53,12 +53,12 @@ static clock_t g_current_tick; * Private Functions ****************************************************************************/ -static inline void timespec_from_usec(FAR struct timespec *ts, - uint64_t microseconds) +static inline void timespec_from_nsec(FAR struct timespec *ts, + uint64_t nanoseconds) { - ts->tv_sec = microseconds / USEC_PER_SEC; - microseconds -= (uint64_t)ts->tv_sec * USEC_PER_SEC; - ts->tv_nsec = microseconds * NSEC_PER_USEC; + ts->tv_sec = nanoseconds / NSEC_PER_SEC; + nanoseconds -= (uint64_t)ts->tv_sec * NSEC_PER_SEC; + ts->tv_nsec = nanoseconds; } static void udelay_accurate(useconds_t microseconds) @@ -68,7 +68,7 @@ static void udelay_accurate(useconds_t microseconds) struct timespec delta; ONESHOT_CURRENT(g_oneshot_lower, &now); - timespec_from_usec(&delta, microseconds); + timespec_from_nsec(&delta, (uint64_t)microseconds * NSEC_PER_USEC); clock_timespec_add(&now, &delta, &end); while (clock_timespec_compare(&now, &end) < 0) @@ -375,7 +375,7 @@ unsigned long up_perf_gettime(void) struct timespec ts; ONESHOT_CURRENT(g_oneshot_lower, &ts); - ret = timespec_to_usec(&ts); + ret = timespec_to_nsec(&ts); } return ret; @@ -383,13 +383,12 @@ unsigned long up_perf_gettime(void) unsigned long up_perf_getfreq(void) { - return USEC_PER_SEC; + return NSEC_PER_SEC; } -void up_perf_convert(unsigned long elapsed, - FAR struct timespec *ts) +void up_perf_convert(unsigned long elapsed, FAR struct timespec *ts) { - timespec_from_usec(ts, elapsed); + timespec_from_nsec(ts, elapsed); } #endif /* CONFIG_ARCH_PERF_EVENTS */