ESPHome 2026.5.0b1
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_loop_threadsafe() {
38 wake_request_set();
39 esphome_main_task_notify();
40}
41
42namespace internal {
43inline void ESPHOME_ALWAYS_INLINE wakeable_delay(uint32_t ms) {
44 // Fast path (with USE_LWIP_FAST_SELECT): FreeRTOS task notifications posted by the lwip
45 // event_callback wrapper (see lwip_fast_select.c) are the single source of truth for
46 // socket wake-ups. Every NETCONN_EVT_RCVPLUS posts an xTaskNotifyGive, so any notification
47 // that lands between wakes keeps the counter non-zero (next ulTaskNotifyTake returns
48 // immediately) or wakes a blocked Take directly. Additional wake sources:
49 // wake_loop_threadsafe() from background tasks, and the ms timeout.
50 if (ms == 0) [[unlikely]] {
51 yield();
52 return;
53 }
54 ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(ms));
55}
56} // namespace internal
57
58} // namespace esphome
59
60#endif // USE_ESP32 || USE_LIBRETINY
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
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 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