aboutsummaryrefslogblamecommitdiff
path: root/unittests/hrt.cpp
blob: d7b4670db12bcc3aa5114b99e1d17519e7c68177 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11




                            





                                                                                            

 

                                                              
                          
                                           
 
#include <sys/time.h>
#include <inttypes.h>
#include <drivers/drv_hrt.h>
#include <stdio.h>

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;
}

hrt_abstime hrt_elapsed_time(const volatile hrt_abstime *then)
{
	// not thread safe
	return hrt_absolute_time() - *then;
}