ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
static_task.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
5#include <freertos/FreeRTOS.h>
6#include <freertos/task.h>
7
9
10#include <cstdint>
11
12namespace esphome {
13
19 public:
20 StaticTask() = default;
21 // Non-copyable, non-movable — the task handle and its buffers are not transferable
22 StaticTask(const StaticTask &) = delete;
23 StaticTask &operator=(const StaticTask &) = delete;
24 StaticTask(StaticTask &&) = delete;
26
28 bool is_created() const { return this->handle_ != nullptr; }
29
31 TaskHandle_t get_handle() const { return this->handle_; }
32
42 bool create(TaskFunction_t fn, const char *name, uint32_t stack_size, void *param, UBaseType_t priority,
43 bool use_psram, BaseType_t core_id = tskNO_AFFINITY);
44
50 bool destroy();
51
55 bool deallocate();
56
57 protected:
58 TaskHandle_t handle_{nullptr};
62 bool use_psram_{false};
63};
64
65} // namespace esphome
66
67#endif // USE_ESP32
Helper for FreeRTOS static task management.
Definition static_task.h:18
bool is_created() const
Check if the task has been created and not yet destroyed.
Definition static_task.h:28
RAMUniquePtr< StackType_t[]> stack_buffer_
Definition static_task.h:60
bool destroy()
Delete the task, keeping the TCB and stack buffer allocated for reuse by a subsequent create() call.
StaticTask(StaticTask &&)=delete
TaskHandle_t get_handle() const
Get the FreeRTOS task handle.
Definition static_task.h:31
bool deallocate()
Delete the task (if created) and free the TCB and stack buffer.
TaskHandle_t handle_
Definition static_task.h:58
RAMUniquePtr< StaticTask_t > tcb_
Definition static_task.h:59
StaticTask & operator=(const StaticTask &)=delete
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.
StaticTask & operator=(StaticTask &&)=delete
StaticTask(const StaticTask &)=delete
uint8_t priority
std::unique_ptr< T, RAMDeleter< T > > RAMUniquePtr
unique_ptr over RAMAllocator storage
Definition helpers.h:2211
static void uint32_t