diff --git a/esphome/core/main_task.c b/esphome/core/main_task.c index 0addb6ed86..52d9c2951a 100644 --- a/esphome/core/main_task.c +++ b/esphome/core/main_task.c @@ -1,39 +1,5 @@ #include "esphome/core/main_task.h" #if defined(USE_ESP32) || defined(USE_LIBRETINY) - -// IRAM_ATTR is defined by esp_attr.h (included via FreeRTOS headers) on ESP32. -// On LibreTiny it's not reliably available — provide a no-op fallback. -#ifndef IRAM_ATTR -#define IRAM_ATTR -#endif - TaskHandle_t esphome_main_task_handle = NULL; - -void esphome_main_task_notify(void) { - TaskHandle_t task = esphome_main_task_handle; - if (task != NULL) { - xTaskNotifyGive(task); - } -} - -void IRAM_ATTR esphome_main_task_notify_from_isr(int *px_higher_priority_task_woken) { - TaskHandle_t task = esphome_main_task_handle; - if (task != NULL) { - vTaskNotifyGiveFromISR(task, (BaseType_t *) px_higher_priority_task_woken); - } -} - -#ifdef USE_ESP32 -void IRAM_ATTR esphome_main_task_notify_any_context(void) { - if (xPortInIsrContext()) { - int px_higher_priority_task_woken = 0; - esphome_main_task_notify_from_isr(&px_higher_priority_task_woken); - portYIELD_FROM_ISR(px_higher_priority_task_woken); - } else { - esphome_main_task_notify(); - } -} #endif - -#endif // USE_ESP32 || USE_LIBRETINY diff --git a/esphome/core/main_task.h b/esphome/core/main_task.h index 4223dec3ec..8ea46afe35 100644 --- a/esphome/core/main_task.h +++ b/esphome/core/main_task.h @@ -20,14 +20,32 @@ extern "C" { extern TaskHandle_t esphome_main_task_handle; /// Wake the main loop task from another FreeRTOS task. NOT ISR-safe. -void esphome_main_task_notify(void); +static inline void esphome_main_task_notify(void) { + TaskHandle_t task = esphome_main_task_handle; + if (task != NULL) { + xTaskNotifyGive(task); + } +} /// Wake the main loop task from an ISR. ISR-safe. -void esphome_main_task_notify_from_isr(int *px_higher_priority_task_woken); +static inline void esphome_main_task_notify_from_isr(int *px_higher_priority_task_woken) { + TaskHandle_t task = esphome_main_task_handle; + if (task != NULL) { + vTaskNotifyGiveFromISR(task, (BaseType_t *) px_higher_priority_task_woken); + } +} #ifdef USE_ESP32 /// Wake the main loop from any context (ISR or task). ESP32-only (needs xPortInIsrContext). -void esphome_main_task_notify_any_context(void); +static inline void esphome_main_task_notify_any_context(void) { + if (xPortInIsrContext()) { + int px_higher_priority_task_woken = 0; + esphome_main_task_notify_from_isr(&px_higher_priority_task_woken); + portYIELD_FROM_ISR(px_higher_priority_task_woken); + } else { + esphome_main_task_notify(); + } +} #endif #ifdef __cplusplus diff --git a/esphome/core/wake.cpp b/esphome/core/wake.cpp index 723988509b..ddc377d191 100644 --- a/esphome/core/wake.cpp +++ b/esphome/core/wake.cpp @@ -15,9 +15,9 @@ namespace esphome { // === ESP32 — IRAM_ATTR entry points === #ifdef USE_ESP32 void IRAM_ATTR wake_loop_isrsafe(int *px_higher_priority_task_woken) { - wake_loop_isrsafe_inline_(px_higher_priority_task_woken); + esphome_main_task_notify_from_isr(px_higher_priority_task_woken); } -void IRAM_ATTR wake_loop_any_context() { wake_loop_any_context_inline_(); } +void IRAM_ATTR wake_loop_any_context() { esphome_main_task_notify_any_context(); } #endif // === ESP8266 / RP2040 === diff --git a/esphome/core/wake.h b/esphome/core/wake.h index 1b2905934d..82375f4c0c 100644 --- a/esphome/core/wake.h +++ b/esphome/core/wake.h @@ -29,15 +29,8 @@ extern volatile bool g_main_loop_woke; #if defined(USE_ESP32) || defined(USE_LIBRETINY) #ifdef USE_ESP32 -/// Inline impl — ISR callers inline this into IRAM. -inline void ESPHOME_ALWAYS_INLINE wake_loop_isrsafe_inline_(int *px_higher_priority_task_woken) { - esphome_main_task_notify_from_isr(px_higher_priority_task_woken); -} /// IRAM_ATTR entry point — defined in wake.cpp. void wake_loop_isrsafe(int *px_higher_priority_task_woken); - -/// Inline impl — ISR callers inline this into IRAM. -inline void ESPHOME_ALWAYS_INLINE wake_loop_any_context_inline_() { esphome_main_task_notify_any_context(); } /// IRAM_ATTR entry point — defined in wake.cpp. void wake_loop_any_context(); #else