From 17ece1bccdd6c9dc671a6b0bfd66c0a642f75672 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 28 Sep 2017 18:22:35 +0800 Subject: [PATCH] Revert Timer Interrupt setup --- cores/esp32/esp32-hal-timer.c | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index a12199a9..88d94a9f 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -65,7 +65,7 @@ static hw_timer_t hw_timer[4] = { }; typedef void (*voidFuncPtr)(void); -static voidFuncPtr __timerInterruptHandlers[4] = {0,}; +static voidFuncPtr __timerInterruptHandlers[4] = {0,0,0,0}; void IRAM_ATTR __timerISR(void * arg){ uint32_t s0 = TIMERG0.int_st_timers.val; @@ -84,10 +84,8 @@ void IRAM_ATTR __timerISR(void * arg){ i = 4; //call callbacks while(i--){ - if(status & (1 << i)){ - if(__timerInterruptHandlers[i]){ - __timerInterruptHandlers[i](); - } + if(__timerInterruptHandlers[i] && status & (1 << i)){ + __timerInterruptHandlers[i](); } } } @@ -186,8 +184,6 @@ bool timerAlarmEnabled(hw_timer_t *timer){ return timer->dev->config.alarm_en; } - - hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){ if(num > 3){ return NULL; @@ -217,12 +213,14 @@ void timerEnd(hw_timer_t *timer){ timerAttachInterrupt(timer, NULL, false); } +#define HWTIMER_INUM 10 void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ static bool initialized = false; - static intr_handle_t intr_handle = NULL; - if(intr_handle){ - esp_intr_disable(intr_handle); - } + //static intr_handle_t intr_handle = NULL; + //if(intr_handle){ + // esp_intr_disable(intr_handle); + //} + ESP_INTR_DISABLE(HWTIMER_INUM); if(fn == NULL){ timer->dev->config.level_int_en = 0; timer->dev->config.edge_int_en = 0; @@ -253,19 +251,22 @@ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ } if(!initialized){ initialized = true; - esp_intr_alloc(intr_source, (int)ESP_INTR_FLAG_IRAM, __timerISR, NULL, &intr_handle); - } else { - intr_matrix_set(esp_intr_get_cpu(intr_handle), intr_source, esp_intr_get_intno(intr_handle)); - } + xt_set_interrupt_handler(HWTIMER_INUM, &__timerISR, NULL); + //esp_intr_alloc(intr_source, (int)ESP_INTR_FLAG_IRAM, __timerISR, NULL, &intr_handle); + }// else { + // intr_matrix_set(esp_intr_get_cpu(intr_handle), intr_source, esp_intr_get_intno(intr_handle)); + //} + intr_matrix_set(xPortGetCoreID(), intr_source, HWTIMER_INUM); if(timer->group){ TIMERG1.int_ena.val |= BIT(timer->timer); } else { TIMERG0.int_ena.val |= BIT(timer->timer); } } - if(intr_handle){ - esp_intr_enable(intr_handle); - } + //if(intr_handle){ + // esp_intr_enable(intr_handle); + //} + ESP_INTR_ENABLE(HWTIMER_INUM); } void timerDetachInterrupt(hw_timer_t *timer){