AP_HAL_AVR Scheduler: support nested atomic sections

This commit is contained in:
Pat Hickey 2012-12-03 11:03:53 -08:00 committed by Andrew Tridgell
parent f543cede01
commit d47f77f8dd
2 changed files with 10 additions and 2 deletions

View File

@ -27,7 +27,9 @@ bool AVRScheduler::_in_timer_proc = false;
AVRScheduler::AVRScheduler() :
_delay_cb(NULL)
_delay_cb(NULL),
_min_delay_cb_ms(65535),
_nested_atomic_ctr(0)
{}
void AVRScheduler::init(void* _isrregistry) {
@ -323,9 +325,13 @@ void AVRScheduler::_timer_event() {
}
void AVRScheduler::begin_atomic() {
_nested_atomic_ctr++;
cli();
}
void AVRScheduler::end_atomic() {
sei();
_nested_atomic_ctr--;
if (_nested_atomic_ctr == 0) {
sei();
}
}

View File

@ -49,6 +49,8 @@ private:
static uint8_t _num_timer_procs;
static bool _in_timer_proc;
uint8_t _nested_atomic_ctr;
};
#endif // __AP_HAL_AVR_SCHEDULER_H__