mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-06 11:31:35 +08:00
px4_qurt_tasks: fix hang because of absolute time
The timeout was triggered using absolute time instead of a delay in usec. This lead to the system hanging. With the fix it continues after the timeout, however, the rates still don't seem right.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include "px4_log.h"
|
#include "px4_log.h"
|
||||||
#include "px4_posix.h"
|
#include "px4_posix.h"
|
||||||
#include "px4_workqueue.h"
|
#include "px4_workqueue.h"
|
||||||
|
#include "px4_time.h"
|
||||||
#include "hrt_work.h"
|
#include "hrt_work.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -369,9 +370,14 @@ int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *ts)
|
|||||||
{
|
{
|
||||||
work_s _hpwork = {};
|
work_s _hpwork = {};
|
||||||
|
|
||||||
// Create a timer to unblock
|
// We get an absolute time but want to calculate a timeout in us.
|
||||||
uint32_t timeout = ts->tv_sec * 1000000 + (ts->tv_nsec / 1000);
|
struct timespec ts_now;
|
||||||
hrt_work_queue(&_hpwork, (worker_t)&timer_cb, (void *)sem, timeout);
|
px4_clock_gettime(CLOCK_REALTIME, &ts_now);
|
||||||
|
uint32_t timeout_us = ((ts->tv_sec - ts_now.tv_sec) * 1000000)
|
||||||
|
+ ((ts->tv_nsec - ts_now.tv_nsec) / 1000);
|
||||||
|
|
||||||
|
// Create a timer to unblock.
|
||||||
|
hrt_work_queue(&_hpwork, (worker_t)&timer_cb, (void *)sem, timeout_us);
|
||||||
sem_wait(sem);
|
sem_wait(sem);
|
||||||
hrt_work_cancel(&_hpwork);
|
hrt_work_cancel(&_hpwork);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user