Jump from ISR to task, timing problems

weedcuper
Posts: 1
Joined: Fri Jul 09, 2021 9:22 am

Jump from ISR to task, timing problems

Postby weedcuper » Fri Jul 09, 2021 9:38 am

Hey there!
I'am doing a quite simple project with ESP32 and can't handle some problem:
I have ISR handler:

Code: Select all

static void IRAM_ATTR gpio_isr_handler(void *arg)
{
    timer_get_counter_value(0, 0, &itr_time); /* fot count time */
    BaseType_t xReturn = pdFALSE;
    xSemaphoreGiveFromISR(xGPIOMutex, &xReturn);
     if (xReturn == pdTRUE)
     {
         portYIELD_FROM_ISR();
     }
}
And here it is a small part of my task which should handle xGPIOMutex mutex:

Code: Select all

void gpio_task(void *arg)
{
    TCA9535_Register last_data = {};
    while (1)
    {
            xSemaphoreTake(xGPIOMutex, portMAX_DELAY);
            {
                timer_get_counter_value(0,0, &task_time); 
                TCA9535ReadInput(&inputRegister);
	    }
    }	
When ISR occurs, I give mutex and switch context to my high priority task. Almost always it works great, about 400us to jump from ISR to task, but some times something happened and this process takes more then 3000us. Ofc I would fix it, but nothing come to my mind anyway.
This is how I create gpio_task (24 the highest priority in this project):

Code: Select all

xTaskCreate(&gpio_task, "gpio_task", 4096, NULL, 24, NULL);
Note that there are much more tasks and interrupts in this project.
And sorry for my eng :)

therealergo
Posts: 8
Joined: Wed Jun 30, 2021 6:16 pm

Re: Jump from ISR to task, timing problems

Postby therealergo » Mon Jul 12, 2021 5:15 pm

Are you using WiFi or Bluetooth or BLE? Those all create high-priority tasks on CPU 0.
You can try using xTaskCreatePinnedToCore to pin your gpio task to a specific core.

If you're using gpio_install_isr_service, you can also pass that ESP_INTR_FLAG_IRAM to ensure that your ISR is called when the cache is disabled.

Who is online

Users browsing this forum: No registered users and 74 guests