Api usage in IRAM_ATTR interrupts

taruroy
Posts: 3
Joined: Thu Feb 07, 2019 1:14 am

Api usage in IRAM_ATTR interrupts

Postby taruroy » Thu Feb 07, 2019 1:22 am

In one of the timer examples, the following is mentioned before an ISR definition:

* Note:
* We don't call the timer API here because they are not declared with IRAM_ATTR.
* If we're okay with the timer irq not being serviced while SPI flash cache is disabled,
* we can allocate this interrupt without the ESP_INTR_FLAG_IRAM flag and use the normal API.
*/
void IRAM_ATTR timer_group0_isr(void *para)

1) Does this mean that any ESP APIs that are not declared with IRAM_ATTR should never be used inside such ISRs? For e.g even many basic APIs such as esp_get_level, esp_set_level do not use the IRAM_ATTR attribute.
2) Same question for usage of user defined functions within these ISRs?

ESP_Angus
Posts: 1577
Joined: Sun May 08, 2016 4:11 am

Re: Api usage in IRAM_ATTR interrupts

Postby ESP_Angus » Thu Feb 07, 2019 4:24 am

For a full explanation, see here:
https://docs.espressif.com/projects/esp ... t-handlers

The short answer is:
  • The restriction of only calling functions in IRAM only applies if the ESP_INTR_FLAG_IRAM is provided when the interrupt is allocated via the esp_intr_alloc() function. If you don't set this flag, you can call any API from the ISR.
  • The downside of this is that during a flash write operation (ie NVS updating a value, or some other flash API which has to perform an erase or a write), processing of non-IRAM-safe interrupts is deferred until after the operation completes (which may be a few tens of milliseconds in the worst case).

taruroy
Posts: 3
Joined: Thu Feb 07, 2019 1:14 am

Re: Api usage in IRAM_ATTR interrupts

Postby taruroy » Thu Feb 07, 2019 5:28 am

Thanks for the reply.
My question was specific to interrupts allocated using ESP_INTR_FLAG_IRAM.
So it seems like even other important functions such as memset or more importantly xQueueSendToBackFromISR cannot be used?
If yes, this does seem to limit the functionality of such ISRs quite a bit.

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

Re: Api usage in IRAM_ATTR interrupts

Postby ESP_Sprite » Sat Feb 09, 2019 10:40 am

FreeRTOS APIs are an exception, as FreeRTOS at the moment is integrally loaded into IRAM; you can safely call those functions.

Who is online

Users browsing this forum: No registered users and 20 guests