driver/abstime.c: add time_monotonic_us

This commit is contained in:
[CST] Focus
2012-03-05 19:59:39 +04:00
parent 289bf2c4b2
commit e7c5d8925f
2 changed files with 15 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
#include <stdint.h>
#include <stdio.h> /* for perror */
#include <time.h>
@@ -27,3 +28,14 @@ time_t time_monotonic(void)
time comparisons if the uptime is low, so add 7 days */
return t.tv_sec + 604800;
}
uint64_t time_monotonic_us(void)
{
struct timespec t;
if (clock_gettime(CLOCK_MONOTONIC, &t))
{
perror("time_monotonic_us clock_gettime");
return -1;
}
return ((int64_t)t.tv_sec + (uint64_t)604800) * (uint64_t) 1000000 + (uint64_t) t.tv_nsec / (uint64_t)1000;
}

View File

@@ -1,3 +1,5 @@
#include <stdint.h>
#ifndef _ABS_TIME_H_
#define _ABS_TIME_H_
#ifdef __cplusplus
@@ -6,6 +8,7 @@ extern "C"
#endif
extern time_t time_monotonic_ms(void);
extern time_t time_monotonic(void);
uint64_t time_monotonic_us(void);
#ifdef __cplusplus
}
#endif