2013-12-31 09:45:38 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <drivers/drv_hrt.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
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;
|
2014-01-01 20:18:12 -04:00
|
|
|
}
|
|
|
|
|
2015-03-02 15:32:39 -04:00
|
|
|
hrt_abstime hrt_elapsed_time(const volatile hrt_abstime *then)
|
|
|
|
{
|
2014-01-01 20:18:12 -04:00
|
|
|
// not thread safe
|
2015-03-02 15:32:39 -04:00
|
|
|
return hrt_absolute_time() - *then;
|
2014-01-02 04:49:43 -04:00
|
|
|
}
|