From 47358929e29790bbedcb4dd4dec18f1e166b896f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Dec 2012 09:09:15 +1100 Subject: [PATCH] HAL_AVR: fixed attach_interrupt race condition --- libraries/AP_HAL_AVR/GPIO.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/AP_HAL_AVR/GPIO.cpp b/libraries/AP_HAL_AVR/GPIO.cpp index e40e1fdd62..ca4acc00f7 100644 --- a/libraries/AP_HAL_AVR/GPIO.cpp +++ b/libraries/AP_HAL_AVR/GPIO.cpp @@ -97,9 +97,12 @@ bool AVRGPIO::attach_interrupt( uint8_t interrupt_num, AP_HAL::Proc proc, uint8_t mode) { if (!((mode == 0)||(mode == 1)||(mode==3))) return false; if (interrupt_num == 6) { + uint8_t oldSREG = SREG; + cli(); _interrupt_6 = proc; EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); EIMSK |= (1 << INT6); + SREG = oldSREG; return true; } else { return false;