From 9f049b4dca4870d9bf2d23f7aabcc8949c568820 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Thu, 24 Feb 2022 14:07:24 +0200 Subject: [PATCH] Inline ts_to_abstime and abstime_to_ts Signed-off-by: Jukka Laitinen --- platforms/nuttx/src/px4/nxp/imxrt/hrt/hrt.c | 25 ------------------- platforms/nuttx/src/px4/nxp/kinetis/hrt/hrt.c | 25 ------------------- platforms/nuttx/src/px4/nxp/s32k1xx/hrt/hrt.c | 25 ------------------- .../nuttx/src/px4/rpi/rpi_common/hrt/hrt.c | 23 ----------------- .../nuttx/src/px4/stm/stm32_common/hrt/hrt.c | 25 ------------------- platforms/posix/src/px4/common/drv_hrt.cpp | 20 --------------- src/drivers/drv_hrt.h | 17 +++++++++++-- 7 files changed, 15 insertions(+), 145 deletions(-) diff --git a/platforms/nuttx/src/px4/nxp/imxrt/hrt/hrt.c b/platforms/nuttx/src/px4/nxp/imxrt/hrt/hrt.c index 8e4785362c..7106a1814c 100644 --- a/platforms/nuttx/src/px4/nxp/imxrt/hrt/hrt.c +++ b/platforms/nuttx/src/px4/nxp/imxrt/hrt/hrt.c @@ -561,31 +561,6 @@ hrt_absolute_time(void) return abstime; } -/** - * Convert a timespec to absolute time - */ -hrt_abstime -ts_to_abstime(const struct timespec *ts) -{ - hrt_abstime result; - - result = (hrt_abstime)(ts->tv_sec) * 1000000; - result += ts->tv_nsec / 1000; - - return result; -} - -/** - * Convert absolute time to a timespec. - */ -void -abstime_to_ts(struct timespec *ts, hrt_abstime abstime) -{ - ts->tv_sec = abstime / 1000000; - abstime -= ts->tv_sec * 1000000; - ts->tv_nsec = abstime * 1000; -} - /** * Store the absolute time in an interrupt-safe fashion */ diff --git a/platforms/nuttx/src/px4/nxp/kinetis/hrt/hrt.c b/platforms/nuttx/src/px4/nxp/kinetis/hrt/hrt.c index dbb8b062a4..8956ddf15a 100644 --- a/platforms/nuttx/src/px4/nxp/kinetis/hrt/hrt.c +++ b/platforms/nuttx/src/px4/nxp/kinetis/hrt/hrt.c @@ -573,31 +573,6 @@ hrt_absolute_time(void) return abstime; } -/** - * Convert a timespec to absolute time - */ -hrt_abstime -ts_to_abstime(const struct timespec *ts) -{ - hrt_abstime result; - - result = (hrt_abstime)(ts->tv_sec) * 1000000; - result += ts->tv_nsec / 1000; - - return result; -} - -/** - * Convert absolute time to a timespec. - */ -void -abstime_to_ts(struct timespec *ts, hrt_abstime abstime) -{ - ts->tv_sec = abstime / 1000000; - abstime -= ts->tv_sec * 1000000; - ts->tv_nsec = abstime * 1000; -} - /** * Store the absolute time in an interrupt-safe fashion */ diff --git a/platforms/nuttx/src/px4/nxp/s32k1xx/hrt/hrt.c b/platforms/nuttx/src/px4/nxp/s32k1xx/hrt/hrt.c index 9251398917..71a97c9d81 100644 --- a/platforms/nuttx/src/px4/nxp/s32k1xx/hrt/hrt.c +++ b/platforms/nuttx/src/px4/nxp/s32k1xx/hrt/hrt.c @@ -609,31 +609,6 @@ hrt_absolute_time(void) return abstime; } -/** - * Convert a timespec to absolute time - */ -hrt_abstime -ts_to_abstime(const struct timespec *ts) -{ - hrt_abstime result; - - result = (hrt_abstime)(ts->tv_sec) * 1000000; - result += ts->tv_nsec / 1000; - - return result; -} - -/** - * Convert absolute time to a timespec. - */ -void -abstime_to_ts(struct timespec *ts, hrt_abstime abstime) -{ - ts->tv_sec = abstime / 1000000; - abstime -= ts->tv_sec * 1000000; - ts->tv_nsec = abstime * 1000; -} - /** * Store the absolute time in an interrupt-safe fashion */ diff --git a/platforms/nuttx/src/px4/rpi/rpi_common/hrt/hrt.c b/platforms/nuttx/src/px4/rpi/rpi_common/hrt/hrt.c index dcbf75645d..cbdaec6eb4 100644 --- a/platforms/nuttx/src/px4/rpi/rpi_common/hrt/hrt.c +++ b/platforms/nuttx/src/px4/rpi/rpi_common/hrt/hrt.c @@ -497,29 +497,6 @@ hrt_abstime hrt_absolute_time(void) return ((uint64_t) hi << 32) | lo; } -/** - * Convert a timespec to absolute time - */ -hrt_abstime ts_to_abstime(const struct timespec *ts) -{ - hrt_abstime result; - - result = (hrt_abstime)(ts->tv_sec) * 1000000; - result += ts->tv_nsec / 1000; - - return result; -} - -/** - * Convert absolute time to a timespec. - */ -void abstime_to_ts(struct timespec *ts, hrt_abstime abstime) -{ - ts->tv_sec = abstime / 1000000; - abstime -= ts->tv_sec * 1000000; - ts->tv_nsec = abstime * 1000; -} - /** * Compare a time value with the current time as atomic operation */ diff --git a/platforms/nuttx/src/px4/stm/stm32_common/hrt/hrt.c b/platforms/nuttx/src/px4/stm/stm32_common/hrt/hrt.c index dc35ca82c0..ce63a41c2b 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/hrt/hrt.c +++ b/platforms/nuttx/src/px4/stm/stm32_common/hrt/hrt.c @@ -694,31 +694,6 @@ hrt_absolute_time(void) return abstime; } -/** - * Convert a timespec to absolute time - */ -hrt_abstime -ts_to_abstime(const struct timespec *ts) -{ - hrt_abstime result; - - result = (hrt_abstime)(ts->tv_sec) * 1000000; - result += ts->tv_nsec / 1000; - - return result; -} - -/** - * Convert absolute time to a timespec. - */ -void -abstime_to_ts(struct timespec *ts, hrt_abstime abstime) -{ - ts->tv_sec = abstime / 1000000; - abstime -= ts->tv_sec * 1000000; - ts->tv_nsec = abstime * 1000; -} - /** * Store the absolute time in an interrupt-safe fashion */ diff --git a/platforms/posix/src/px4/common/drv_hrt.cpp b/platforms/posix/src/px4/common/drv_hrt.cpp index d9638d03ee..a75c953f85 100644 --- a/platforms/posix/src/px4/common/drv_hrt.cpp +++ b/platforms/posix/src/px4/common/drv_hrt.cpp @@ -144,19 +144,6 @@ hrt_abstime hrt_absolute_time() #endif // defined(ENABLE_LOCKSTEP_SCHEDULER) } -/* - * Convert a timespec to absolute time. - */ -hrt_abstime ts_to_abstime(const struct timespec *ts) -{ - hrt_abstime result; - - result = (hrt_abstime)(ts->tv_sec) * 1000000; - result += ts->tv_nsec / 1000; - - return result; -} - /* * Store the absolute time in an interrupt-safe fashion. * @@ -484,13 +471,6 @@ hrt_call_invoke() hrt_unlock(); } -void abstime_to_ts(struct timespec *ts, hrt_abstime abstime) -{ - ts->tv_sec = abstime / 1000000; - abstime -= ts->tv_sec * 1000000; - ts->tv_nsec = abstime * 1000; -} - int px4_clock_gettime(clockid_t clk_id, struct timespec *tp) { if (clk_id == CLOCK_MONOTONIC) { diff --git a/src/drivers/drv_hrt.h b/src/drivers/drv_hrt.h index 1b7d61f733..c4d3c12d32 100644 --- a/src/drivers/drv_hrt.h +++ b/src/drivers/drv_hrt.h @@ -97,12 +97,25 @@ __EXPORT extern hrt_abstime hrt_absolute_time(void); /** * Convert a timespec to absolute time. */ -__EXPORT extern hrt_abstime ts_to_abstime(const struct timespec *ts); +static inline hrt_abstime ts_to_abstime(const struct timespec *ts) +{ + hrt_abstime result; + + result = (hrt_abstime)(ts->tv_sec) * 1000000; + result += ts->tv_nsec / 1000; + + return result; +} /** * Convert absolute time to a timespec. */ -__EXPORT extern void abstime_to_ts(struct timespec *ts, hrt_abstime abstime); +static inline void abstime_to_ts(struct timespec *ts, hrt_abstime abstime) +{ + ts->tv_sec = abstime / 1000000; + abstime -= ts->tv_sec * 1000000; + ts->tv_nsec = abstime * 1000; +} /** * Compute the delta between a timestamp taken in the past