aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2014-11-18 20:02:27 +0100
committerCristian Maglie <c.maglie@bug.st>2014-11-25 15:56:11 +0100
commit00f5ed6b4516f5f39576089b5367f31e15fa6998 (patch)
tree1071088304a0ea8dac78f2f51e9cbd1a09d902ae
parent4948bf5650ec9a5a3638c57167ba8212e8c46242 (diff)
[avr] Made SPI.usingInterrupt() synchronized (Andrew Kroll)
-rw-r--r--libraries/SPI/SPI.cpp16
1 files 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)