FastLED 3.10.10
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
13 return config.isDefault() || configureWorkerImpl(config);
14}
15
21
25
27
28bool IChannelDriver::waitForState(bool allowDraining, u32 timeoutMs) FL_NO_EXCEPT {
29 const auto condition = [this, allowDraining]() {
30 const auto state = poll().state;
32 (allowDraining && state == IChannelDriver::DriverState::DRAINING);
33 };
34 const u32 startTime = timeoutMs > 0 ? millis() : 0;
35
36 // Tier 1: instant non-blocking check.
37 if (condition()) {
38 return true;
39 }
40
41 // Tier 2: bounded microsecond spin (#2818). Catches short DMA tails
42 // without paying the >=1-tick floor below. Budget runtime-tunable via
43 // FastLED.setWaitSpinBudgetUs(N); 0 disables.
44 {
45 const u32 spinBudget = fl::detail::getWaitSpinBudgetUs();
46 if (spinBudget > 0) {
47 const u32 spinStart = fl::micros();
48 while ((fl::micros() - spinStart) < spinBudget) {
49 if (condition()) {
50 return true;
51 }
52 if (timeoutMs > 0 && (millis() - startTime) >= timeoutMs) {
53 FL_ERROR("Timeout occurred while waiting for condition");
54 return false;
55 }
56 }
57 }
58 }
59
60 while (!condition()) {
61 // Check timeout if specified
62 if (timeoutMs > 0 && (millis() - startTime >= timeoutMs)) {
63 FL_ERROR("Timeout occurred while waiting for condition");
64 return false; // Timeout occurred
65 }
66
67 // Adaptive yield (refs #2815, generalizes the #2493 ESP32-P4 carve-out):
68 // see the matching comment in ChannelManager::waitForState for the
69 // full rationale. The deep yield is only needed when a radio is
70 // actually up; otherwise the FreeRTOS tick floor is pure timing drift.
72 // Radio active: keep WiFi/lwIP/BT alive with the deep yield.
74 } else {
75 // No radio: fast yield, no FreeRTOS tick floor.
77 }
78 }
79
80 return true; // Condition met
81}
82
84 // wait until the driver is in a READY state.
85 bool ok = waitForState(false, timeoutMs);
86 return ok;
87}
88
90 // wait until the driver is in a READY or DRAINING state.
91 bool ok = waitForState(true, timeoutMs);
92 return ok;
93}
94
95} // namespace fl
TestState state
FastLED chrono implementation - duration types for time measurements.
bool configureWorker(const WorkerConfig &config) FL_NO_EXCEPT
Configure shared worker settings before transmission.
void fillWorkerDiagnostics(WorkerDiagnostics &) const FL_NO_EXCEPT
FL_NO_INLINE bool waitForState(bool allowDraining, u32 timeoutMs) FL_NO_EXCEPT
bool configureWorkerImpl(const WorkerConfig &) FL_NO_EXCEPT
WorkerDiagnostics workerDiagnostics() const FL_NO_EXCEPT
Snapshot worker evidence after serializing with transmission completion.
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.
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Base definition for an LED controller.
Worker scheduling evidence.
Cross-platform facade for runtime network activity detection.
@ READY
Hardware idle; ready to accept new transmissions.
Definition driver.h:171
@ DRAINING
All channels submitted; still transmitting.
Definition driver.h:173
Shared engine settings, configured before the first transmission.
Runtime-tunable microsecond spin budget for the channel-manager and driver wait loops (Phase 1 of #28...