ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
wake_zephyr.cpp
Go to the documentation of this file.
2
3#ifdef USE_ZEPHYR
4
5#include "esphome/core/hal.h"
6#include "esphome/core/wake.h"
7
8#include <zephyr/kernel.h>
9
10namespace esphome {
11
12// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
13K_SEM_DEFINE(esphome_wake_sem, 0, 1);
14
15// === Wake-requested flag storage ===
16#ifdef ESPHOME_THREAD_MULTI_ATOMICS
17// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
18std::atomic<uint8_t> g_wake_requested{0};
19#else
20// Cortex-M0: aligned 8-bit store/load is a single non-tearing instruction,
21// and k_sem_give()/k_sem_take() provide the release/acquire barriers.
22// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
23volatile uint8_t g_wake_requested = 0;
24#endif
25
26void wake_scheduler_threadsafe() { k_sem_give(&esphome_wake_sem); }
27
29 wake_request_set();
31}
32
33namespace internal {
34void wakeable_delay(uint32_t ms) {
35 if (ms == 0) [[unlikely]] {
36 yield();
37 return;
38 }
39 k_sem_take(&esphome_wake_sem, ms == UINT32_MAX ? K_FOREVER : K_MSEC(ms));
40}
41} // namespace internal
42
43} // namespace esphome
44
45#endif // USE_ZEPHYR
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.
std::atomic< uint8_t > g_wake_requested
Definition wake.h:49
void wake_loop_threadsafe()
Non-ISR: always inline.
void wake_scheduler_threadsafe()
K_SEM_DEFINE(esphome_wake_sem, 0, 1)
static void uint32_t
Platform-specific main loop wake primitives.