disable and enable gpio interrupt core problem

eliet52
Posts: 4
Joined: Fri May 03, 2019 9:51 am

disable and enable gpio interrupt core problem

Postby eliet52 » Mon Jun 03, 2019 1:51 pm

Hi, I have a problem concerning the gpio_intr_disbale and gpio_intr_enable functions.
It seems that sometimes, after diabling some gpio interruption, the enable function doesn't work and doesn't use the right core to reactivate, even if both functions are called within the same task and have the same context.
Do you have any solutions or raised issues about this problematic behavior?
Thank you!!!
Elie :roll:

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: disable and enable gpio interrupt core problem

Postby ESP_Sprite » Tue Jun 04, 2019 1:02 am

Do you have a code example that shows this behaviour?

eliet52
Posts: 4
Joined: Fri May 03, 2019 9:51 am

Re: disable and enable gpio interrupt core problem

Postby eliet52 » Tue Jun 04, 2019 12:22 pm

I put some parts of my code below. As you can see, the disable and enable isr functions are called within the same context, in the push_btn task. However, as I said earlier, the gpio_intr_enable function doesn't work after pushing the button a random number of times. The issue seems to be that the enable function is called on the wrong core. Thanks for your help :D
  1. void IRAM_ATTR push_btn_isr_handler()
  2. {
  3.     if (!push_btn_intr_disabled) {
  4.         sensor_evt_t evt = SENSOR_EVT_HIGH;
  5.         xQueueSendFromISR(push_btn_evt_queue, &evt, NULL);
  6.         /* lock interruption */
  7.         push_btn_intr_disabled = true;
  8.     }
  9. }
  10.  
  11. static void manage_push_btn_release(push_btn_state_t state)
  12. {
  13.     switch (state) {
  14.     case SHORT_PRESS_STATE:
  15.         /* increment counter and send data */
  16.         push_btn_cnt++;
  17.         ESP_ERROR_CHECK(gpio_intr_enable(PUSH_BTN_PIN));
  18.         break;
  19.     case ...
  20.     }
  21. }
  22.  
  23. void push_btn(void* arg)
  24. {
  25.     push_btn_evt_t evt = SENSOR_EVT_NONE;
  26.     push_btn_state_t state = NONE;
  27.  
  28.     /* create the push_btn_timer for debounce purpose */
  29.     const esp_timer_create_args_t push_btn_args = { .callback = &push_btn_timer_callback };
  30.     ESP_ERROR_CHECK(esp_timer_create(&push_btn_args, &push_btn_timer));
  31.  
  32.     /* gpio isr init */
  33.     gpio_install_isr_service(0);
  34.     if (gpio_isr_handler_add(PUSH_BTN_PIN, push_btn_isr_handler, (void*)PUSH_BTN_PIN) != ESP_OK) {
  35.         gpio_isr_handler_remove(PUSH_BTN_PIN);
  36.         gpio_isr_handler_add(PUSH_BTN_PIN, push_btn_isr_handler, (void*)PUSH_BTN_PIN);
  37.     }
  38.  
  39.     for (;;) {
  40.         if (xQueueReceive(push_btn_evt_queue, &evt, portMAX_DELAY)) {
  41.             switch ((int)evt) {
  42.             case SENSOR_EVT_HIGH:
  43.                 ESP_ERROR_CHECK(gpio_intr_disable(PUSH_BTN_PIN));
  44.                 push_btn_intr_disabled = false;
  45.                 state = SHORT_PRESS_STATE;
  46.                 /* start periodic timer to trigger push button events */
  47.                 ESP_ERROR_CHECK(esp_timer_start_periodic(push_btn_timer, POLLING_PERIOD_MS * 1000));
  48.                 break;
  49.             case SENSOR_EVT_LOW:
  50.                 /* manage app behaviour depending on press duration */
  51.                 manage_push_btn_release(state);
  52.                 state = NONE;
  53.                 break;
  54.             case ...
  55.             }
  56.         }
  57.     }
  58. }
Elie :roll:

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: disable and enable gpio interrupt core problem

Postby ESP_Sprite » Wed Jun 05, 2019 3:06 am

How do you create the push_btn task? Could it be that you're not pinning it to one particular core? Because if you don't, whatever core has free time will run it.

eliet52
Posts: 4
Joined: Fri May 03, 2019 9:51 am

Re: disable and enable gpio interrupt core problem

Postby eliet52 » Wed Jun 05, 2019 6:38 am

In another c file (application.c), I do this:
  1. void application_init(void)
  2. {
  3.     push_btn_evt_queue = xQueueCreate(5, sizeof(uint8_t));
  4.     xTaskCreate(push_btn, "push_btn", 4096, NULL, CONFIG_APP_PUSH_BTN_PRIORITY, NULL);
  5. }
Elie :roll:

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: disable and enable gpio interrupt core problem

Postby ESP_Sprite » Wed Jun 05, 2019 7:18 am

Gotcha. xTaskCreate creates an unpinned task, which as I said above will execute on any core that has free time. Try xTaskCreatePinnedToCore instead.

eliet52
Posts: 4
Joined: Fri May 03, 2019 9:51 am

Re: disable and enable gpio interrupt core problem

Postby eliet52 » Wed Jun 05, 2019 7:40 am

Thanks a lot it works!!!
Elie :roll:

Who is online

Users browsing this forum: No registered users and 144 guests