Skip to content

Commit

Permalink
px4io mixer: fix atomic access to system_state.fmu_data_received_time
Browse files Browse the repository at this point in the history
system_state.fmu_data_received_time can be set from an IRQ handler, thus
we need to ensure every read access to it in mixer_tick is atomic.
So we read it once and copy it into a local variable.
  • Loading branch information
bkueng committed Jan 23, 2019
1 parent 2b9fc60 commit a17fc11
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/modules/px4iofirmware/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ mixer_tick(void)
mixer_handle_text_create_mixer();

/* check that we are receiving fresh data from the FMU */
if ((system_state.fmu_data_received_time == 0) ||
hrt_elapsed_time_atomic(&system_state.fmu_data_received_time) > FMU_INPUT_DROP_LIMIT_US) {
irqstate_t flags = enter_critical_section();
const hrt_abstime fmu_data_received_time = system_state.fmu_data_received_time;
leave_critical_section(flags);

if ((fmu_data_received_time == 0) ||
hrt_elapsed_time(&fmu_data_received_time) > FMU_INPUT_DROP_LIMIT_US) {

/* too long without FMU input, time to go to failsafe */
if (r_status_flags & PX4IO_P_STATUS_FLAGS_FMU_OK) {
Expand All @@ -135,9 +139,9 @@ mixer_tick(void)
/* this flag is never cleared once OK */
PX4_ATOMIC_MODIFY_OR(r_status_flags, PX4IO_P_STATUS_FLAGS_FMU_INITIALIZED);

if (system_state.fmu_data_received_time > last_fmu_update) {
if (fmu_data_received_time > last_fmu_update) {
new_fmu_data = true;
last_fmu_update = system_state.fmu_data_received_time;
last_fmu_update = fmu_data_received_time;
}
}

Expand Down

0 comments on commit a17fc11

Please sign in to comment.