FreeRTOS-Cpp
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
FreeRTOS::StaticTask< N > Class Template Reference

Class that encapsulates the functionality of a FreeRTOS task. More...

#include <Task.hpp>

Inheritance diagram for FreeRTOS::StaticTask< N >:
Inheritance graph
[legend]
Collaboration diagram for FreeRTOS::StaticTask< N >:
Collaboration graph
[legend]

Public Member Functions

 StaticTask (const StaticTask &)=delete
 
StaticTaskoperator= (const StaticTask &)=delete
 
- Public Member Functions inherited from FreeRTOS::TaskBase
 TaskBase (const TaskBase &)=delete
 
TaskBaseoperator= (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...
 

Protected Member Functions

 StaticTask (const UBaseType_t priority=tskIDLE_PRIORITY, const char *name="")
 Construct a new Task object by calling TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, const char * const pcName, const uint32_t ulStackDepth, void * const pvParameters, UBaseType_t uxPriority, StackType_t * const puxStackBuffer, StaticTask_t * const pxTaskBuffer ) More...
 
 StaticTask (StaticTask &&) noexcept=default
 
StaticTaskoperator= (StaticTask &&) noexcept=default
 
- Protected Member Functions inherited from FreeRTOS::TaskBase
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...
 

Private Attributes

StaticTask_t taskBuffer
 
StackType_t stack [N]
 

Additional Inherited Members

- Public Types inherited from FreeRTOS::TaskBase
enum class  State {
  Running = eRunning , Ready = eReady , Blocked = eBlocked , Suspended = eSuspended ,
  Deleted = eDeleted , Invalid = eInvalid
}
 
enum class  NotifyAction {
  NoAction = eNoAction , SetBits = eSetBits , Increment = eIncrement , SetValueWithOverwrite = eSetValueWithOverwrite ,
  SetValueWithoutOverwrite = eSetValueWithoutOverwrite
}
 
using NotificationBits = std::bitset< 32 >
 
- Static Public Member Functions inherited from FreeRTOS::TaskBase
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...
 
- Static Protected Member Functions inherited from FreeRTOS::TaskBase
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...
 

Detailed Description

template<UBaseType_t N = configMINIMAL_STACK_SIZE>
class FreeRTOS::StaticTask< N >

Class that encapsulates the functionality of a FreeRTOS task.

StaticTask Task.hpp <FreeRTOS/Task.hpp>

Each task requires RAM that is used to hold the task state, and used by the task as its stack. If a task is created using this class then the RAM is included in the object. If a task is created using FreeRTOS::Task() then the required RAM is automatically allocated from the FreeRTOS heap. See the Static Vs Dynamic allocation page for more information.

Note
This class is not intended to be instantiated by the user. The user should create a class that derives from this class and implement taskFunction().
Warning
This class contains the task's data structures (TCB) and the array used to store the task's stack, so any instace of this class or class derived from this class must be persistent (not declared on the stack of another function).
Template Parameters
NThe number of indexes in the array of StackType_t used to store the stack for this task.

Constructor & Destructor Documentation

◆ StaticTask()

template<UBaseType_t N = configMINIMAL_STACK_SIZE>
FreeRTOS::StaticTask< N >::StaticTask ( const UBaseType_t  priority = tskIDLE_PRIORITY,
const char *  name = "" 
)
inlineexplicitprotected

Construct a new Task object by calling TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, const char * const pcName, const uint32_t ulStackDepth, void * const pvParameters, UBaseType_t uxPriority, StackType_t * const puxStackBuffer, StaticTask_t * const pxTaskBuffer )

Task.hpp

See also
https://www.freertos.org/xTaskCreateStatic.html
Note
When calling xTaskCreateStatic the constructor passes the this pointer as the task function argument. This pointer is used so that the interface function callTaskFunction() can invoke taskEntry() for this instance of the class.
Parameters
priorityThe priority at which the created task will execute. Priorities are asserted to be less than configMAX_PRIORITIES. If configASSERT is undefined, priorities are silently capped at (configMAX_PRIORITIES - 1).
nameA descriptive name for the task. This is mainly used to facilitate debugging, but can also be used to obtain a task handle. The maximum length of a task's name is defined by configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.

Example Usage

#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::StaticTask<configMINIMAL_STACK_SIZE> {
public:
MyTask(const UBaseType_t priority, const char* name)
: FreeRTOS::StaticTask<configMINIMAL_STACK_SIZE>(priority, name) {}
void taskFunction() final;
};
// Task to be created.
void MyTask::taskFunction() {
for (;;) {
// Task code goes here.
}
}
// Create the task in persistent storage.
static MyTask task((tskIDLE_PRIORITY + 1), "NAME");
// Function that starts the scheduler.
void aFunction() {
// Start the scheduler.
}
Class that encapsulates the functionality of a FreeRTOS task.
Definition: Task.hpp:1423
virtual void taskFunction()=0
Abstraction function that acts as the entry point of the task for the user.
void startScheduler()
Function that calls vTaskStartScheduler()
Definition: Kernel.hpp:275

The documentation for this class was generated from the following file: