SITL: added in recursion check in timer_handler()

This commit is contained in:
Andrew Tridgell 2012-11-21 09:10:10 +11:00
parent 833d433caf
commit 07f5baea9e
1 changed files with 14 additions and 8 deletions

View File

@ -228,13 +228,16 @@ static void sitl_simulator_output(void)
static void timer_handler(int signum) static void timer_handler(int signum)
{ {
static uint32_t last_update_count; static uint32_t last_update_count;
static bool in_timer;
if (_interrupts_are_blocked()) { if (in_timer || _interrupts_are_blocked()) {
return; return;
} }
uint8_t oldSREG = SREG; uint8_t oldSREG = SREG;
cli(); cli();
in_timer = true;
#ifndef __CYGWIN__ #ifndef __CYGWIN__
/* make sure we die if our parent dies */ /* make sure we die if our parent dies */
if (kill(parent_pid, 0) != 0) { if (kill(parent_pid, 0) != 0) {
@ -242,15 +245,15 @@ static void timer_handler(int signum)
} }
#else #else
static uint16_t count = 0; static uint16_t count = 0;
static uint32_t last_report; static uint32_t last_report;
count++; count++;
if (millis() - last_report > 1000) { if (millis() - last_report > 1000) {
printf("TH %u cps\n", count); printf("TH %u cps\n", count);
count = 0; count = 0;
last_report = millis(); last_report = millis();
} }
#endif #endif
/* check for packet from flight sim */ /* check for packet from flight sim */
@ -267,11 +270,13 @@ static void timer_handler(int signum)
if (update_count == 0) { if (update_count == 0) {
sitl_update_gps(0, 0, 0, 0, 0, false); sitl_update_gps(0, 0, 0, 0, 0, false);
SREG = oldSREG; SREG = oldSREG;
in_timer = false;
return; return;
} }
if (update_count == last_update_count) { if (update_count == last_update_count) {
SREG = oldSREG; SREG = oldSREG;
in_timer = false;
return; return;
} }
last_update_count = update_count; last_update_count = update_count;
@ -295,6 +300,7 @@ static void timer_handler(int signum)
timer_scheduler.run(); timer_scheduler.run();
SREG = oldSREG; SREG = oldSREG;
in_timer = false;
} }