aboutsummaryrefslogtreecommitdiff
path: root/unittests/hrt.cpp
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-12-20 13:54:58 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-12-20 13:54:58 +0100
commit6e0cf5002914e9045082bdfe1d3acc484a37f7fb (patch)
treedceede05053ad0fb51e641e7e26509b4d1309dee /unittests/hrt.cpp
parent19d5383c56b78132e63ea30ef1625b0aaa4a0dee (diff)
downloadpx4-firmware-6e0cf5002914e9045082bdfe1d3acc484a37f7fb.tar.gz
px4-firmware-6e0cf5002914e9045082bdfe1d3acc484a37f7fb.tar.bz2
px4-firmware-6e0cf5002914e9045082bdfe1d3acc484a37f7fb.zip
Move unittests into a more perceivable directory
Diffstat (limited to 'unittests/hrt.cpp')
-rw-r--r--unittests/hrt.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/unittests/hrt.cpp b/unittests/hrt.cpp
new file mode 100644
index 000000000..01b5958b7
--- /dev/null
+++ b/unittests/hrt.cpp
@@ -0,0 +1,16 @@
+#include <sys/time.h>
+#include <inttypes.h>
+#include <drivers/drv_hrt.h>
+#include <stdio.h>
+
+hrt_abstime hrt_absolute_time() {
+ struct timeval te;
+ gettimeofday(&te, NULL); // get current time
+ hrt_abstime us = static_cast<uint64_t>(te.tv_sec) * 1e6 + te.tv_usec; // caculate us
+ return us;
+}
+
+hrt_abstime hrt_elapsed_time(const volatile hrt_abstime *then) {
+ // not thread safe
+ return hrt_absolute_time() - *then;
+}