Files
firmware/src/concurrency/InterruptableDelay.cpp

43 lines
811 B
C++
Raw Normal View History

2020-10-10 09:57:57 +08:00
#include "concurrency/InterruptableDelay.h"
#include "configuration.h"
namespace concurrency
{
InterruptableDelay::InterruptableDelay()
{
}
InterruptableDelay::~InterruptableDelay()
{
}
/**
* Returns false if we were interrupted
*/
bool InterruptableDelay::delay(uint32_t msec)
{
if (msec) {
// DEBUG_MSG("delay %u ", msec);
2020-10-10 09:57:57 +08:00
// sem take will return false if we timed out (i.e. were not interrupted)
2020-10-11 09:18:47 +08:00
bool r = semaphore.take(msec);
2020-10-10 09:57:57 +08:00
// DEBUG_MSG("interrupt=%d\n", r);
2020-10-10 09:57:57 +08:00
return !r;
} else {
return true;
}
}
void InterruptableDelay::interrupt()
{
2020-10-11 09:18:47 +08:00
semaphore.give();
2020-10-10 09:57:57 +08:00
}
IRAM_ATTR void InterruptableDelay::interruptFromISR(BaseType_t *pxHigherPriorityTaskWoken)
{
2020-10-11 09:18:47 +08:00
semaphore.giveFromISR(pxHigherPriorityTaskWoken);
2020-10-10 09:57:57 +08:00
}
} // namespace concurrency