Fix detach pin interrupt in hwSleep (#599)

Fix issue #598
Pin interrupts used as wakeup source for hwSleep now get detached
correctly, also when the interrupts did not occur.
This commit is contained in:
Embedded Innovation
2016-10-03 20:44:04 +02:00
committed by Olivier
parent 6e414eeeeb
commit 32596676e5
+12
View File
@@ -30,11 +30,19 @@ volatile uint8_t _wakeUp2Interrupt = INVALID_INTERRUPT_NUM; // Interrupt num
void wakeUp1() //place to send the interrupts void wakeUp1() //place to send the interrupts
{ {
detachInterrupt(_wakeUp1Interrupt); detachInterrupt(_wakeUp1Interrupt);
if (_wakeUp2Interrupt != INVALID_INTERRUPT_NUM)
{
detachInterrupt(_wakeUp2Interrupt);
}
_wokeUpByInterrupt = _wakeUp1Interrupt; _wokeUpByInterrupt = _wakeUp1Interrupt;
} }
void wakeUp2() //place to send the second interrupts void wakeUp2() //place to send the second interrupts
{ {
detachInterrupt(_wakeUp2Interrupt); detachInterrupt(_wakeUp2Interrupt);
if (_wakeUp1Interrupt != INVALID_INTERRUPT_NUM)
{
detachInterrupt(_wakeUp1Interrupt);
}
_wokeUpByInterrupt = _wakeUp2Interrupt; _wokeUpByInterrupt = _wakeUp2Interrupt;
} }
@@ -130,6 +138,10 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
hwPowerDown(SLEEP_FOREVER); hwPowerDown(SLEEP_FOREVER);
} }
// Assure any interrupts attached, will get detached when they did not occur.
if (interrupt1 != INVALID_INTERRUPT_NUM) detachInterrupt(interrupt1);
if (interrupt2 != INVALID_INTERRUPT_NUM) detachInterrupt(interrupt2);
// Return what woke the mcu. // Return what woke the mcu.
int8_t ret = MY_WAKE_UP_BY_TIMER; // default: no interrupt triggered, timer wake up int8_t ret = MY_WAKE_UP_BY_TIMER; // default: no interrupt triggered, timer wake up
if (interruptWakeUp()) ret = static_cast<int8_t>(_wokeUpByInterrupt); if (interruptWakeUp()) ret = static_cast<int8_t>(_wokeUpByInterrupt);