|
|
|
@ -14,6 +14,7 @@
@@ -14,6 +14,7 @@
|
|
|
|
|
#include <drivers/drv_hrt.h> |
|
|
|
|
#include <nuttx/arch.h> |
|
|
|
|
#include <systemlib/systemlib.h> |
|
|
|
|
#include <pthread.h> |
|
|
|
|
#include <poll.h> |
|
|
|
|
|
|
|
|
|
#include "UARTDriver.h" |
|
|
|
@ -82,15 +83,26 @@ uint32_t PX4Scheduler::millis()
@@ -82,15 +83,26 @@ uint32_t PX4Scheduler::millis()
|
|
|
|
|
return hrt_absolute_time() / 1000; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
delay for a specified number of microseconds using a semaphore wait |
|
|
|
|
*/ |
|
|
|
|
void PX4Scheduler::delay_microseconds_semaphore(uint16_t usec)
|
|
|
|
|
{ |
|
|
|
|
sem_t wait_semaphore; |
|
|
|
|
struct hrt_call wait_call; |
|
|
|
|
sem_init(&wait_semaphore, 0, 0); |
|
|
|
|
hrt_call_after(&wait_call, usec, (hrt_callout)sem_post, &wait_semaphore); |
|
|
|
|
sem_wait(&wait_semaphore); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PX4Scheduler::delay_microseconds(uint16_t usec)
|
|
|
|
|
{ |
|
|
|
|
#if 0 |
|
|
|
|
if (_in_timer_proc) { |
|
|
|
|
::printf("ERROR: delay_microseconds() from timer process\n"); |
|
|
|
|
perf_begin(_perf_delay); |
|
|
|
|
if (usec >= 500) { |
|
|
|
|
delay_microseconds_semaphore(usec); |
|
|
|
|
perf_end(_perf_delay); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
perf_begin(_perf_delay); |
|
|
|
|
uint32_t start = micros(); |
|
|
|
|
uint32_t dt; |
|
|
|
|
while ((dt=(micros() - start)) < usec) { |
|
|
|
@ -112,8 +124,7 @@ void PX4Scheduler::delay(uint16_t ms)
@@ -112,8 +124,7 @@ void PX4Scheduler::delay(uint16_t ms)
|
|
|
|
|
|
|
|
|
|
while ((hrt_absolute_time() - start)/1000 < ms &&
|
|
|
|
|
!_px4_thread_should_exit) { |
|
|
|
|
// this yields the CPU to other apps
|
|
|
|
|
poll(NULL, 0, 1); |
|
|
|
|
delay_microseconds_semaphore(1000); |
|
|
|
|
if (_min_delay_cb_ms <= ms) { |
|
|
|
|
if (_delay_cb) { |
|
|
|
|
_delay_cb(); |
|
|
|
@ -221,7 +232,7 @@ void PX4Scheduler::_run_timers(bool called_from_timer_thread)
@@ -221,7 +232,7 @@ void PX4Scheduler::_run_timers(bool called_from_timer_thread)
|
|
|
|
|
void *PX4Scheduler::_timer_thread(void) |
|
|
|
|
{ |
|
|
|
|
while (!_px4_thread_should_exit) { |
|
|
|
|
poll(NULL, 0, 1); |
|
|
|
|
delay_microseconds_semaphore(1000); |
|
|
|
|
|
|
|
|
|
// run registered timers
|
|
|
|
|
perf_begin(_perf_timers); |
|
|
|
|