HAL_Linux: use CLOCK_MONOTONIC_RAW to ensure clock never goes backwards
this avoids ntp mucking with APM timing
This commit is contained in:
parent
a4604ab317
commit
07b8f45770
@ -28,7 +28,7 @@ typedef void *(*pthread_startroutine_t)(void *);
|
||||
|
||||
void LinuxScheduler::init(void* machtnichts)
|
||||
{
|
||||
gettimeofday(&_sketch_start_time, NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC, &_sketch_start_time);
|
||||
|
||||
pthread_attr_t thread_attr;
|
||||
struct sched_param param;
|
||||
@ -79,20 +79,20 @@ void LinuxScheduler::delay(uint16_t ms)
|
||||
|
||||
uint32_t LinuxScheduler::millis()
|
||||
{
|
||||
struct timeval tp;
|
||||
gettimeofday(&tp,NULL);
|
||||
return 1.0e3*((tp.tv_sec + (tp.tv_usec*1.0e-6)) -
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return 1.0e3*((ts.tv_sec + (ts.tv_nsec*1.0e-9)) -
|
||||
(_sketch_start_time.tv_sec +
|
||||
(_sketch_start_time.tv_usec*1.0e-6)));
|
||||
(_sketch_start_time.tv_nsec*1.0e-9)));
|
||||
}
|
||||
|
||||
uint32_t LinuxScheduler::micros()
|
||||
{
|
||||
struct timeval tp;
|
||||
gettimeofday(&tp,NULL);
|
||||
return 1.0e6*((tp.tv_sec + (tp.tv_usec*1.0e-6)) -
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return 1.0e6*((ts.tv_sec + (ts.tv_nsec*1.0e-9)) -
|
||||
(_sketch_start_time.tv_sec +
|
||||
(_sketch_start_time.tv_usec*1.0e-6)));
|
||||
(_sketch_start_time.tv_nsec*1.0e-9)));
|
||||
}
|
||||
|
||||
void LinuxScheduler::delay_microseconds(uint16_t us)
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
void reboot(bool hold_in_bootloader);
|
||||
|
||||
private:
|
||||
struct timeval _sketch_start_time;
|
||||
struct timespec _sketch_start_time;
|
||||
void _timer_handler(int signum);
|
||||
|
||||
AP_HAL::Proc _delay_cb;
|
||||
|
Loading…
Reference in New Issue
Block a user