This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 15f88804ca drivers/alarm: modify the default precision of
up_perf_gettime to ns
15f88804ca is described below
commit 15f88804caca56ecaf2ca70cb2e2dab61f784659
Author: yinshengkai <[email protected]>
AuthorDate: Wed Aug 30 17:48:55 2023 +0800
drivers/alarm: modify the default precision of up_perf_gettime to ns
Signed-off-by: yinshengkai <[email protected]>
---
drivers/timers/arch_alarm.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/drivers/timers/arch_alarm.c b/drivers/timers/arch_alarm.c
index f77cec97e6..8c73d5591c 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 */