ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::StaticTask Class Reference

Helper for FreeRTOS static task management. More...

#include <static_task.h>

Public Member Functions

 StaticTask ()=default
 
 StaticTask (const StaticTask &)=delete
 
StaticTask & operator= (const StaticTask &)=delete
 
 StaticTask (StaticTask &&)=delete
 
StaticTask & operator= (StaticTask &&)=delete
 
bool is_created () const
 Check if the task has been created and not yet destroyed.
 
TaskHandle_t get_handle () const
 Get the FreeRTOS task handle.
 
bool create (TaskFunction_t fn, const char *name, uint32_t stack_size, void *param, UBaseType_t priority, bool use_psram, BaseType_t core_id=tskNO_AFFINITY)
 Allocate the TCB (always internal RAM) and the stack, then create the task.
 
bool destroy ()
 Delete the task, keeping the TCB and stack buffer allocated for reuse by a subsequent create() call.
 
bool deallocate ()
 Delete the task (if created) and free the TCB and stack buffer.
 

Protected Attributes

TaskHandle_t handle_ {nullptr}
 
RAMUniquePtr< StaticTask_t > tcb_
 
RAMUniquePtr< StackType_t[]> stack_buffer_
 
uint32_t stack_size_ {0}
 
bool use_psram_ {false}
 

Detailed Description

Helper for FreeRTOS static task management.

Stores the TCB in internal RAM and manages the stack buffer with create/destroy methods. Call destroy() and deallocate() from another task: a task cannot free the stack it is still running on.

Definition at line 18 of file static_task.h.

Constructor & Destructor Documentation

◆ StaticTask() [1/3]

esphome::StaticTask::StaticTask ( )
default

◆ StaticTask() [2/3]

esphome::StaticTask::StaticTask ( const StaticTask & )
delete

◆ StaticTask() [3/3]

esphome::StaticTask::StaticTask ( StaticTask && )
delete

Member Function Documentation

◆ create()

bool esphome::StaticTask::create ( TaskFunction_t fn,
const char * name,
uint32_t stack_size,
void * param,
UBaseType_t priority,
bool use_psram,
BaseType_t core_id = tskNO_AFFINITY )

Allocate the TCB (always internal RAM) and the stack, then create the task.

Parameters
fnTask function
nameTask name (for debug)
stack_sizeStack size in bytes (StackType_t is a byte on ESP-IDF)
paramParameter passed to task function
priorityFreeRTOS task priority
use_psramIf true, allocate stack in PSRAM; otherwise internal RAM
core_idCPU core, or tskNO_AFFINITY to leave scheduling unrestricted
Returns
true on success; false if either allocation fails or the task cannot be created

Definition at line 9 of file static_task.cpp.

◆ deallocate()

bool esphome::StaticTask::deallocate ( )

Delete the task (if created) and free the TCB and stack buffer.

Returns
true if the buffers were freed; false if the task is still running on another core, in which case the caller should try again later.

Definition at line 71 of file static_task.cpp.

◆ destroy()

bool esphome::StaticTask::destroy ( )

Delete the task, keeping the TCB and stack buffer allocated for reuse by a subsequent create() call.

The task must have finished its work and parked itself, either suspended or blocked indefinitely: it is suspended here so that it cannot be scheduled again, and it is given no chance to clean up.

Returns
true if the task was deleted; false if it is still running on another core, in which case the caller should try again later.

Definition at line 50 of file static_task.cpp.

◆ get_handle()

TaskHandle_t esphome::StaticTask::get_handle ( ) const
inline

Get the FreeRTOS task handle.

Definition at line 31 of file static_task.h.

◆ is_created()

bool esphome::StaticTask::is_created ( ) const
inline

Check if the task has been created and not yet destroyed.

Definition at line 28 of file static_task.h.

◆ operator=() [1/2]

StaticTask & esphome::StaticTask::operator= ( const StaticTask & )
delete

◆ operator=() [2/2]

StaticTask & esphome::StaticTask::operator= ( StaticTask && )
delete

Field Documentation

◆ handle_

TaskHandle_t esphome::StaticTask::handle_ {nullptr}
protected

Definition at line 58 of file static_task.h.

◆ stack_buffer_

RAMUniquePtr<StackType_t[]> esphome::StaticTask::stack_buffer_
protected

Definition at line 60 of file static_task.h.

◆ stack_size_

uint32_t esphome::StaticTask::stack_size_ {0}
protected

Definition at line 61 of file static_task.h.

◆ tcb_

RAMUniquePtr<StaticTask_t> esphome::StaticTask::tcb_
protected

Definition at line 59 of file static_task.h.

◆ use_psram_

bool esphome::StaticTask::use_psram_ {false}
protected

Definition at line 62 of file static_task.h.


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