Base class that provides the standard semaphore interface to FreeRTOS::BinarySemaphore, FreeRTOS::StaticBinarySemaphore, FreeRTOS::CountingSemaphore, and FreeRTOS::StaticCountingSemaphore.
More...
#include <FreeRTOS/Semaphore.hpp>
|
| SemaphoreBase (const SemaphoreBase &)=delete |
|
SemaphoreBase & | operator= (const SemaphoreBase &)=delete |
|
bool | isValid () const |
| Function that checks if the underlying semaphore handle is not NULL. This should be used to ensure a semaphore has been created correctly. More...
|
|
UBaseType_t | getCount () const |
| Function that calls UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore ) More...
|
|
bool | take (const TickType_t ticksToWait=portMAX_DELAY) const |
| Function that calls xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait ) More...
|
|
bool | takeFromISR (bool &higherPriorityTaskWoken) const |
| Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken) More...
|
|
bool | takeFromISR () const |
| Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken) More...
|
|
bool | give () const |
| Function that calls xSemaphoreGive( SemaphoreHandle_t xSemaphore ) More...
|
|
bool | giveFromISR (bool &higherPriorityTaskWoken) const |
| Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken ) More...
|
|
bool | giveFromISR () const |
| Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken ) More...
|
|
|
static void * | operator new (size_t, void *ptr) |
|
static void * | operator new[] (size_t, void *ptr) |
|
static void * | operator new (size_t)=delete |
|
static void * | operator new[] (size_t)=delete |
|
|
SemaphoreHandle_t | handle = NULL |
| Handle used to refer to the semaphore when using the FreeRTOS interface.
|
|
|
class | BinarySemaphore |
|
class | StaticBinarySemaphore |
|
class | CountingSemaphore |
|
class | StaticCountingSemaphore |
|
◆ ~SemaphoreBase()
FreeRTOS::SemaphoreBase::~SemaphoreBase |
( |
| ) |
|
|
inlineprivate |
◆ getCount()
UBaseType_t FreeRTOS::SemaphoreBase::getCount |
( |
| ) |
const |
|
inline |
Function that calls UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore )
Semaphore.hpp
- See also
- https://www.freertos.org/uxSemaphoreGetCount.html
Returns the count of a semaphore.
- Returns
- UBaseType_t If the semaphore is a counting semaphore then the semaphores current count value is returned. If the semaphore is a binary semaphore then 1 is returned if the semaphore is available, and 0 is returned if the semaphore is not available.
◆ give()
bool FreeRTOS::SemaphoreBase::give |
( |
| ) |
const |
|
inline |
Function that calls xSemaphoreGive( SemaphoreHandle_t xSemaphore )
Semaphore.hpp
- See also
- https://www.freertos.org/a00123.html
Function to release a semaphore.
This must not be used from an ISR. See giveFromISR() for an alternative which can be used from an ISR.
- Return values
-
true | If the semaphore was released. |
false | If an error occurred. Semaphores are implemented using queues. An error can occur if there is no space on the queue to post a message indicating that the semaphore was not first obtained correctly. |
Example Usage
#include <FreeRTOS/Semaphore.hpp>
#include <FreeRTOS/Task.hpp>
public:
void taskFunction() final;
};
void MyTask::taskFunction() {
if (binarySemaphore.
give()) {
}
if (binarySemaphore.
take(0)) {
if (!binarySemaphore.
give()) {
}
}
}
}
Class that encapsulates the functionality of a FreeRTOS binary semaphore.
Definition: Semaphore.hpp:309
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
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
Class that encapsulates the functionality of a FreeRTOS task.
Definition: Task.hpp:1323
◆ giveFromISR() [1/2]
bool FreeRTOS::SemaphoreBase::giveFromISR |
( |
| ) |
const |
|
inline |
Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken )
Semaphore.hpp
- See also
- https://www.freertos.org/a00124.html
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ giveFromISR() [2/2]
bool FreeRTOS::SemaphoreBase::giveFromISR |
( |
bool & |
higherPriorityTaskWoken | ) |
const |
|
inline |
Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken )
Semaphore.hpp
- See also
- https://www.freertos.org/a00124.html
Function to release a semaphore.
This macro can be used from an ISR.
- Parameters
-
higherPriorityTaskWoken | giveFromISR() will set higherPriorityTaskWoken to true if giving the semaphore caused a task to unblock, and the unblocked task has a priority higher than the currently running task. If giveFromISR() sets this value to true then a context switch should be requested before the interrupt is exited. |
- Return values
-
true | If the semaphore was successfully given. |
false | Otherwise. |
Example Usage
#include <FreeRTOS/Semaphore.hpp>
#include <FreeRTOS/Task.hpp>
#define LONG_TIME 0xffff
#define TICKS_TO_WAIT 10
public:
void taskFunction() final;
};
static FreeRTOS::StaticBinarySemaphore binarySemaphore;
void MyTask::taskFunction() {
for (;;) {
if (binarySemaphore.take()) {
}
}
}
void vTimerISR(void* pvParameters) {
static TickType_t ucLocalTickCount = 0;
bool higherPriorityTaskWoken = false;
ucLocalTickCount++;
if (ucLocalTickCount >= TICKS_TO_WAIT) {
binarySemaphore.giveFromISR(higherPriorityTaskWoken);
ucLocalTickCount = 0;
}
}
void yield()
Function that calls taskYIELD()
Definition: Kernel.hpp:153
◆ isValid()
bool FreeRTOS::SemaphoreBase::isValid |
( |
| ) |
const |
|
inline |
Function that checks if the underlying semaphore handle is not NULL. This should be used to ensure a semaphore has been created correctly.
Semaphore.hpp
- Return values
-
true | the handle is not NULL. |
false | the handle is NULL. |
◆ take()
bool FreeRTOS::SemaphoreBase::take |
( |
const TickType_t |
ticksToWait = portMAX_DELAY | ) |
const |
|
inline |
Function that calls xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait )
Semaphore.hpp
- See also
- https://www.freertos.org/a00122.html
Function to obtain a semaphore.
This macro must not be called from an ISR. takeFromISR() can be used to take a semaphore from within an interrupt if required, although this would not be a normal operation. Semaphores use queues as their underlying mechanism, so functions are to some extent interoperable.
- Parameters
-
ticksToWait | The time in ticks to wait for the semaphore to become available. The macro portTICK_PERIOD_MS can be used to convert this to a real time. A block time of zero can be used to poll the semaphore. |
- Return values
-
true | If the semaphore was obtained. |
false | If xTicksToWait expired without the semaphore becoming available. |
Example Usage
#include <FreeRTOS/Semaphore.hpp>
#include <FreeRTOS/Task.hpp>
public:
void taskFunction() final;
};
class MyOtherTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
FreeRTOS::StaticBinarySemaphore binarySemaphore;
void MyTask::taskFunction() {
}
void MyOtherTask::taskFunction() {
if (binarySemaphore.isValid()) {
if (binarySemaphore.take()) {
binarySemaphore.give();
} else {
}
}
}
◆ takeFromISR() [1/2]
bool FreeRTOS::SemaphoreBase::takeFromISR |
( |
| ) |
const |
|
inline |
Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken)
Semaphore.hpp
- See also
- https://www.freertos.org/xSemaphoreTakeFromISR.html
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ takeFromISR() [2/2]
bool FreeRTOS::SemaphoreBase::takeFromISR |
( |
bool & |
higherPriorityTaskWoken | ) |
const |
|
inline |
Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken)
Semaphore.hpp
- See also
- https://www.freertos.org/xSemaphoreTakeFromISR.html
A version of take() that can be called from an ISR. Unlike take(), takeFromISR() does not permit a block time to be specified.
- Parameters
-
higherPriorityTaskWoken | It is possible (although unlikely, and dependent on the semaphore type) that a semaphore will have one or more tasks blocked on it waiting to give the semaphore. Calling takeFromISR() will make a task that was blocked waiting to give the semaphore leave the Blocked state. If calling the API function causes a task to leave the Blocked state, and the unblocked task has a priority equal to or higher than the currently executing task (the task that was interrupted), then, internally, the API function will set higherPriorityTaskWoken to true. If takeFromISR() sets higherPriorityTaskWoken to true, then a context switch should be performed before the interrupt is exited. This will ensure that the interrupt returns directly to the highest priority Ready state task. The mechanism is identical to that used in the FreeRTOS::receiveFromISR() function, and readers are referred to the FreeRTOS::receiveFromISR() documentation for further explanation. |
- Return values
-
true | If the semaphore was successfully taken. |
false | If the semaphore was not successfully taken because it was not available. |
The documentation for this class was generated from the following file:
- /home/runner/work/FreeRTOS-Cpp/FreeRTOS-Cpp/FreeRTOS-Cpp/include/FreeRTOS/Semaphore.hpp