mirror of
https://github.com/esphome/esphome.git
synced 2026-09-14 00:28:39 +00:00
Tighten millis() fast-path comments
This commit is contained in:
@@ -16,19 +16,15 @@ void loop();
|
||||
namespace esphome {
|
||||
|
||||
void HOT yield() { ::yield(); }
|
||||
// Skip the Arduino core's ::millis() wrapper so the public esphome::millis() is
|
||||
// inlinable at its call sites and matches MillisInternal::get()'s fast path.
|
||||
// Inline the tick read so esphome::millis() matches MillisInternal::get()'s fast
|
||||
// path instead of going through the Arduino core's out-of-line ::millis() wrapper.
|
||||
//
|
||||
// RTL87xx and LN882x run FreeRTOS at 1 kHz, so xTaskGetTickCount() is already in
|
||||
// milliseconds. IRAM_ATTR is kept on those families because components (e.g.
|
||||
// rotary_encoder) call millis() from ISR handlers, and in ISR context millis()
|
||||
// dispatches to xTaskGetTickCountFromISR() to satisfy the FreeRTOS API contract.
|
||||
// RTL87xx / LN882x (1 kHz): xTaskGetTickCount() is already ms. IRAM_ATTR + ISR
|
||||
// dispatch are needed because ISR handlers (e.g. rotary_encoder) call millis().
|
||||
//
|
||||
// BK72xx runs FreeRTOS at 500 Hz — multiply by portTICK_PERIOD_MS (== 2) to convert
|
||||
// ticks to milliseconds, matching the Arduino core's wiring.c. IRAM_ATTR is a no-op
|
||||
// on BK72xx (see hal.h): the SDK masks FIQ + IRQ at the CPU around every flash
|
||||
// operation, so no ISR runs while flash is stalled and IRAM placement is unnecessary.
|
||||
// BK72xx therefore also skips the ISR dispatch, matching the Arduino core.
|
||||
// BK72xx (500 Hz): ticks * portTICK_PERIOD_MS (== 2). IRAM_ATTR and ISR dispatch
|
||||
// are both unnecessary — the SDK masks FIQ + IRQ during flash writes (see hal.h),
|
||||
// so no ISR runs while flash is stalled.
|
||||
#if defined(USE_RTL87XX) || defined(USE_LN882X)
|
||||
uint32_t IRAM_ATTR HOT millis() {
|
||||
static_assert(configTICK_RATE_HZ == 1000, "millis() fast path requires 1 kHz FreeRTOS tick");
|
||||
|
||||
@@ -36,19 +36,13 @@ class MillisInternal {
|
||||
#if defined(USE_ESP32) && CONFIG_FREERTOS_HZ == 1000
|
||||
return xTaskGetTickCount();
|
||||
#elif defined(USE_LIBRETINY) && (defined(USE_RTL87XX) || defined(USE_LN882X))
|
||||
// RTL87xx and LN882x run FreeRTOS at 1 kHz, so xTaskGetTickCount() is
|
||||
// already in milliseconds.
|
||||
// 1 kHz: xTaskGetTickCount() is already ms.
|
||||
static_assert(configTICK_RATE_HZ == 1000, "MillisInternal fast path requires 1 kHz FreeRTOS tick");
|
||||
return xTaskGetTickCount();
|
||||
#elif defined(USE_BK72XX)
|
||||
// BK72xx runs FreeRTOS at 500 Hz; scale ticks by portTICK_PERIOD_MS (== 2).
|
||||
// Inlined here because esphome::millis() on BK72xx is out-of-line (its
|
||||
// IRAM_ATTR is a no-op — see hal.h — because the BK72xx SDK wraps flash
|
||||
// operations in GLOBAL_INT_DISABLE() which masks FIQ + IRQ at the CPU for
|
||||
// the duration of every write, so no ISR runs while flash is stalled and
|
||||
// IRAM placement / FromISR dispatch are both unnecessary). Calling the
|
||||
// out-of-line esphome::millis() would still cost a real function call,
|
||||
// which this inlined path avoids.
|
||||
// 500 Hz: scale by portTICK_PERIOD_MS (== 2). Inlined to avoid the
|
||||
// out-of-line call to esphome::millis() (IRAM_ATTR is a no-op on BK72xx —
|
||||
// SDK masks FIQ + IRQ during flash writes, see hal.h).
|
||||
static_assert(configTICK_RATE_HZ == 500, "BK72xx MillisInternal assumes 500 Hz FreeRTOS tick");
|
||||
return xTaskGetTickCount() * portTICK_PERIOD_MS;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user