FastLED 3.9.15
Loading...
Searching...
No Matches

◆ waitForCondition()

template<typename Condition>
bool fl::IChannelDriver::waitForCondition ( Condition condition,
u32 timeoutMs = 1000 )
protected

Definition at line 13 of file driver.cpp.hpp.

13 {
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}
static bool isAnyNetworkActive() FL_NOEXCEPT
#define FL_ERROR(X)
Definition log.h:219
fl::u32 getWaitSpinBudgetUs() FL_NOEXCEPT
Get the current tiered-wait spin budget (microseconds).
void run(fl::u32 microseconds, ExecFlags flags)
Run selected task subsystems.
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
fl::u32 micros()
Universal microsecond timer - returns microseconds since system startup.

References FL_ERROR, fl::detail::getWaitSpinBudgetUs(), fl::net::NetworkDetector::isAnyNetworkActive(), fl::micros(), fl::millis(), fl::task::run(), and fl::task::SYSTEM.

Referenced by operator=(), waitForReady(), and waitForReadyOrDraining().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: