28 #ifndef FREERTOS_SEMAPHORE_HPP
29 #define FREERTOS_SEMAPHORE_HPP
57 static void*
operator new(size_t,
void* ptr) {
return ptr; }
58 static void*
operator new[](size_t,
void* ptr) {
return ptr; }
59 static void*
operator new(size_t) =
delete;
60 static void*
operator new[](size_t) =
delete;
115 inline bool take(
const TickType_t ticksToWait = portMAX_DELAY)
const {
116 return (xSemaphoreTake(
handle, ticksToWait) == pdTRUE);
149 BaseType_t taskWoken = pdFALSE;
150 bool result = (xSemaphoreTakeFromISR(
handle, &taskWoken) == pdTRUE);
151 if (taskWoken == pdTRUE) {
152 higherPriorityTaskWoken =
true;
168 return (xSemaphoreTakeFromISR(
handle, NULL) == pdTRUE);
192 inline bool give()
const {
return (xSemaphoreGive(
handle) == pdTRUE); }
218 BaseType_t taskWoken = pdFALSE;
219 bool result = (xSemaphoreGiveFromISR(
handle, &taskWoken) == pdTRUE);
220 if (taskWoken == pdTRUE) {
221 higherPriorityTaskWoken =
true;
237 return (xSemaphoreGiveFromISR(
handle, NULL) == pdTRUE);
266 #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
389 const UBaseType_t initialCount = 0) {
390 this->
handle = xSemaphoreCreateCounting(maxCount, initialCount);
403 #if (configSUPPORT_STATIC_ALLOCATION == 1)
465 this->
handle = xSemaphoreCreateBinaryStatic(&staticBinarySemaphore);
476 StaticSemaphore_t staticBinarySemaphore;
502 const UBaseType_t initialCount = 0) {
503 this->
handle = xSemaphoreCreateCountingStatic(maxCount, initialCount,
504 &staticCountingSemaphore);
516 StaticSemaphore_t staticCountingSemaphore;
Class that encapsulates the functionality of a FreeRTOS binary semaphore.
Definition: Semaphore.hpp:309
BinarySemaphore()
Construct a new BinarySemaphore object by calling SemaphoreHandle_t xSemaphoreCreateBinary( void )
Definition: Semaphore.hpp:326
Class that encapsulates the functionality of a FreeRTOS counting semaphore.
Definition: Semaphore.hpp:370
CountingSemaphore(const UBaseType_t maxCount, const UBaseType_t initialCount=0)
Construct a new CountingSemaphore by calling SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t ...
Definition: Semaphore.hpp:388
Base class that provides the standard semaphore interface to FreeRTOS::BinarySemaphore,...
Definition: Semaphore.hpp:47
bool takeFromISR() const
Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition: Semaphore.hpp:167
bool take(const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait )
Definition: Semaphore.hpp:115
bool give() const
Function that calls xSemaphoreGive( SemaphoreHandle_t xSemaphore )
Definition: Semaphore.hpp:192
SemaphoreHandle_t handle
Handle used to refer to the semaphore when using the FreeRTOS interface.
Definition: Semaphore.hpp:263
bool takeFromISR(bool &higherPriorityTaskWoken) const
Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition: Semaphore.hpp:148
UBaseType_t getCount() const
Function that calls UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore )
Definition: Semaphore.hpp:88
bool isValid() const
Function that checks if the underlying semaphore handle is not NULL. This should be used to ensure a ...
Definition: Semaphore.hpp:71
bool giveFromISR() const
Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition: Semaphore.hpp:236
~SemaphoreBase()
Destroy the SemaphoreBase object by calling void vSemaphoreDelete( SemaphoreHandle_t xSemaphore )
Definition: Semaphore.hpp:254
bool giveFromISR(bool &higherPriorityTaskWoken) const
Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition: Semaphore.hpp:217
Class that encapsulates the functionality of a FreeRTOS binary semaphore.
Definition: Semaphore.hpp:446
StaticBinarySemaphore()
Construct a new StaticBinarySemaphore object by calling SemaphoreHandle_t xSemaphoreCreateBinaryStati...
Definition: Semaphore.hpp:464
Definition: Semaphore.hpp:479
StaticCountingSemaphore(const UBaseType_t maxCount, const UBaseType_t initialCount=0)
Construct a new StaticCountingSemaphore object by calling SemaphoreHandle_t xSemaphoreCreateCountingS...
Definition: Semaphore.hpp:501