firmware/src/concurrency/BinarySemaphoreFreeRTOS.cpp

41 lines
782 B
C++
Raw Normal View History

#include "concurrency/BinarySemaphoreFreeRTOS.h"
2023-01-21 13:34:29 +00:00
#include "configuration.h"
2021-03-09 08:45:40 +00:00
#include <assert.h>
2020-10-11 01:18:47 +00:00
#ifdef HAS_FREE_RTOS
namespace concurrency
{
2022-01-24 18:39:17 +00:00
BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS() : semaphore(xSemaphoreCreateBinary())
2020-10-11 01:18:47 +00:00
{
2021-03-09 08:45:40 +00:00
assert(semaphore);
2020-10-11 01:18:47 +00:00
}
BinarySemaphoreFreeRTOS::~BinarySemaphoreFreeRTOS()
{
vSemaphoreDelete(semaphore);
}
/**
* Returns false if we were interrupted
*/
bool BinarySemaphoreFreeRTOS::take(uint32_t msec)
{
return xSemaphoreTake(semaphore, pdMS_TO_TICKS(msec));
}
void BinarySemaphoreFreeRTOS::give()
{
xSemaphoreGive(semaphore);
}
IRAM_ATTR void BinarySemaphoreFreeRTOS::giveFromISR(BaseType_t *pxHigherPriorityTaskWoken)
{
xSemaphoreGiveFromISR(semaphore, pxHigherPriorityTaskWoken);
}
} // namespace concurrency
2022-01-24 18:39:17 +00:00
#endif