Skip to content
Snippets Groups Projects
Commit 27e3f0c0 authored by Andrew Tridgell's avatar Andrew Tridgell
Browse files

SITL: fixed a interrupt recursion bug

this can be triggered by the timer scheduler re-enabling interrupts
parent 5002be9a
No related branches found
No related tags found
No related merge requests found
...@@ -232,6 +232,7 @@ static void timer_handler(int signum) ...@@ -232,6 +232,7 @@ static void timer_handler(int signum)
if (_interrupts_are_blocked()) { if (_interrupts_are_blocked()) {
return; return;
} }
uint8_t oldSREG = SREG;
cli(); cli();
#ifndef __CYGWIN__ #ifndef __CYGWIN__
...@@ -255,9 +256,6 @@ static void timer_handler(int signum) ...@@ -255,9 +256,6 @@ static void timer_handler(int signum)
/* check for packet from flight sim */ /* check for packet from flight sim */
sitl_fdm_input(); sitl_fdm_input();
// trigger all timers
timer_scheduler.run();
// trigger RC input // trigger RC input
if (isr_registry._registry[ISR_REGISTRY_TIMER4_CAPT]) { if (isr_registry._registry[ISR_REGISTRY_TIMER4_CAPT]) {
isr_registry._registry[ISR_REGISTRY_TIMER4_CAPT](); isr_registry._registry[ISR_REGISTRY_TIMER4_CAPT]();
...@@ -268,12 +266,12 @@ static void timer_handler(int signum) ...@@ -268,12 +266,12 @@ 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);
sei(); SREG = oldSREG;
return; return;
} }
if (update_count == last_update_count) { if (update_count == last_update_count) {
sei(); SREG = oldSREG;
return; return;
} }
last_update_count = update_count; last_update_count = update_count;
...@@ -292,7 +290,11 @@ static void timer_handler(int signum) ...@@ -292,7 +290,11 @@ static void timer_handler(int signum)
// so the ADC code doesn't get stuck // so the ADC code doesn't get stuck
ADCSRA &= ~_BV(ADSC); ADCSRA &= ~_BV(ADSC);
sei(); // trigger all APM timers. We do this last as it can re-enable
// interrupts, which can lead to recursion
timer_scheduler.run();
SREG = oldSREG;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment