HAL_SITL: add methods to fetch native system clock info

This commit is contained in:
Siddharth Purohit 2020-05-31 18:03:00 +05:30 committed by Andrew Tridgell
parent c17aec07a2
commit f0e6a8c535

View File

@ -177,4 +177,45 @@ uint64_t millis64()
return ret;
}
uint32_t native_micros()
{
return native_micros64() & 0xFFFFFFFF;
}
uint32_t native_millis()
{
return native_millis64() & 0xFFFFFFFF;
}
/*
we define a millis16() here to avoid an issue with sitl builds in cygwin
*/
uint16_t native_millis16()
{
return native_millis64() & 0xFFFF;
}
uint64_t native_micros64()
{
struct timeval tp;
gettimeofday(&tp, nullptr);
uint64_t ret = 1.0e6 * ((tp.tv_sec + (tp.tv_usec * 1.0e-6)) -
(state.start_time.tv_sec +
(state.start_time.tv_usec * 1.0e-6)));
return ret;
}
uint64_t native_millis64()
{
struct timeval tp;
gettimeofday(&tp, nullptr);
uint64_t ret = 1.0e3*((tp.tv_sec + (tp.tv_usec*1.0e-6)) -
(state.start_time.tv_sec +
(state.start_time.tv_usec*1.0e-6)));
return ret;
}
} // namespace AP_HAL