From 0688ef09f13a3c7915b86246292d077c783989a0 Mon Sep 17 00:00:00 2001 From: "U-AndyHPNB2\\Andy" Date: Wed, 9 Jun 2021 00:23:16 +0200 Subject: [PATCH] fix issues in hw_timer --- components/esp8266/driver/hw_timer.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/components/esp8266/driver/hw_timer.c b/components/esp8266/driver/hw_timer.c index e3eb26dd9..c54670b49 100644 --- a/components/esp8266/driver/hw_timer.c +++ b/components/esp8266/driver/hw_timer.c @@ -159,10 +159,20 @@ uint32_t hw_timer_get_count_data() return frc1.count.data; } -static void IRAM_ATTR hw_timer_isr_cb(void* arg) -{ - if (!frc1.ctrl.reload) { - frc1.ctrl.en = 0; +static void IRAM_ATTR hw_timer_isr_cb(void *arg) +{ + typeof ( ((frc1_struct_t*)0)->ctrl) ctrl; + ctrl.val = frc1.ctrl.val; + if (!ctrl.reload) { + ctrl.en = 0; + frc1.ctrl.val = ctrl.val; //stop counter + /* frc1.count.val == 0 causes continuous fire even with the timer disabled. + * We force an immediate reload to avoid that*/ + uint32_t val = frc1.load.val; //split to suppress a warning + frc1.load.val= val; + /* Clear the interrupt just in case the timer fired again. + * This might occur even in case of interrupt latencies */ + soc_clear_int_mask(1ul << (ETS_FRC_TIMER1_INUM)); } if (hw_timer_obj->cb != NULL) { hw_timer_obj->cb(arg); @@ -242,4 +252,4 @@ esp_err_t hw_timer_init(hw_timer_callback_t callback, void *arg) hw_timer_intr_enable(); return ESP_OK; -} \ No newline at end of file +}