2020-10-11 01:18:47 +00:00
|
|
|
#include "configuration.h"
|
2021-06-27 17:56:28 +00:00
|
|
|
#include "concurrency/BinarySemaphoreFreeRTOS.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
|