From 611f39f3687e3c399ed0aec6d5b81d58a83da647 Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Wed, 17 Sep 2025 15:03:18 +0300 Subject: [PATCH] feat(esp_timer): esp_timer_is_active while callback is running --- components/esp_timer/src/esp_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index 3d28fb7af58..023c92e8246 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -38,6 +38,7 @@ typedef enum { FL_ISR_DISPATCH_METHOD = (1 << 0), //!< 0=Callback is called from timer task, 1=Callback is called from timer ISR FL_SKIP_UNHANDLED_EVENTS = (1 << 1), //!< 0=NOT skip unhandled events for periodic timers, 1=Skip unhandled events for periodic timers + FL_CALLBACK_IS_RUNNING = (1 << 2), //!< 0=Callback is NOT running, 1=Callback is running } flags_t; struct esp_timer { @@ -409,6 +410,7 @@ static bool timer_process_alarm(esp_timer_dispatch_t dispatch_method) free(it); it = NULL; } else { + it->flags |= FL_CALLBACK_IS_RUNNING; if (it->period > 0) { int skipped = (now - it->alarm) / it->period; if ((it->flags & FL_SKIP_UNHANDLED_EVENTS) && (skipped > 1)) { @@ -434,6 +436,7 @@ static bool timer_process_alarm(esp_timer_dispatch_t dispatch_method) timer_list_unlock(dispatch_method); (*callback)(arg); timer_list_lock(dispatch_method); + it->flags &= ~FL_CALLBACK_IS_RUNNING; #if WITH_PROFILING it->times_triggered++; it->total_callback_run_time += esp_timer_impl_get_time() - callback_start; @@ -764,5 +767,5 @@ bool IRAM_ATTR esp_timer_is_active(esp_timer_handle_t timer) if (timer == NULL) { return false; } - return timer_armed(timer); + return timer_armed(timer) || (timer->flags & FL_CALLBACK_IS_RUNNING); }