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!!!
disable and enable gpio interrupt core problem
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: disable and enable gpio interrupt core problem
Do you have a code example that shows this behaviour?
Re: disable and enable gpio interrupt core problem
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
- void IRAM_ATTR push_btn_isr_handler()
- {
- if (!push_btn_intr_disabled) {
- sensor_evt_t evt = SENSOR_EVT_HIGH;
- xQueueSendFromISR(push_btn_evt_queue, &evt, NULL);
- /* lock interruption */
- push_btn_intr_disabled = true;
- }
- }
- static void manage_push_btn_release(push_btn_state_t state)
- {
- switch (state) {
- case SHORT_PRESS_STATE:
- /* increment counter and send data */
- push_btn_cnt++;
- ESP_ERROR_CHECK(gpio_intr_enable(PUSH_BTN_PIN));
- break;
- case ...
- }
- }
- void push_btn(void* arg)
- {
- push_btn_evt_t evt = SENSOR_EVT_NONE;
- push_btn_state_t state = NONE;
- /* create the push_btn_timer for debounce purpose */
- const esp_timer_create_args_t push_btn_args = { .callback = &push_btn_timer_callback };
- ESP_ERROR_CHECK(esp_timer_create(&push_btn_args, &push_btn_timer));
- /* gpio isr init */
- gpio_install_isr_service(0);
- if (gpio_isr_handler_add(PUSH_BTN_PIN, push_btn_isr_handler, (void*)PUSH_BTN_PIN) != ESP_OK) {
- gpio_isr_handler_remove(PUSH_BTN_PIN);
- gpio_isr_handler_add(PUSH_BTN_PIN, push_btn_isr_handler, (void*)PUSH_BTN_PIN);
- }
- for (;;) {
- if (xQueueReceive(push_btn_evt_queue, &evt, portMAX_DELAY)) {
- switch ((int)evt) {
- case SENSOR_EVT_HIGH:
- ESP_ERROR_CHECK(gpio_intr_disable(PUSH_BTN_PIN));
- push_btn_intr_disabled = false;
- state = SHORT_PRESS_STATE;
- /* start periodic timer to trigger push button events */
- ESP_ERROR_CHECK(esp_timer_start_periodic(push_btn_timer, POLLING_PERIOD_MS * 1000));
- break;
- case SENSOR_EVT_LOW:
- /* manage app behaviour depending on press duration */
- manage_push_btn_release(state);
- state = NONE;
- break;
- case ...
- }
- }
- }
- }
Elie
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: disable and enable gpio interrupt core problem
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.
Re: disable and enable gpio interrupt core problem
In another c file (application.c), I do this:
- void application_init(void)
- {
- push_btn_evt_queue = xQueueCreate(5, sizeof(uint8_t));
- xTaskCreate(push_btn, "push_btn", 4096, NULL, CONFIG_APP_PUSH_BTN_PRIORITY, NULL);
- }
Elie
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: disable and enable gpio interrupt core problem
Gotcha. xTaskCreate creates an unpinned task, which as I said above will execute on any core that has free time. Try xTaskCreatePinnedToCore instead.
Who is online
Users browsing this forum: Google [Bot] and 170 guests