ESPHome 2026.8.0b4
Loading...
Searching...
No Matches
wake_esp8266.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_ESP8266
6
7#include "esphome/core/hal.h"
8
9#include <coredecls.h>
10
11namespace esphome {
12
14inline void ESPHOME_ALWAYS_INLINE wake_loop_impl() {
15 // Set the wake-requested flag BEFORE esp_schedule so the consumer is
16 // guaranteed to see it on its next gate check.
17 wake_request_set();
18 // Skip the post when a wake was already signalled and not yet consumed by
19 // wakeable_delay(): esp_schedule() -> ets_post() can enter SDK WiFi pm code,
20 // which must not be poked per-byte from the software serial RX ISR (see
21 // esphome#18409). The flag can stay latched while the loop is awake, which
22 // is intentional; posts are only needed to cut a suspend short.
24 return;
25 g_main_loop_woke = true;
26 esp_schedule();
27}
28
31
34
36inline void ESPHOME_ALWAYS_INLINE wake_loop_isrsafe() { wake_loop_impl(); }
37
38namespace internal {
39inline void ESPHOME_ALWAYS_INLINE wakeable_delay(uint32_t ms) {
40 if (ms == 0) [[unlikely]] {
41 delay(0);
42 return;
43 }
44 if (g_main_loop_woke) {
45 g_main_loop_woke = false;
46 // Yield even on the already-woken fast path so callers in tight loops
47 // (e.g. lwIP raw TCP wait_for_data_) make forward progress when ISRs
48 // keep re-setting g_main_loop_woke between iterations.
49 delay(0);
50 return;
51 }
52 esp_delay(ms, []() { return !g_main_loop_woke; });
53}
54} // namespace internal
55
56} // namespace esphome
57
58#endif // USE_ESP8266
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_impl()
Inline implementation — IRAM callers inline this directly.
volatile bool g_main_loop_woke
void HOT delay(uint32_t ms)
Definition hal.cpp:85
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