ESPHome 2026.11.0-dev
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_scheduler_impl() {
15 // Skip the post when a wake was already signalled and not yet consumed by
16 // wakeable_delay(): esp_schedule() -> ets_post() can enter SDK WiFi pm code,
17 // which must not be poked per-byte from the software serial RX ISR (see
18 // esphome#18409). The flag can stay latched while the loop is awake, which
19 // is intentional; posts are only needed to cut a suspend short.
21 return;
22 g_main_loop_woke = true;
23 esp_schedule();
24}
25
26inline void ESPHOME_ALWAYS_INLINE wake_loop_impl() {
27 // Set the wake-requested flag BEFORE esp_schedule so the consumer is
28 // guaranteed to see it on its next gate check.
29 wake_request_set();
31}
32
35
39
41inline void ESPHOME_ALWAYS_INLINE wake_loop_isrsafe() { wake_loop_impl(); }
42
43namespace internal {
44inline void ESPHOME_ALWAYS_INLINE wakeable_delay(uint32_t ms) {
45 if (ms == 0) [[unlikely]] {
46 delay(0);
47 return;
48 }
49 if (g_main_loop_woke) {
50 g_main_loop_woke = false;
51 // Yield even on the already-woken fast path so callers in tight loops
52 // (e.g. lwIP raw TCP wait_for_data_) make forward progress when ISRs
53 // keep re-setting g_main_loop_woke between iterations.
54 delay(0);
55 return;
56 }
57 esp_delay(ms, []() { return !g_main_loop_woke; });
58}
59} // namespace internal
60
61} // namespace esphome
62
63#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()
void wake_scheduler_threadsafe()
volatile bool g_main_loop_woke
void ESPHOME_ALWAYS_INLINE wake_scheduler_impl()
Inline implementation — IRAM callers inline this directly.
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