Page 1 of 1

Api usage in IRAM_ATTR interrupts

Posted: Thu Feb 07, 2019 1:22 am
by taruroy
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?

Re: Api usage in IRAM_ATTR interrupts

Posted: Thu Feb 07, 2019 4:24 am
by ESP_Angus
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).

Re: Api usage in IRAM_ATTR interrupts

Posted: Thu Feb 07, 2019 5:28 am
by taruroy
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.

Re: Api usage in IRAM_ATTR interrupts

Posted: Sat Feb 09, 2019 10:40 am
by ESP_Sprite
FreeRTOS APIs are an exception, as FreeRTOS at the moment is integrally loaded into IRAM; you can safely call those functions.