Use hrt_elapsed_time() in cases where we can't be sure the timestamp won't change under us.

This commit is contained in:
px4dev 2013-02-24 11:42:34 -08:00
parent 923a7cc505
commit f245d6b1a7
4 changed files with 6 additions and 6 deletions

View File

@ -154,7 +154,7 @@ adc_measure(unsigned channel)
while (!(rSR & ADC_SR_EOC)) { while (!(rSR & ADC_SR_EOC)) {
/* never spin forever - this will give a bogus result though */ /* never spin forever - this will give a bogus result though */
if ((hrt_absolute_time() - now) > 1000) { if (hrt_elapsed_time(&now) > 1000) {
debug("adc timeout"); debug("adc timeout");
break; break;
} }

View File

@ -218,7 +218,7 @@ controls_tick() {
* If we haven't seen any new control data in 200ms, assume we * If we haven't seen any new control data in 200ms, assume we
* have lost input. * have lost input.
*/ */
if ((hrt_absolute_time() - system_state.rc_channels_timestamp) > 200000) { if (hrt_elapsed_time(&system_state.rc_channels_timestamp) > 200000) {
rc_input_lost = true; rc_input_lost = true;
/* clear the input-kind flags here */ /* clear the input-kind flags here */
@ -294,7 +294,7 @@ ppm_input(uint16_t *values, uint16_t *num_values)
* If we have received a new PPM frame within the last 200ms, accept it * If we have received a new PPM frame within the last 200ms, accept it
* and then invalidate it. * and then invalidate it.
*/ */
if ((hrt_absolute_time() - ppm_last_valid_decode) < 200000) { if (hrt_elapsed_time(&ppm_last_valid_decode) < 200000) {
/* PPM data exists, copy it */ /* PPM data exists, copy it */
*num_values = ppm_decoded_channels; *num_values = ppm_decoded_channels;

View File

@ -88,7 +88,7 @@ void
mixer_tick(void) mixer_tick(void)
{ {
/* check that we are receiving fresh data from the FMU */ /* check that we are receiving fresh data from the FMU */
if ((hrt_absolute_time() - system_state.fmu_data_received_time) > FMU_INPUT_DROP_LIMIT_US) { if (hrt_elapsed_time(&system_state.fmu_data_received_time) > FMU_INPUT_DROP_LIMIT_US) {
/* too long without FMU input, time to go to failsafe */ /* too long without FMU input, time to go to failsafe */
if (r_status_flags & PX4IO_P_STATUS_FLAGS_FMU_OK) { if (r_status_flags & PX4IO_P_STATUS_FLAGS_FMU_OK) {

View File

@ -105,12 +105,12 @@ extern uint16_t r_page_servo_failsafe[]; /* PX4IO_PAGE_FAILSAFE_PWM */
*/ */
struct sys_state_s { struct sys_state_s {
uint64_t rc_channels_timestamp; volatile uint64_t rc_channels_timestamp;
/** /**
* Last FMU receive time, in microseconds since system boot * Last FMU receive time, in microseconds since system boot
*/ */
uint64_t fmu_data_received_time; volatile uint64_t fmu_data_received_time;
}; };