Skip to content

Commit 6d98555

Browse files
committed
Change timer interrupt allocator
1 parent f9b2d42 commit 6d98555

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

cores/esp32/esp32-hal-timer.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "esp_attr.h"
2323
#include "esp_intr.h"
2424

25-
#define HWTIMER_INUM 10
2625
#define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock)
2726
#define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock)
2827

@@ -220,7 +219,10 @@ void timerEnd(hw_timer_t *timer){
220219

221220
void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
222221
static bool initialized = false;
223-
ESP_INTR_DISABLE(HWTIMER_INUM);
222+
static intr_handle_t intr_handle = NULL;
223+
if(intr_handle){
224+
esp_intr_disable(intr_handle);
225+
}
224226
if(fn == NULL){
225227
timer->dev->config.level_int_en = 0;
226228
timer->dev->config.edge_int_en = 0;
@@ -232,10 +234,6 @@ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
232234
}
233235
__timerInterruptHandlers[timer->num] = NULL;
234236
} else {
235-
if(!initialized){
236-
xt_set_interrupt_handler(HWTIMER_INUM, &__timerISR, NULL);
237-
initialized = true;
238-
}
239237
__timerInterruptHandlers[timer->num] = fn;
240238
timer->dev->config.level_int_en = edge?0:1;//When set, an alarm will generate a level type interrupt.
241239
timer->dev->config.edge_int_en = edge?1:0;//When set, an alarm will generate an edge type interrupt.
@@ -253,14 +251,21 @@ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
253251
intr_source = ETS_TG0_T0_EDGE_INTR_SOURCE + timer->timer;
254252
}
255253
}
256-
intr_matrix_set(xPortGetCoreID(), intr_source, HWTIMER_INUM);
254+
if(!initialized){
255+
initialized = true;
256+
esp_intr_alloc(intr_source, (int)ESP_INTR_FLAG_IRAM, __timerISR, NULL, &intr_handle);
257+
} else {
258+
intr_matrix_set(esp_intr_get_cpu(intr_handle), intr_source, esp_intr_get_intno(intr_handle));
259+
}
257260
if(timer->group){
258261
TIMERG1.int_ena.val |= BIT(timer->timer);
259262
} else {
260263
TIMERG0.int_ena.val |= BIT(timer->timer);
261264
}
262265
}
263-
ESP_INTR_ENABLE(HWTIMER_INUM);
266+
if(intr_handle){
267+
esp_intr_enable(intr_handle);
268+
}
264269
}
265270

266271
void timerDetachInterrupt(hw_timer_t *timer){

0 commit comments

Comments
 (0)