Page 1 of 1

Can't disable Timer interrupt

Posted: Fri Apr 10, 2020 1:04 am
by francis2
Hey,
So I followed the implementation of timer interrupt (https://github.com/espressif/esp-idf/bl ... ple_main.c ). It worked perfectly but now I want to disable and then re enable the interuption caused by Group 0 Timer 1 's alarm, and I can't seem to disable the interrupt.

This is the timer's config and init
  1. void timerGrp0Init(int timer_idx, double timer_interval_sec){
  2.     /* Select and initialize basic parameters of the timer */
  3.     timer_config_t config;
  4.     config.divider = TIMER_DIVIDER;
  5.     config.counter_dir = TIMER_COUNT_UP;
  6.     config.counter_en = TIMER_PAUSE;
  7.     config.alarm_en = TIMER_ALARM_EN;
  8.     config.intr_type = TIMER_INTR_LEVEL;
  9.     config.auto_reload = 1;
  10. #ifdef TIMER_GROUP_SUPPORTS_XTAL_CLOCK
  11.     config.clk_src = TIMER_SRC_CLK_APB;
  12. #endif
  13.     timer_init(TIMER_GROUP_0, timer_idx, &config);
  14.  
  15.     /* Timer's counter will initially start from value below.
  16.        Also, if auto_reload is set, this value will be automatically reload on alarm */
  17.     timer_set_counter_value(TIMER_GROUP_0, timer_idx, 0x00000000ULL);
  18.  
  19.     /* Configure the alarm value and the interrupt on alarm. */
  20.     timer_set_alarm_value(TIMER_GROUP_0, timer_idx, timer_interval_sec * TIMER_SCALE);
  21.     timer_enable_intr(TIMER_GROUP_0, timer_idx);
  22.     timer_isr_register(TIMER_GROUP_0, timer_idx, timerGrp0Isr, (void*)timer_idx, ESP_INTR_FLAG_IRAM, NULL);
  23.  
  24.     timer_start(TIMER_GROUP_0, timer_idx);
  25. }
This is the ISR:
  1. void IRAM_ATTR timerGrp0Isr(void *para){                            //This interrupt is handled by CPU1
  2.     int timer_idx = (int)para;
  3.     timer_spinlock_take(TIMER_GROUP_0);
  4.  
  5.     //Wake acqAdc2 in order to start ADC readings from adc2. CPU0 will start immediatly acquiring
  6.     vTaskNotifyGiveFromISR(acquiring_2_task, (BaseType_t*)NULL);
  7.  
  8.     //Wake acqAdc1 in order to start ADC readings form adc1. This will only start when this handler is terminated.
  9.     vTaskNotifyGiveFromISR(acquiring_1_task, (BaseType_t*)NULL);
  10.  
  11.     //Clear the interrupt
  12.     timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, timer_idx);
  13.  
  14.     //After the alarm has been triggered we need enable it again, so it is triggered the next time
  15.     timer_group_enable_alarm_in_isr(TIMER_GROUP_0, timer_idx);
  16.  
  17.     timer_spinlock_give(TIMER_GROUP_0);
  18. }
And then, when acquiring_1_task receives the notification, it immediately disables the interrupt like so:
  1. void acqAdc1(){
  2.     //Init Timer 0_1 (timer 1 from group 0) and register it's interupt handler
  3.     timerGrp0Init(TIMER_1, TIMER1_INTERVAL_SEC);
  4.  
  5.     //Config all possible adc channels
  6.     configSixAdcChannels(ADC_RESOLUTION);
  7.  
  8.     while(1){
  9.         if(ulTaskNotifyTake(pdTRUE, ONE_HOUR_MS/portTICK_PERIOD_MS ) == 1){     //THIS IS WHERE THE TASK RECIEVES THE NOTIFICATION
  10.            
  11.  
  12.             if(timer_disable_intr(TIMER_GROUP_0, 1) == ESP_OK){
  13.                 printf("Disable ok\n");
  14.             }
  15.  
  16.             //TODO clear acq_config.adc1_num_channels
  17.         }else{
  18.             DEBUG_PRINT(W, "acqAdc1", "ulTaskNotifyTake timed out!");
  19.         }
  20.     }
  21. }
The thing is, I keep getting periodically the interruption after the disable has been made, does someone know what I'm doing wrong?

Thanks in advance