OSDN Git Service

Correct timestamps read from the timestamp iio channel
[android-x86/hardware-intel-libsensors.git] / utils.c
diff --git a/utils.c b/utils.c
index b8a12ac..dbfd48e 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -257,6 +257,7 @@ int decode_type_spec(       const char type_buf[MAX_TYPE_SPEC_LEN],
        return storagebits / 8;
 }
 
+
 int64_t load_timestamp_monotonic(struct timespec *ts)
 {
        clock_gettime(CLOCK_MONOTONIC, ts);
@@ -264,6 +265,7 @@ int64_t load_timestamp_monotonic(struct timespec *ts)
        return (1000000000LL * ts->tv_sec + ts->tv_nsec);
 }
 
+
 int64_t load_timestamp_sys_clock(void)
 {
        static int s_fd = -1;
@@ -288,6 +290,17 @@ int64_t load_timestamp_sys_clock(void)
        return 1000000000LL * ts.tv_sec + ts.tv_nsec;
 }
 
+
+int64_t get_timestamp_realtime (void)
+{
+       struct timespec ts = {0};
+
+       clock_gettime(CLOCK_REALTIME, &ts);
+
+       return 1000000000LL * ts.tv_sec + ts.tv_nsec;
+}
+
+
 int64_t get_timestamp_monotonic(void)
 {
        struct timespec ts = {0};
@@ -295,11 +308,13 @@ int64_t get_timestamp_monotonic(void)
        return load_timestamp_monotonic(&ts);
 }
 
+
 int64_t get_timestamp(void)
 {
        return (get_timestamp_monotonic() + ts_delta);
 }
 
+
 void set_timestamp(struct timespec *out, int64_t target_ns)
 {
        out->tv_sec  = target_ns / 1000000000LL;