From 00f5ed6b4516f5f39576089b5367f31e15fa6998 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 18 Nov 2014 20:02:27 +0100 Subject: [avr] Made SPI.usingInterrupt() synchronized (Andrew Kroll) --- libraries/SPI/SPI.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index 40d4278..077b6a3 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -111,11 +111,9 @@ void SPIClass::end() { void SPIClass::usingInterrupt(uint8_t interruptNumber) { - uint8_t mask; - - if (interruptMode > 1) return; - - noInterrupts(); + uint8_t mask = 0; + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin switch (interruptNumber) { #ifdef SPI_INT0_MASK case 0: mask = SPI_INT0_MASK; break; @@ -143,12 +141,12 @@ void SPIClass::usingInterrupt(uint8_t interruptNumber) #endif default: interruptMode = 2; - interrupts(); - return; + break; } - interruptMode = 1; interruptMask |= mask; - interrupts(); + if (!interruptMode) + interruptMode = 1; + SREG = sreg; } void SPIClass::notUsingInterrupt(uint8_t interruptNumber) -- cgit v1.2.3-18-g5258