}
-int decode_type_spec( const char type_buf[MAX_TYPE_SPEC_LEN],
- struct datum_info_t *type_info)
+int64_t get_timestamp_realtime (void)
{
- /* Return size in bytes for this type specification, or -1 in error */
- char sign;
- char endianness;
- unsigned int realbits, storagebits, shift;
- int tokens;
-
- /* Valid specs: "le:u10/16>>0", "le:s16/32>>0" or "le:s32/32>>0" */
-
- tokens = sscanf(type_buf, "%ce:%c%u/%u>>%u",
- &endianness, &sign, &realbits, &storagebits, &shift);
-
- if (tokens != 5 ||
- (endianness != 'b' && endianness != 'l') ||
- (sign != 'u' && sign != 's') ||
- realbits > storagebits ||
- (storagebits != 16 && storagebits != 32 && storagebits != 64)) {
- ALOGE("Invalid iio channel type spec: %s\n", type_buf);
- return -1;
- }
-
- type_info->endianness = endianness;
- type_info->sign = sign;
- type_info->realbits = (short) realbits;
- type_info->storagebits = (short) storagebits;
- type_info->shift = (short) shift;
-
- return storagebits / 8;
-}
-
-int64_t load_timestamp_monotonic(struct timespec *ts)
-{
- clock_gettime(CLOCK_MONOTONIC, ts);
+ struct timespec ts = {0};
+ clock_gettime(CLOCK_REALTIME, &ts);
- return (1000000000LL * ts->tv_sec + ts->tv_nsec);
+ return 1000000000LL * ts.tv_sec + ts.tv_nsec;
}
-int64_t load_timestamp_sys_clock(void)
-{
- static int s_fd = -1;
- int fd, result = 0;
- struct timespec ts;
-
- if (s_fd == -1) {
- fd = open("/dev/alarm", O_RDONLY);
- if (android_atomic_cmpxchg(-1, fd, &s_fd)) {
- close(fd);
- }
- }
-
- result = ioctl(s_fd,
- ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts);
- if (result != 0) {
- /** /dev/alarm doesn't exist, fallback to CLOCK_BOOTTIME */
- result = clock_gettime(CLOCK_BOOTTIME, &ts);
- }
+int64_t get_timestamp_boot (void)
+{
+ struct timespec ts = {0};
+ clock_gettime(CLOCK_BOOTTIME, &ts);
return 1000000000LL * ts.tv_sec + ts.tv_nsec;
}
-int64_t get_timestamp_monotonic(void)
+
+int64_t get_timestamp_monotonic (void)
{
struct timespec ts = {0};
+ clock_gettime(CLOCK_MONOTONIC, &ts);
- return load_timestamp_monotonic(&ts);
+ return 1000000000LL * ts.tv_sec + ts.tv_nsec;
}
-int64_t get_timestamp(void)
-{
- return (get_timestamp_monotonic() + ts_delta);
-}
-void set_timestamp(struct timespec *out, int64_t target_ns)
+void set_timestamp (struct timespec *out, int64_t target_ns)
{
out->tv_sec = target_ns / 1000000000LL;
out->tv_nsec = target_ns % 1000000000LL;