FreeRTOS-Cpp
|
Base class that provides the standard task interface to FreeRTOS::Task and FreeRTOS::StaticTask. More...
#include <FreeRTOS/Task.hpp>
Public Member Functions | |
TaskBase (const TaskBase &)=delete | |
TaskBase & | operator= (const TaskBase &)=delete |
virtual void | taskEntry () final |
Function that acts as the entry point of the task instance. This function initializes the previous wake time of the task and calls the user implemented taskFunction(). More... | |
UBaseType_t | getPriority () const |
Function that calls UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) More... | |
void | setPriority (const UBaseType_t newPriority) const |
Function that calls void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) More... | |
void | suspend () const |
Function that calls void vTaskSuspend( TaskHandle_t xTaskToSuspend ) More... | |
void | resume () const |
Function that calls void vTaskResume( TaskHandle_t xTaskToResume ) More... | |
bool | resumeFromISR () const |
Function that calls BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) More... | |
bool | abortDelay () const |
Function that calls BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) More... | |
UBaseType_t | getStackHighWaterMark () const |
Function that calls UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) More... | |
configSTACK_DEPTH_TYPE | getStackHighWaterMark2 () const |
Function that calls UBaseType_t uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) More... | |
State | getState () const |
Function that calls UBaseType_t uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) More... | |
const char * | getName () const |
Function that calls char *pcTaskGetName( TaskHandle_t xTaskToQuery ) More... | |
void | notifyGive (const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify ) More... | |
void | notifyGiveFromISR (bool &higherPriorityTaskWoken, const UBaseType_t index=0) const |
Function that calls void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken ) More... | |
void | notifyGiveFromISR (const UBaseType_t index=0) const |
Function that calls void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken ) More... | |
bool | notify (const NotifyAction action, const NotificationBits value=0, const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction ) More... | |
std::pair< bool, NotificationBits > | notifyAndQuery (const NotifyAction action, const NotificationBits value=0, const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue ) More... | |
std::pair< bool, NotificationBits > | notifyAndQueryFromISR (bool &higherPriorityTaskWoken, const NotifyAction action, const NotificationBits value=0, const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken ) More... | |
std::pair< bool, NotificationBits > | notifyAndQueryFromISR (const NotifyAction action, const NotificationBits value=0, const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken ) More... | |
bool | notifyFromISR (bool &higherPriorityTaskWoken, const NotifyAction action, const NotificationBits value=0, const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken ) More... | |
bool | notifyFromISR (const NotifyAction action, const NotificationBits value=0, const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken ) More... | |
bool | notifyStateClear (const UBaseType_t index=0) const |
Function that calls BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear ) More... | |
NotificationBits | notifyValueClear (const NotificationBits bitsToClear=0, const UBaseType_t index=0) const |
Function that calls uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear ) More... | |
Static Public Member Functions | |
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 |
static TaskHandle_t | getIdleHandle () |
Function that calls TaskHandle_t xTaskGetIdleTaskHandle( void ) More... | |
static TaskHandle_t | getHandle (const char *name) |
Function that calls TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) More... | |
static std::pair< bool, NotificationBits > | notifyWait (const TickType_t ticksToWait=portMAX_DELAY, const NotificationBits bitsToClearOnEntry=0, const NotificationBits bitsToClearOnExit=0, const UBaseType_t index=0) |
Function that calls BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) More... | |
Protected Member Functions | |
virtual void | taskFunction ()=0 |
Abstraction function that acts as the entry point of the task for the user. More... | |
bool | delayUntil (const TickType_t timeIncrement=0) |
Function that calls BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement ) More... | |
Static Protected Member Functions | |
static void | delay (const TickType_t ticksToDelay=0) |
Function that calls void vTaskDelay( const TickType_t xTicksToDelay ) More... | |
static NotificationBits | notifyTake (const TickType_t ticksToWait=portMAX_DELAY, const bool clearCountOnExit=true, const UBaseType_t index=0) |
Function that calls uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) More... | |
Private Member Functions | |
TaskBase ()=default | |
Construct a new TaskBase object. This default constructor is deliberately private as this class is not intended to be instantiated or derived from by the user. Use FreeRTOS::Task or FreeRTOS::StaticTask as a base class for creating a task. | |
TaskBase (TaskBase &&) noexcept=default | |
TaskBase & | operator= (TaskBase &&) noexcept=default |
~TaskBase () | |
Destroy the Task object. More... | |
Private Attributes | |
TaskHandle_t | handle = NULL |
Handle used to refer to the task when using the FreeRTOS interface. | |
TickType_t | previousWakeTime = 0 |
Variable that holds the time at which the task was last unblocked. | |
Friends | |
class | Task |
template<UBaseType_t > | |
class | StaticTask |
Base class that provides the standard task interface to FreeRTOS::Task and FreeRTOS::StaticTask.
|
inlineprivate |
Destroy the Task object.
If INCLUDE_vTaskDelete is defined as 1 and the task handle is not NULL, then the destructor will call void vTaskDelete( TaskHandle_t xTask )
See the RTOS Configuration documentation for more information.
Calling void vTaskDelete( TaskHandle_t xTask )
will remove a task from the RTOS kernels management. The task being deleted will be removed from all ready, blocked, suspended and event lists.
void vTaskDelete( TaskHandle_t xTask )
Memory allocated by the task code is not automatically freed, and should be freed before the task is deleted.Example Usage
|
inline |
Function that calls BaseType_t xTaskAbortDelay( TaskHandle_t xTask )
INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this function to be available.
A task will enter the Blocked state when it is waiting for an event. The event it is waiting for can be a temporal event (waiting for a time), such as when delay() is called, or an event on an object, such as when FreeRTOS::Queue::receive() or notifyTake() is called. If the handle of a task that is in the Blocked state is used in a call to abortDelay() then the task will leave the Blocked state, and return from whichever function call placed the task into the Blocked state.
There is no 'FromISR' version of this function as an interrupt would need to know which object a task was blocked on in order to know which actions to take. For example, if the task was blocked on a queue the interrupt handler would then need to know if the queue was locked.
true | Otherwise. |
false | If the task was not in the Blocked state. |
|
inlinestaticprotected |
Function that calls void vTaskDelay( const TickType_t xTicksToDelay )
INCLUDE_vTaskDelay must be defined as 1 for this function to be available. See the configuration section for more information.
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate. The constant portTICK_PERIOD_MS can be used to calculate real time from the tick rate - with the resolution of one tick period.
delay() specifies a time at which the task wishes to unblock relative to the time at which delay() is called. For example, specifying a block period of 100 ticks will cause the task to unblock 100 ticks after delay() is called. delay() does not therefore provide a good method of controlling the frequency of a periodic task as the path taken through the code, as well as other task and interrupt activity, will affect the frequency at which delay() gets called and therefore the time at which the task next executes. See delayUntil() for an alternative API function designed to facilitate fixed frequency execution. It does this by specifying an absolute time (rather than a relative time) at which the calling task should unblock.
ticksToDelay | The amount of time, in tick periods, that the task should block. |
Example Usage
|
inlineprotected |
Function that calls BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement )
INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available. See the configuration section for more information.
Delay a task until a specified time. This function can be used by periodic tasks to ensure a constant execution frequency.
This function differs from delay() in one important aspect: delay() will cause a task to block for the specified number of ticks from the time delay () is called. It is therefore difficult to use delay() by itself to generate a fixed execution frequency as the time between a task starting to execute and that task calling delay() may not be fixed [the task may take a different path though the code between calls, or may get interrupted or preempted a different number of times each time it executes].
Whereas delay() specifies a wake time relative to the time at which the function is called, delayUntil() specifies the absolute (exact) time at which it wishes to unblock.
The function pdMS_TO_TICKS() can be used to calculate the number of ticks from a time specified in milliseconds with a resolution of one tick period.
timeIncrement | The cycle time period. The task will be unblocked at time (previousWakeTime + timeIncrement). Calling delayUntil() with the same timeIncrement parameter value will cause the task to execute with a fixed interval period. |
Example Usage
|
inlinestatic |
Function that calls TaskHandle_t xTaskGetHandle( const char *pcNameToQuery )
name | The text name (as a standard C NULL terminated string) of the task for which the handle will be returned. |
|
inlinestatic |
Function that calls TaskHandle_t xTaskGetIdleTaskHandle( void )
getIdleTaskHandle() is only available if INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
Simply returns the handle of the idle task. It is not valid to call getIdleTaskHandle() before the scheduler has been started.
|
inline |
Function that calls char *pcTaskGetName( TaskHandle_t xTaskToQuery )
Looks up the name of a task.
|
inline |
Function that calls UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask )
INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available. See the RTOS Configuration documentation for more information.
Obtain the priority of any task.
Example Usage
|
inline |
Function that calls UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for this function to be available.
Returns the high water mark of the stack. That is, the minimum free stack space there has been (in words, so on a 32 bit machine a value of 1 means 4 bytes) since the task started. The smaller the returned number the closer the task has come to overflowing its stack.
getStackHighWaterMark() and getStackHighWaterMark2() are the same except for their return type. Using configSTACK_DEPTH_TYPE allows the user to determine the return type. It gets around the problem of the value overflowing on 8-bit types without breaking backward compatibility for applications that expect an 8-bit return type.
|
inline |
Function that calls UBaseType_t uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )
Returns the high water mark of the stack. That is, the minimum free stack space there has been (in words, so on a 32 bit machine a value of 1 means 4 bytes) since the task started. The smaller the returned number the closer the task has come to overflowing its stack.
getStackHighWaterMark() and getStackHighWaterMark2() are the same except for their return type. Using configSTACK_DEPTH_TYPE allows the user to determine the return type. It gets around the problem of the value overflowing on 8-bit types without breaking backward compatibility for applications that expect an 8-bit return type.
|
inline |
Function that calls UBaseType_t uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )
INCLUDE_eTaskGetState must be defined as 1 for this function to be available. See the configuration section for more information.
Obtain the state of any task. States are encoded by the FreeRTOS::Task::State enumerated class type.
|
inline |
Function that calls BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction )
configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these functions to be available.
Each task has a private array of "notification values" (or 'notifications'), each of which is a 32-bit unsigned integer (uint32_t). The constant configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the array, and (for backward compatibility) defaults to 1 if left undefined. Prior to FreeRTOS V10.4.0 there was only one notification value per task.
Events can be sent to a task using an intermediary object. Examples of such objects are queues, semaphores, mutexes and event groups. Task notifications are a method of sending an event directly to a task without the need for such an intermediary object.
A notification sent to a task can optionally perform an action, such as update, overwrite or increment one of the task's notification values. In that way task notifications can be used to send data to a task, or be used as light weight and fast binary or counting semaphores.
A task can use notifyWait() or notifyTake() to [optionally] block to wait for a notification to be pending. The task does not consume any CPU time while it is in the Blocked state.
A notification sent to a task will remain pending until it is cleared by the task calling notifyWait() or notifyTake(). If the task was already in the Blocked state to wait for a notification when the notification arrives then the task will automatically be removed from the Blocked state (unblocked) and the notification cleared.
action | Specifies how the notification updates the task's notification value, if at all. Valid values for action are as follows:
| ||||||||||||
value | Data that can be sent with the notification. How the data is used depends on the value of the action parameter. | ||||||||||||
index | The index within the target task's array of notification values to which the notification is to be sent. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
Example Usage
|
inline |
Function that calls BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue )
notifyAndQuery() performs the same operation as notify() with the addition that it also returns the target task's prior notification value (the notification value at the time the function is called rather than when the function returns).
action | An enumerated type that can take one of the values documented in the table below in order to perform the associated action.
| ||||||||||||
value | Used to update the notification value of the task. See the description of the action parameter below. | ||||||||||||
index | The index within the target task's array of notification values to which the notification is to be sent. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
Example Usage
|
inline |
Function that calls BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken )
notifyAndQueryFromISR() performs the same operation as notifyFromISR() with the addition that it also returns the target task's prior notification value (the notification value at the time the function is called rather than at the time the function returns).
higherPriorityTaskWoken | A reference that will be set to true if sending the notification caused a task to unblock, and the unblocked task has a priority higher than the currently running task. If higherPriorityTaskWoken is set to true, then a context switch should be requested before the interrupt is exited. | ||||||||||||
action | An enumerated type that can take one of the values documented in the table below in order to perform the associated action.
| ||||||||||||
value | Used to update the notification value of the task. See the description of the action parameter below. | ||||||||||||
index | The index within the target task's array of notification values to which the notification is to be sent. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
false | If action is set to SetValueWithoutOverwrite and the task's notification value cannot be updated because the target task already had a notification pending. |
true | Otherwise. |
Example Usage
|
inline |
Function that calls BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Function that calls BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken )
Version of notify() that can be used from an interrupt service routine (ISR). See the documentation page for the notify() API function for a description of their operation and the necessary configuration parameters, as well as backward compatibility information.
higherPriorityTaskWoken | A reference that will be set to true if sending the notification caused a task to unblock, and the unblocked task has a priority higher than the currently running task. If higherPriorityTaskWoken is set to true, then a context switch should be requested before the interrupt is exited. | ||||||||||||
action | An enumerated type that can take one of the values documented in the table below in order to perform the associated action.
| ||||||||||||
value | Used to update the notification value of the task. See the description of the action parameter below. | ||||||||||||
index | The index within the target task's array of notification values to which the notification is to be sent. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
false | If action is set to SetValueWithoutOverwrite and the task's notification value cannot be updated because the target task already had a notification pending. |
true | Otherwise. |
Example Usage This example demonstrates how to use notifyFromISR() with the SetBits action. See the notify() API documentation page for examples showing how to use the NoAction, SetValueWithOverwrite and SetValueWithoutOverwrite actions.
|
inline |
Function that calls BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Function that calls BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify )
configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these functions to be available.
Each task has a private array of "notification values" (or 'notifications'), each of which is a 32-bit unsigned integer (uint32_t). The constant configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the array, and (for backward compatibility) defaults to 1 if left undefined. Prior to FreeRTOS V10.4.0 there was only one notification value per task.
Events can be sent to a task using an intermediary object. Examples of such objects are queues, semaphores, mutexes and event groups. Task notifications are a method of sending an event directly to a task without the need for such an intermediary object.
A notification sent to a task can optionally perform an action, such as update, overwrite or increment one of the task's notification values. In that way task notifications can be used to send data to a task, or be used as light weight and fast binary or counting semaphores.
notifyGive() indicies is are intended for use when task notifications are used as light weight and faster binary or counting semaphore equivalents. Actual FreeRTOS semaphores are given using the FreeRTOS::Semaphore API, the equivalent action that instead uses a task notification is notifyGive().
When task notifications are being used as a binary or counting semaphore equivalent then the task being notified should wait for the notification using the notificationTake() API function rather than the notifyWaitIndexed() API function.
index | The index within the target task's array of notification values to which the notification is to be sent. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
Example Usage
|
inline |
Function that calls void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken )
Version of notifyGive() that can be used from an interrupt service routine (ISR). See the documentation page for the notifyGive() API function for a description of their operation and the necessary configuration parameters.
higherPriorityTaskWoken | A reference that will be set to true if sending the notification caused a task to unblock, and the unblocked task has a priority higher than the currently running task. If higherPriorityTaskWoken is set to true, then a context switch should be requested before the interrupt is exited. |
index | The index within the target task's array of notification values to which the notification is to be sent. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
Example Usage
|
inline |
Function that calls void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Function that calls BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear )
configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these functions to be available.
Each RTOS task has an array of task notifications. Each task notification has a notification state that can be either ‘pending’ or ‘not pending’, and a 32-bit notification value.
If a notification is sent to an index within the array of notifications then the notification at that index is said to be 'pending' until the task reads its notification value or explicitly clears the notification state to 'not pending' by calling notifyStateClear().
index | The index within the target task's array of notification values to act upon. For example, setting index to 1 will clear the state of the notification at index 1 within the array. |
index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
notifyStateClear() does not have this parameter and always acts on the notification at index 0.
true | If the task had a notification pending, and the notification was cleared. |
false | If the task didn't have a notification pending. |
Example Usage
|
inlinestaticprotected |
Function that calls uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait )
configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these functions to be available.
Each task has a private array of "notification values" (or 'notifications'), each of which is a 32-bit unsigned integer (uint32_t). The constant configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the array, and (for backward compatibility) defaults to 1 if left undefined. Prior to FreeRTOS V10.4.0 there was only one notification value per task.
Events can be sent to a task using an intermediary object. Examples of such objects are queues, semaphores, mutexes and event groups. Task notifications are a method of sending an event directly to a task without the need for such an intermediary object.
A notification sent to a task can optionally perform an action, such as update, overwrite or increment one of the task's notification values. In that way task notifications can be used to send data to a task, or be used as light weight and fast binary or counting semaphores.
notifyTake() is intended for use when a task notification is used as a faster and lighter weight binary or counting semaphore alternative. Actual FreeRTOS semaphores are taken using the FreeRTOS::Semaphore::take() API function, the equivalent action that instead uses a task notification is notifyTake().
When task notifications are being used as a binary or counting semaphore equivalent then the task being notified should wait for the notification using the notificationTake() API function rather than the notifyWait() API function.
notifyTake() can either clear the task's notification value at the array index specified by the indexToWaitOn parameter to zero on exit, in which case the notification value acts like a binary semaphore, or decrement the notification value on exit, in which case the notification value acts like a counting semaphore.
A task can use notifyTake() to [optionally] block to wait for a notification. The task does not consume any CPU time while it is in the Blocked state.
Where as notifyWait() will return when a notification is pending, notifyTake() will return when the task's notification value is not zero.
ticksToWait | The maximum time to wait in the Blocked state for a notification to be received if a notification is not already pending when notifyTake() is called. The RTOS task does not consume any CPU time when it is in the Blocked state. The time is specified in RTOS tick periods. The pdMS_TO_TICKS() macro can be used to convert a time specified in milliseconds into a time specified in ticks. |
clearCountOnExit | If an RTOS task notification is received and clearCountOnExit is set to false then the RTOS task's notification value is decremented before notifyTake() exits. This is equivalent to the value of a counting semaphore being decremented by a successful call to FreeRTOS::Semaphore::Take(). If an RTOS task notification is received and clearCountOnExit is set to true then the RTOS task's notification value is reset to 0 before notifyTake() exits. This is equivalent to the value of a binary semaphore being left at zero (or empty, or 'not available') after a successful call to FreeRTOS::Semaphore::Take(). |
index | The index within the calling task's array of notification values on which the calling task will wait for a notification to be non-zero. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
Example Usage
|
inline |
Function that calls uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear )
configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these functions to be available.
Each RTOS task has an array of task notifications. Each task notification has a notification state that can be either ‘pending’ or ‘not pending’, and a 32-bit notification value.
notifyValueClear() clears the bits specified by the bitsToClear bit mask in the notification value at array index index of the task.
bitsToClear | Bit mask of the bits to clear in the notification value of the task. Set a bit to 1 to clear the corresponding bits in the task's notification value. Set bitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear the notification value to 0. Set bitsToClear to 0 to query the task's notification value without clearing any bits. |
index | The index within the target task's array of notification values in which to clear the bits. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
Example Usage
|
inlinestatic |
Function that calls BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait )
configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these functions to be available.
Each task has an array of 'task notifications' (or just 'notifications'), each of which has a state and a 32-bit value. A direct to task notification is an event sent directly to a task that can unblock the receiving task, and optionally update one of the receiving task’s notification values in a number of different ways. For example, a notification may overwrite one of the receiving task’s notification values, or just set one or more bits in one of the receiving task’s notification values.
notifyWait() waits, with an optional timeout, for the calling task to receive a notification. If the receiving RTOS task was already Blocked waiting for a notification when the notification it is waiting for arrives the receiving RTOS task will be removed from the Blocked state and the notification cleared.
notifyGive() must not be called from an interrupt service routine. Use notifyGiveFromISR() instead.
ticksToWait | The maximum time to wait in the Blocked state for a notification to be received if a notification is not already pending when notifyWait() is called. |
The RTOS task does not consume any CPU time when it is in the Blocked state.
The time is specified in RTOS tick periods. The pdMS_TO_TICKS() macro can be used to convert a time specified in milliseconds into a time specified in ticks.
bitsToClearOnEntry | Any bits set in bitsToClearOnEntry will be cleared in the calling RTOS task's notification value on entry to the notifyWait() function (before the task waits for a new notification) provided a notification is not already pending when notifyWait() is called. |
For example, if bitsToClearOnEntry is 0x01, then bit 0 of the task's notification value will be cleared on entry to the function.
Setting bitsToClearOnEntry to 0xffffffff (ULONG_MAX) will clear all the bits in the task's notification value, effectively clearing the value to 0.
bitsToClearOnExit | Any bits set in bitsToClearOnExit will be cleared in the calling RTOS task's notification value before notifyWait() function exits if a notification was received. |
The bits are cleared after the RTOS task's notification value are returned.
For example, if bitsToClearOnExit is 0x03, then bit 0 and bit 1 of the task's notification value will be cleared before the function exits.
Setting bitsToClearOnExit to 0xffffffff (ULONG_MAX) will clear all the bits in the task's notification value, effectively clearing the value to 0.
index | The index within the calling task's array of notification values on which the calling task will wait for a notification to be received. index must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. |
true | If a notification was received, or a notification was already pending when notifyWait() was called. |
false | If the call to notifyWait() timed out before a notification was received. |
Example Usage
|
inline |
Function that calls void vTaskResume( TaskHandle_t xTaskToResume )
INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. See the RTOS Configuration documentation for more information.
Resumes a suspended task.
A task that has been suspended by one or more calls to suspend() will be made available for running again by a single call to resume().
Example Usage
|
inline |
Function that calls BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )
INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be available. See the configuration section for more information.
An implementation of resume() that can be called from within an ISR.
A task that has been suspended by one or more calls to suspend() will be made available for running again by a single call to resumeFromISR().
resumeFromISR() should not be used to synchronize a task with an interrupt if there is a chance that the interrupt could arrive prior to the task being suspended - as this can lead to interrupts being missed. Use of a semaphore as a synchronisation mechanism would avoid this eventuality.
true | If resuming the task should result in a context switch. This is used by the ISR to determine if a context switch may be required following the ISR. |
false | Otherwise. |
Example Usage
|
inline |
Function that calls void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority )
INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. See the configuration section for more information.
Set the priority of the task.
A context switch will occur before the function returns if the priority being set is higher than the currently executing task.
newPriority | The priority to which the task will be set. |
Example Usage
|
inline |
Function that calls void vTaskSuspend( TaskHandle_t xTaskToSuspend )
INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. See the RTOS Configuration documentation for more information.
Suspend a task. When suspended a task will never get any microcontroller processing time, no matter what its priority.
Calls to suspend() are not accumulative - i.e. calling suspend() twice on the same task still only requires one call to resume() to ready the suspended task.
Example Usage
|
inlinefinalvirtual |
Function that acts as the entry point of the task instance. This function initializes the previous wake time of the task and calls the user implemented taskFunction().
callTaskFunction()
and should not be called or referenced by the user.
|
protectedpure virtual |
Abstraction function that acts as the entry point of the task for the user.