22
22
#include "esp_attr.h"
23
23
#include "esp_intr.h"
24
24
25
- #define HWTIMER_INUM 10
26
25
#define HWTIMER_LOCK () portENTER_CRITICAL(timer->lock)
27
26
#define HWTIMER_UNLOCK () portEXIT_CRITICAL(timer->lock)
28
27
@@ -220,7 +219,10 @@ void timerEnd(hw_timer_t *timer){
220
219
221
220
void timerAttachInterrupt (hw_timer_t * timer , void (* fn )(void ), bool edge ){
222
221
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
+ }
224
226
if (fn == NULL ){
225
227
timer -> dev -> config .level_int_en = 0 ;
226
228
timer -> dev -> config .edge_int_en = 0 ;
@@ -232,10 +234,6 @@ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
232
234
}
233
235
__timerInterruptHandlers [timer -> num ] = NULL ;
234
236
} else {
235
- if (!initialized ){
236
- xt_set_interrupt_handler (HWTIMER_INUM , & __timerISR , NULL );
237
- initialized = true;
238
- }
239
237
__timerInterruptHandlers [timer -> num ] = fn ;
240
238
timer -> dev -> config .level_int_en = edge ?0 :1 ;//When set, an alarm will generate a level type interrupt.
241
239
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){
253
251
intr_source = ETS_TG0_T0_EDGE_INTR_SOURCE + timer -> timer ;
254
252
}
255
253
}
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
+ }
257
260
if (timer -> group ){
258
261
TIMERG1 .int_ena .val |= BIT (timer -> timer );
259
262
} else {
260
263
TIMERG0 .int_ena .val |= BIT (timer -> timer );
261
264
}
262
265
}
263
- ESP_INTR_ENABLE (HWTIMER_INUM );
266
+ if (intr_handle ){
267
+ esp_intr_enable (intr_handle );
268
+ }
264
269
}
265
270
266
271
void timerDetachInterrupt (hw_timer_t * timer ){
0 commit comments