arduino-audio-tools
Loading...
Searching...
No Matches
Task Class Reference

FreeRTOS task. More...

#include <Task.h>

Inheritance diagram for Task:
ITask

Public Member Functions

 Task ()=default
 Task (const char *name, int stackSizeWords, int priority=1, int core=-1)
 ~Task ()
bool begin (std::function< void()> process)
bool create (const char *name, int stackSizeWords, int priority=1, int core=-1)
void end ()
 suspends the task
int getCoreID ()
void * getReference ()
TaskHandle_t & getTaskHandle ()
bool isEnded ()
 true if the task was never created or has been removed
bool isRunning ()
 true if the task was created and is not suspended
bool isSuspended ()
 true if the task was created and is currently suspended
void remove ()
 deletes the FreeRTOS task
void resume ()
void setReference (void *r)
void suspend ()

Static Protected Member Functions

static void nop ()
static void task_loop (void *arg)

Protected Attributes

std::function< void()> loop_code = nop
void * ref = nullptr
int task_core = -1
const char * task_name = nullptr
int task_priority = 1
int task_stack_size = 0
bool task_suspended = false
TaskHandle_t xHandle = nullptr

Detailed Description

FreeRTOS task.

Note
Supported by all FreeRTOS platforms
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ Task() [1/2]

Task ( const char * name,
int stackSizeWords,
int priority = 1,
int core = -1 )
inline

Defines the task parameters; the actual FreeRTOS task is only created when begin() is called (typically from setup()), so that it is safe to declare a Task as a global object.

Parameters
nametask name, used for debugging (e.g. in FreeRTOS trace tools); must stay valid for the lifetime of the task
stackSizeWordsstack depth in words (stack size in bytes = stackSizeWords * sizeof(StackType_t)); note that on ESP32 (ESP-IDF) FreeRTOS takes the stack depth in bytes; too small a value can cause a stack overflow, which on some platforms (e.g. RP2040/arduino-pico) halts the whole system instead of failing gracefully
priorityFreeRTOS task priority; valid range and meaning are platform-specific (bounded by configMAX_PRIORITIES, which differs a lot between platforms, e.g. RP2040/arduino-pico only goes up to 7)
corecore to pin the task to (0 or 1), or -1 to let the scheduler decide; only relevant on multi-core targets

◆ Task() [2/2]

Task ( )
default

◆ ~Task()

~Task ( )
inline

Member Function Documentation

◆ begin()

bool begin ( std::function< void()> process)
inlinevirtual

Implements ITask.

◆ create()

bool create ( const char * name,
int stackSizeWords,
int priority = 1,
int core = -1 )
inline

If you used the empty constructor, you need to call create! Returns false if the task exists already or could not be created.

Parameters
stackSizeWordsstack depth in words (in bytes on ESP32/ESP-IDF)

◆ end()

void end ( )
inlinevirtual

suspends the task

Implements ITask.

◆ getCoreID()

int getCoreID ( )
inline

◆ getReference()

void * getReference ( )
inline

◆ getTaskHandle()

TaskHandle_t & getTaskHandle ( )
inline

◆ isEnded()

bool isEnded ( )
inlinevirtual

true if the task was never created or has been removed

Implements ITask.

◆ isRunning()

bool isRunning ( )
inlinevirtual

true if the task was created and is not suspended

Implements ITask.

◆ isSuspended()

bool isSuspended ( )
inlinevirtual

true if the task was created and is currently suspended

Implements ITask.

◆ nop()

void nop ( )
inlinestaticprotected

◆ remove()

void remove ( )
inline

deletes the FreeRTOS task

◆ resume()

void resume ( )
inline

◆ setReference()

void setReference ( void * r)
inline

◆ suspend()

void suspend ( )
inline

suspends the task (no effect if it was not created: a null handle would suspend the calling task)

◆ task_loop()

void task_loop ( void * arg)
inlinestaticprotected

Member Data Documentation

◆ loop_code

std::function<void()> loop_code = nop
protected

◆ ref

void* ref = nullptr
protected

◆ task_core

int task_core = -1
protected

◆ task_name

const char* task_name = nullptr
protected

◆ task_priority

int task_priority = 1
protected

◆ task_stack_size

int task_stack_size = 0
protected

◆ task_suspended

bool task_suspended = false
protected

◆ xHandle

TaskHandle_t xHandle = nullptr
protected

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