Page 1 of 1

Porting ARM Cortex M code

Posted: Thu Feb 16, 2017 3:55 pm
by ammaree
I am trying to port some code from the ARM Cortex M3/4 environment and need to determine whether a function is called from an application/thread or ISR context. Currently I am reading the SCB.ICSR.VECTACTIVE value to determine this since a value > 0 will provide the ISR number.

Is there a similar mechanism in the ESP32 that can be used?

Re: Porting ARM Cortex M code

Posted: Tue Feb 21, 2017 3:15 am
by ESP_Sprite
Are you using this in the standard esp-idf environment? In esp-idf, you could check the port_interruptNesting[xPortGetCoreID()] variable for non-zero-ness. It's defined in freertos/port.c, but not nicely exported, unfortunately. I'll think of a nicer way to get this information, it can be useful in general.

Re: Porting ARM Cortex M code

Posted: Tue Feb 21, 2017 8:07 pm
by ammaree
Yes, I am using this in a "standard" esp-idf environment.

In the Cortex-M environment the VECTACTIVE field provides info on whether executing in task context (return 0) or ISR context (return 1 -> 3FF) with the value returned being a direct reference to the IRQ being serviced.

Just getting a 0=task or 1=ISR value will already be of value but ultimately it would be of far greater value if the value returned (0 to 69) is directly related to the PRO_INTR_STATUS_REG_0/1/2 values. That is assuming that only a single bit in these registers can/will be set at any moment.

Maybe a function similar to xTaskGetContext(uint32_t CpuID) and by default to doing the xPortGetCoreID() call if the CpuID supplied is zero.

Thanks

Andre

Re: Porting ARM Cortex M code

Posted: Wed Feb 22, 2017 2:22 am
by ESP_Sprite
You are aware of the fact that you can pass an argument to your interrupt handler when you set it up, right? (The 'void *arg' argument in esp_intr_alloc; the same argument will be fed into the installed interrupt handler.) Maybe you can use that to figure out what interrupt you're called from?