I would like to know how to check if CPU is in IRQ handler routine. I see from technical reference manual that there is CPSR register which has 8 bit reserved for specifying current cpu mode but unfortunately in FreeRTOS CortexA9 port FreeRTOS_IRQ_Handler I can see that during IRQ handling cpu mode is being switched to Supervisor mode hence there is no possibility to use CPSR. Any ideas how to work out this problem ?
Temporarily I turned off switching to SVC mode during IRQ handling but I suspect this is not good idea…
I’m sure there will be a way, but I would have to get the A9
architecture manual out to see, and I think you would need to look at
the GIC (interrupt controller) registers, not the CPU registers. I’m
pretty sure from memory there is a GIC register that tells you the
priority you are running at. As a quick and dirty solution, as there is
a single IRQ entry point, you could edit the IRQ entry code to increment
an interrupt nesting count on entry and decrement the count on exit -
then if the count is greater than 0 you know you are in the IRQ.
If you don’t switch to SVC mode then the system will crash if interrupts
nest.