Revert Timer Interrupt setup

This commit is contained in:
me-no-dev 2017-09-28 18:22:35 +08:00
parent 6d98555658
commit 17ece1bccd

View File

@ -65,7 +65,7 @@ static hw_timer_t hw_timer[4] = {
}; };
typedef void (*voidFuncPtr)(void); typedef void (*voidFuncPtr)(void);
static voidFuncPtr __timerInterruptHandlers[4] = {0,}; static voidFuncPtr __timerInterruptHandlers[4] = {0,0,0,0};
void IRAM_ATTR __timerISR(void * arg){ void IRAM_ATTR __timerISR(void * arg){
uint32_t s0 = TIMERG0.int_st_timers.val; uint32_t s0 = TIMERG0.int_st_timers.val;
@ -84,13 +84,11 @@ void IRAM_ATTR __timerISR(void * arg){
i = 4; i = 4;
//call callbacks //call callbacks
while(i--){ while(i--){
if(status & (1 << i)){ if(__timerInterruptHandlers[i] && status & (1 << i)){
if(__timerInterruptHandlers[i]){
__timerInterruptHandlers[i](); __timerInterruptHandlers[i]();
} }
} }
} }
}
uint64_t timerRead(hw_timer_t *timer){ uint64_t timerRead(hw_timer_t *timer){
timer->dev->update = 1; timer->dev->update = 1;
@ -186,8 +184,6 @@ bool timerAlarmEnabled(hw_timer_t *timer){
return timer->dev->config.alarm_en; return timer->dev->config.alarm_en;
} }
hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){ hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp){
if(num > 3){ if(num > 3){
return NULL; return NULL;
@ -217,12 +213,14 @@ void timerEnd(hw_timer_t *timer){
timerAttachInterrupt(timer, NULL, false); timerAttachInterrupt(timer, NULL, false);
} }
#define HWTIMER_INUM 10
void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){
static bool initialized = false; static bool initialized = false;
static intr_handle_t intr_handle = NULL; //static intr_handle_t intr_handle = NULL;
if(intr_handle){ //if(intr_handle){
esp_intr_disable(intr_handle); // esp_intr_disable(intr_handle);
} //}
ESP_INTR_DISABLE(HWTIMER_INUM);
if(fn == NULL){ if(fn == NULL){
timer->dev->config.level_int_en = 0; timer->dev->config.level_int_en = 0;
timer->dev->config.edge_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){ if(!initialized){
initialized = true; initialized = true;
esp_intr_alloc(intr_source, (int)ESP_INTR_FLAG_IRAM, __timerISR, NULL, &intr_handle); xt_set_interrupt_handler(HWTIMER_INUM, &__timerISR, NULL);
} else { //esp_intr_alloc(intr_source, (int)ESP_INTR_FLAG_IRAM, __timerISR, NULL, &intr_handle);
intr_matrix_set(esp_intr_get_cpu(intr_handle), intr_source, esp_intr_get_intno(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){ if(timer->group){
TIMERG1.int_ena.val |= BIT(timer->timer); TIMERG1.int_ena.val |= BIT(timer->timer);
} else { } else {
TIMERG0.int_ena.val |= BIT(timer->timer); TIMERG0.int_ena.val |= BIT(timer->timer);
} }
} }
if(intr_handle){ //if(intr_handle){
esp_intr_enable(intr_handle); // esp_intr_enable(intr_handle);
} //}
ESP_INTR_ENABLE(HWTIMER_INUM);
} }
void timerDetachInterrupt(hw_timer_t *timer){ void timerDetachInterrupt(hw_timer_t *timer){