ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
wake_freertos.h
Go to the documentation of this file.
1#pragma once
2
4
5#if defined(USE_ESP32) || defined(USE_LIBRETINY)
6
7#include "esphome/core/hal.h"
9
10namespace esphome {
11
14__attribute__((always_inline)) inline void wake_main_task_any_context() {
15 // Set the wake-requested flag BEFORE the task notification so the consumer
16 // (Application::loop() gate) is guaranteed to see it on its next gate check.
17 wake_request_set();
18 if (in_isr_context()) {
19 BaseType_t px_higher_priority_task_woken = pdFALSE;
20 esphome_main_task_notify_from_isr(&px_higher_priority_task_woken);
21#ifdef portYIELD_FROM_ISR
22 portYIELD_FROM_ISR(px_higher_priority_task_woken);
23#else
24 // ARM9 FreeRTOS port (BK72xx) does not define portYIELD_FROM_ISR; the IRQ
25 // exit sequence performs the context switch if one was requested.
26 (void) px_higher_priority_task_woken;
27#endif
28 } else {
29 esphome_main_task_notify();
30 }
31}
32
34void wake_loop_isrsafe(BaseType_t *px_higher_priority_task_woken);
36
37inline void wake_scheduler_threadsafe() { esphome_main_task_notify(); }
38
39inline void wake_loop_threadsafe() {
40 wake_request_set();
42}
43
44namespace internal {
45inline void ESPHOME_ALWAYS_INLINE wakeable_delay(uint32_t ms) {
46 // Fast path (with USE_LWIP_FAST_SELECT): FreeRTOS task notifications posted by the lwip
47 // event_callback wrapper (see lwip_fast_select.c) are the single source of truth for
48 // socket wake-ups. Every NETCONN_EVT_RCVPLUS calls esphome_main_task_notify(), so any notification
49 // that lands between wakes keeps the counter non-zero (next esphome_main_task_wait() returns
50 // immediately) or wakes a blocked wait directly. Additional wake sources:
51 // wake_loop_threadsafe() from background tasks, and the ms timeout.
52 if (ms == 0) [[unlikely]] {
53 yield();
54 return;
55 }
56 esphome_main_task_wait(pdMS_TO_TICKS(ms));
57}
58} // namespace internal
59
60} // namespace esphome
61
62#endif // USE_ESP32 || USE_LIBRETINY
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
void yield(void)
void ESPHOME_ALWAYS_INLINE wakeable_delay(uint32_t ms)
Host wakeable_delay uses select() over the registered fds — defined in wake_host.cpp.
void wake_loop_threadsafe()
Non-ISR: always inline.
void wake_scheduler_threadsafe()
void ESPHOME_ALWAYS_INLINE wake_loop_isrsafe()
ISR-safe: no task_woken arg because ESP8266 has no FreeRTOS. Caller must be IRAM_ATTR.
void IRAM_ATTR wake_loop_any_context()
IRAM_ATTR entry point for ISR callers — defined in wake_esp8266.cpp.
static void uint32_t