mirror of
https://github.com/esphome/esphome.git
synced 2026-02-23 17:58:23 -07:00
[core] Use constexpr for compile-time constants (#14071)
This commit is contained in:
@@ -111,7 +111,7 @@ namespace esphome {
|
||||
// For reboots, it's more important to shut down quickly than disconnect cleanly
|
||||
// since we're not entering deep sleep. The only consequence of not shutting down
|
||||
// cleanly is a warning in the log.
|
||||
static const uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000; // 1 second for quick reboot
|
||||
static constexpr uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000; // 1 second for quick reboot
|
||||
|
||||
class Application {
|
||||
public:
|
||||
|
||||
@@ -846,9 +846,9 @@ void IRAM_ATTR HOT delay_microseconds_safe(uint32_t us) {
|
||||
// avoids CPU locks that could trigger WDT or affect WiFi/BT stability
|
||||
uint32_t start = micros();
|
||||
|
||||
const uint32_t lag = 5000; // microseconds, specifies the maximum time for a CPU busy-loop.
|
||||
// it must be larger than the worst-case duration of a delay(1) call (hardware tasks)
|
||||
// 5ms is conservative, it could be reduced when exact BT/WiFi stack delays are known
|
||||
constexpr uint32_t lag = 5000; // microseconds, specifies the maximum time for a CPU busy-loop.
|
||||
// it must be larger than the worst-case duration of a delay(1) call (hardware tasks)
|
||||
// 5ms is conservative, it could be reduced when exact BT/WiFi stack delays are known
|
||||
if (us > lag) {
|
||||
delay((us - lag) / 1000UL); // note: in disabled-interrupt contexts delay() won't actually sleep
|
||||
while (micros() - start < us - lag)
|
||||
|
||||
@@ -728,7 +728,7 @@ uint64_t Scheduler::millis_64_(uint32_t now) {
|
||||
|
||||
// Define a safe window around the rollover point (10 seconds)
|
||||
// This covers any reasonable scheduler delays or thread preemption
|
||||
static const uint32_t ROLLOVER_WINDOW = 10000; // 10 seconds in milliseconds
|
||||
static constexpr uint32_t ROLLOVER_WINDOW = 10000; // 10 seconds in milliseconds
|
||||
|
||||
// Check if we're near the rollover boundary (close to std::numeric_limits<uint32_t>::max() or just past 0)
|
||||
bool near_rollover = (last > (std::numeric_limits<uint32_t>::max() - ROLLOVER_WINDOW)) || (now < ROLLOVER_WINDOW);
|
||||
|
||||
Reference in New Issue
Block a user