ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
main_task.h
Go to the documentation of this file.
1#pragma once
2
5
6#if defined(USE_ESP32) || defined(USE_LIBRETINY)
7
8#ifdef USE_ESP32
9#include <freertos/FreeRTOS.h>
10#include <freertos/task.h>
11#else
12#include <FreeRTOS.h>
13#include <task.h>
14#endif
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20extern TaskHandle_t esphome_main_task_handle;
21
22#ifdef USE_ESP32
26#if configTASK_NOTIFICATION_ARRAY_ENTRIES < 2
27#error "CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES must be at least 2"
28#endif
29#endif
30
33__attribute__((always_inline)) static inline void esphome_main_task_notify() {
34 TaskHandle_t task = esphome_main_task_handle;
35 if (task != NULL) {
36#ifdef USE_ESP32
37 xTaskNotifyGiveIndexed(task, ESPHOME_MAIN_TASK_NOTIFY_INDEX);
38#else
39 xTaskNotifyGive(task);
40#endif
41 }
42}
43
45__attribute__((always_inline)) static inline void esphome_main_task_notify_from_isr(
46 BaseType_t *px_higher_priority_task_woken) {
47 TaskHandle_t task = esphome_main_task_handle;
48 if (task != NULL) {
49#ifdef USE_ESP32
50 vTaskNotifyGiveIndexedFromISR(task, ESPHOME_MAIN_TASK_NOTIFY_INDEX, px_higher_priority_task_woken);
51#else
52 vTaskNotifyGiveFromISR(task, px_higher_priority_task_woken);
53#endif
54 }
55}
56
58__attribute__((always_inline)) static inline void esphome_main_task_wait(TickType_t ticks) {
59#ifdef USE_ESP32
60 ulTaskNotifyTakeIndexed(ESPHOME_MAIN_TASK_NOTIFY_INDEX, pdTRUE, ticks);
61#else
62 ulTaskNotifyTake(pdTRUE, ticks);
63#endif
64}
65
66#ifdef __cplusplus
67}
68#endif
69
70#endif // USE_ESP32 || USE_LIBRETINY
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
@ ESPHOME_MAIN_TASK_NOTIFY_INDEX
Definition main_task.h:25
TaskHandle_t esphome_main_task_handle
Main loop task handle and wake helpers — shared between wake.h (C++) and lwip_fast_select....
Definition main_task.c:4