Merge pull request #231 from cetic/fix-native-clock
Native monotonic timer
This commit is contained in:
commit
d1208f7c5b
@ -79,11 +79,11 @@ rtimer_arch_schedule(rtimer_clock_t t)
|
||||
|
||||
c = t - (unsigned short)clock_time();
|
||||
|
||||
val.it_value.tv_sec = c / 1000;
|
||||
val.it_value.tv_usec = (c % 1000) * 1000;
|
||||
val.it_value.tv_sec = c / CLOCK_SECOND;
|
||||
val.it_value.tv_usec = (c % CLOCK_SECOND) * CLOCK_SECOND;
|
||||
|
||||
PRINTF("rtimer_arch_schedule time %u %u in %d.%d seconds\n", t, c, c / 1000,
|
||||
(c % 1000) * 1000);
|
||||
PRINTF("rtimer_arch_schedule time %u %u in %d.%d seconds\n", t, c, val.it_value.tv_sec,
|
||||
val.it_value.tv_usec);
|
||||
|
||||
val.it_interval.tv_sec = val.it_interval.tv_usec = 0;
|
||||
setitimer(ITIMER_REAL, &val, NULL);
|
||||
|
@ -19,6 +19,10 @@ else
|
||||
CONTIKI_TARGET_SOURCEFILES += tun6-net.c
|
||||
endif
|
||||
|
||||
ifeq ($(HOST_OS),Linux)
|
||||
TARGET_LIBFILES += -lrt
|
||||
endif
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
.SUFFIXES:
|
||||
|
@ -42,24 +42,49 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
typedef struct clock_timespec_s {
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
} clock_timespec_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
get_time(clock_timespec_t *spec)
|
||||
{
|
||||
#if defined(__linux__) || (defined(__MACH__) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
spec->tv_sec = ts.tv_sec;
|
||||
spec->tv_nsec = ts.tv_nsec;
|
||||
#else
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
spec->tv_sec = tv.tv_sec;
|
||||
spec->tv_nsec = tv.tv_usec * 1000;
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
{
|
||||
clock_timespec_t ts;
|
||||
|
||||
get_time(&ts);
|
||||
|
||||
return ts.tv_sec * CLOCK_SECOND + ts.tv_nsec / (1000000000 / CLOCK_SECOND);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned long
|
||||
clock_seconds(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
clock_timespec_t ts;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
get_time(&ts);
|
||||
|
||||
return tv.tv_sec;
|
||||
return ts.tv_sec;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user