wifi_sta_connect_status_() is a non-inlined function call that reads
3 static globals through literal pool indirections on every loop
iteration. Since those globals are only modified during event
processing, skip the call entirely when wifi_loop_() found no
events and we're already in STA_CONNECTED state.
wifi_loop_() now returns bool (true if events were processed) on
all platforms. ESP8266 and Pico W always return true since they
poll state directly rather than using an event queue.
GCC on Xtensa emits memw for relaxed atomic loads too, so the
savings from relaxed vs acquire are only 2 memw (~4 cycles) — not
worth the weaker correctness guarantees. The real optimization is
the early return that skips get_and_reset_dropped_count() and the
pop() loop entirely.
On Xtensa (ESP32), even relaxed atomic loads emit memw instructions,
but they avoid the more expensive acquire fences. The pop() path
required acquire loads + release stores just to discover the queue
was empty. By checking empty_relaxed() first, the steady-state
connected path (queue always empty) returns in ~7 instructions
instead of falling through to get_and_reset_dropped_count() and pop().
The FreeRTOS timer command queue moves from heap to BSS on all
LibreTiny targets, not just BK72xx. RTL87xx and LN882x benefit
from the same heap savings.
Add build flag and required callbacks (following ESP-IDF's pvPortMalloc
approach) so FreeRTOSQueue can use xQueueCreateStatic — queue storage
lives in BSS with zero runtime heap allocation.
- Protect dropped_count_ increment and get+reset with
portENTER_CRITICAL/portEXIT_CRITICAL since std::atomic is unavailable
on NO_ATOMICS platforms
- Delete copy/move constructors and assignment operators
- Remove volatile qualifier (critical sections provide proper
synchronization)
BK72xx's FreeRTOS does not enable configSUPPORT_STATIC_ALLOCATION,
so xQueueCreateStatic is unavailable. Fall back to xQueueCreate
which is a one-time heap allocation during setup.
Replace static FreeRTOS queue globals in the LibreTiny WiFi component
with the same queue abstraction used by ESP32:
- ESPHOME_THREAD_MULTI_ATOMICS (RTL87xx, LN882x): LockFreeQueue
- ESPHOME_THREAD_MULTI_NO_ATOMICS (BK72xx): new FreeRTOSQueue wrapper
Add FreeRTOSQueue in freertos_queue.h — an xQueue wrapper providing
the same API as LockFreeQueue (push, pop, get_and_reset_dropped_count)
for platforms without hardware atomic instructions.
The event queue is now a class member instead of a static global,
matching the ESP32 pattern.
Co-authored-by: J. Nick Koston <nick+github@koston.org>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>