FastLED 3.10.8
Loading...
Searching...
No Matches
driver.cpp.hpp
Go to the documentation of this file.
1
4#include "fl/log/log.h"
6#include "fl/stl/chrono.h"
7#include "fl/task/executor.h"
8#include "platforms/is_platform.h"
9
10namespace fl {
11
12template<typename Condition>
13bool IChannelDriver::waitForCondition(Condition condition, u32 timeoutMs) FL_NO_EXCEPT {
14 const u32 startTime = timeoutMs > 0 ? millis() : 0;
15
16 // Tier 1: instant non-blocking check.
17 if (condition()) {
18 return true;
19 }
20
21 // Tier 2: bounded microsecond spin (#2818). Catches short DMA tails
22 // without paying the >=1-tick floor below. Budget runtime-tunable via
23 // FastLED.setWaitSpinBudgetUs(N); 0 disables.
24 {
25 const u32 spinBudget = fl::detail::getWaitSpinBudgetUs();
26 if (spinBudget > 0) {
27 const u32 spinStart = fl::micros();
28 while ((fl::micros() - spinStart) < spinBudget) {
29 if (condition()) {
30 return true;
31 }
32 if (timeoutMs > 0 && (millis() - startTime) >= timeoutMs) {
33 FL_ERROR("Timeout occurred while waiting for condition");
34 return false;
35 }
36 }
37 }
38 }
39
40 while (!condition()) {
41 // Check timeout if specified
42 if (timeoutMs > 0 && (millis() - startTime >= timeoutMs)) {
43 FL_ERROR("Timeout occurred while waiting for condition");
44 return false; // Timeout occurred
45 }
46
47 // Adaptive yield (refs #2815, generalizes the #2493 ESP32-P4 carve-out):
48 // see the matching comment in ChannelManager::waitForCondition for the
49 // full rationale. The deep yield is only needed when a radio is
50 // actually up; otherwise the FreeRTOS tick floor is pure timing drift.
52 // Radio active: keep WiFi/lwIP/BT alive with the deep yield.
54 } else {
55 // No radio: fast yield, no FreeRTOS tick floor.
57 }
58 }
59
60 return true; // Condition met
61}
62
64 // wait until the driver is in a READY state.
65 bool ok = waitForCondition([this]() {
66 auto state = poll();
68 }, timeoutMs);
69 return ok;
70}
71
73 // wait until the driver is in a READY or DRAINING state.
74 bool ok = waitForCondition([this]() {
75 auto state = poll();
77 }, timeoutMs);
78 return ok;
79}
80
81} // namespace fl
TestState state
FastLED chrono implementation - duration types for time measurements.
bool waitForCondition(Condition condition, u32 timeoutMs=1000) FL_NO_EXCEPT
virtual DriverState poll() FL_NO_EXCEPT=0
Query driver state and perform maintenance.
bool waitForReady(u32 timeoutMs=1000) FL_NO_EXCEPT
Wait for driver to become READY.
bool waitForReadyOrDraining(u32 timeoutMs=1000) FL_NO_EXCEPT
static bool isAnyNetworkActive() FL_NO_EXCEPT
Task executor — runs registered task runners and manages the run loop.
#define FL_ERROR(...)
Definition log.h:373
Centralized logging categories for FastLED hardware interfaces and subsystems.
fl::u32 getWaitSpinBudgetUs() FL_NO_EXCEPT
Get the current tiered-wait spin budget (microseconds).
void yield_system(fl::u32 microseconds) FL_NO_EXCEPT
OS-level yield only: same behavior as run(us, ExecFlags::SYSTEM).
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
fl::u32 micros() FL_NO_EXCEPT
Universal microsecond timer - returns microseconds since system startup.
Base definition for an LED controller.
Definition crgb.hpp:179
Cross-platform facade for runtime network activity detection.
@ READY
Hardware idle; ready to accept new transmissions.
Definition driver.h:170
@ DRAINING
All channels submitted; still transmitting.
Definition driver.h:172
Runtime-tunable microsecond spin budget for the channel-manager and driver wait loops (Phase 1 of #28...