timer: enable interrupts during timer processing

this prevents us losing serial bytes when we call sensor drivers that
take more than 100usec to read.

We also prevent timer recursion by re-enabling the timer after all
callbacks are complete
This commit is contained in:
Andrew Tridgell 2011-12-16 19:48:31 +11:00
parent 09947dace1
commit c41e7c505b
1 changed files with 14 additions and 5 deletions

View File

@ -5,6 +5,7 @@ extern "C" {
#include <inttypes.h>
#include <stdint.h>
#include "WConstants.h"
#include <avr/interrupt.h>
}
int AP_TimerProcess::_period;
@ -40,9 +41,17 @@ void AP_TimerProcess::register_process(void (*proc)(void) )
void AP_TimerProcess::run(void)
{
TCNT2 = _period;
for (int i = 0; i < _pidx; i++) {
if (_proc[i] != NULL)
_proc[i]();
}
// we re-enable interrupts here as some of these functions
// take a long time, and we don't want to block other critical
// interrupts, especially the serial interrupt
sei();
for (int i = 0; i < _pidx; i++) {
if (_proc[i] != NULL)
_proc[i]();
}
// to prevent recursion, we don't enable the timer interrupt
// again until we've completed the tasks
TCNT2 = _period;
}