ARM Cortex M4: test from unpriviledged mode if inside interrupt

1.8k Views Asked by At

I am working with the following CPU: Stellaris LM4F120H5QR Microcontroller. This CPU contains a MPU and I want to utalize this thing. But a lot of registers are no longer accessable when inside unpriviliged mode and I cannot seem to find a register which indicates that the system is inside an interrupt and is readable from unpriviliged mode.

I need this because there is code that might take a different route when called from an interrupt. If I do a wrong check from unprivileged mode, the system will immedeatly jump to access fault.

So how can I check if a function is called from an interrupt in a way that will not create a fault when called from unprivileged mode?

1

There are 1 best solutions below

2
On

According to ARM's documentation the CONTROL and ISR registers might be just what you need.

So, using the CMSIS prototypes, the code might look like:

if (__get_IPSR() || !(__get_CONTROL() & 0x1)) 
{
   /* Privilged code */
}
else
{
   /* Unprivileged code */
}

As far as I know, reading those should be allowed even to a user thread.