From c6718a5bca0094f2a7c5199ed39a503b2599baf4 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 20 Jan 2019 17:28:55 +0100 Subject: [PATCH] Posix: Add initial stub for atomic HRT The actual implementation is not atomic, as the value on the application layer would be limited. --- platforms/posix/src/px4_layer/drv_hrt.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platforms/posix/src/px4_layer/drv_hrt.cpp b/platforms/posix/src/px4_layer/drv_hrt.cpp index fb50fb9014..06b3e5d764 100644 --- a/platforms/posix/src/px4_layer/drv_hrt.cpp +++ b/platforms/posix/src/px4_layer/drv_hrt.cpp @@ -211,6 +211,20 @@ hrt_abstime hrt_elapsed_time(const volatile hrt_abstime *then) return delta; } +/* + * Compute the delta between a timestamp taken in the past + * and now. + * + * This function is safe to use even if the timestamp is updated + * by an interrupt during execution. + */ +hrt_abstime hrt_elapsed_time_atomic(const volatile hrt_abstime *then) +{ + // This is not atomic as the value on the application layer of POSIX is limited. + hrt_abstime delta = hrt_absolute_time() - *then; + return delta; +} + /* * Store the absolute time in an interrupt-safe fashion. *