Files
firmware/src/concurrency/InterruptableDelay.cpp

35 lines
733 B
C++
Raw Normal View History

2020-10-10 09:57:57 +08:00
#include "configuration.h"
#include "concurrency/InterruptableDelay.h"
2020-10-10 09:57:57 +08:00
namespace concurrency
{
InterruptableDelay::InterruptableDelay() {}
2020-10-10 09:57:57 +08:00
InterruptableDelay::~InterruptableDelay() {}
2020-10-10 09:57:57 +08:00
/**
* Returns false if we were interrupted
*/
bool InterruptableDelay::delay(uint32_t msec)
{
2022-12-29 20:41:37 -06:00
// LOG_DEBUG("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)
bool r = semaphore.take(msec);
2020-10-10 09:57:57 +08:00
2022-12-29 20:41:37 -06:00
// LOG_DEBUG("interrupt=%d\n", r);
return !r;
2020-10-10 09:57:57 +08:00
}
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