Porting ARM Cortex M code

ammaree
Posts: 33
Joined: Tue Dec 27, 2016 2:10 am

Porting ARM Cortex M code

Postby ammaree » Thu Feb 16, 2017 3:55 pm

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?

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

Re: Porting ARM Cortex M code

Postby ESP_Sprite » Tue Feb 21, 2017 3:15 am

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.

ammaree
Posts: 33
Joined: Tue Dec 27, 2016 2:10 am

Re: Porting ARM Cortex M code

Postby ammaree » Tue Feb 21, 2017 8:07 pm

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

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

Re: Porting ARM Cortex M code

Postby ESP_Sprite » Wed Feb 22, 2017 2:22 am

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: No registered users and 96 guests