mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
feat(esp_timer): esp_timer_is_active while callback is running
This commit is contained in:
committed by
guozifan
parent
d51737a36d
commit
bebb748360
@@ -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 {
|
||||
@@ -412,6 +413,7 @@ static __attribute__((noinline, noclone)) bool timer_process_alarm(esp_timer_dis
|
||||
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)) {
|
||||
@@ -437,6 +439,7 @@ static __attribute__((noinline, noclone)) bool timer_process_alarm(esp_timer_dis
|
||||
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;
|
||||
@@ -773,5 +776,5 @@ bool ESP_TIMER_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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user