FastLED 3.9.15
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) {
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
63bool IChannelDriver::waitForReady(u32 timeoutMs) {
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 waitForReadyOrDraining(u32 timeoutMs=1000) FL_NOEXCEPT
bool waitForCondition(Condition condition, u32 timeoutMs=1000) FL_NOEXCEPT
bool waitForReady(u32 timeoutMs=1000) FL_NOEXCEPT
Wait for driver to become READY.
virtual DriverState poll() FL_NOEXCEPT=0
Query driver state and perform maintenance.
static bool isAnyNetworkActive() FL_NOEXCEPT
Task executor — runs registered task runners and manages the run loop.
#define FL_ERROR(X)
Definition log.h:219
Centralized logging categories for FastLED hardware interfaces and subsystems.
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.
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:167
@ DRAINING
All channels submitted; still transmitting.
Definition driver.h:169
Runtime-tunable microsecond spin budget for the channel-manager and driver wait loops (Phase 1 of #28...