From 45ee699eaeb54d528d44ecd4cc119b757bf8fd01 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Wed, 12 May 2021 14:00:58 +0800 Subject: [PATCH] driver/timer: only re-enable alarm in callback when auto reload is true closes https://github.com/espressif/esp-idf/issues/7001 --- components/driver/timer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/driver/timer.c b/components/driver/timer.c index 5dee417725e..63027481f5d 100644 --- a/components/driver/timer.c +++ b/components/driver/timer.c @@ -216,8 +216,12 @@ static void IRAM_ATTR timer_isr_default(void *arg) is_awoken = timer_obj->timer_isr_fun.fn(timer_obj->timer_isr_fun.args); //Clear intrrupt status timer_hal_clear_intr_status(&(timer_obj->hal)); - //After the alarm has been triggered, we need enable it again, so it is triggered the next time. - timer_hal_set_alarm_enable(&(timer_obj->hal), TIMER_ALARM_EN); + //If the timer is set to auto reload, we need enable it again, so it is triggered the next time. + if (timer_hal_get_auto_reload(&timer_obj->hal)) { + timer_hal_set_alarm_enable(&(timer_obj->hal), TIMER_ALARM_EN); + } else { + timer_hal_set_alarm_enable(&(timer_obj->hal), TIMER_ALARM_DIS); + } } } TIMER_EXIT_CRITICAL(&timer_spinlock[timer_obj->timer_isr_fun.isr_timer_group]);