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?
Porting ARM Cortex M code
-
- Posts: 9758
- Joined: Thu Nov 26, 2015 4:08 am
Re: Porting ARM Cortex M code
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
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
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
-
- Posts: 9758
- Joined: Thu Nov 26, 2015 4:08 am
Re: Porting ARM Cortex M code
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?
Who is online
Users browsing this forum: ESP_Sprite and 177 guests