0

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?

artless noise
  • 21,212
  • 6
  • 68
  • 105
Cheiron
  • 3,620
  • 4
  • 32
  • 63

1 Answers1

1

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.

mash5
  • 124
  • 1
  • 4
  • According to that page both registers can only be access in privileged mode. Or am I misreading? – Cheiron Nov 05 '14 at 20:15
  • The ARM manual indeed indicates these registers as privileged, but reading from CONTROL, at least, should be also available in non-privileged mode. There's a sample in the "Definitive Guide to a Cortex M3" book, where this code is used in user thread context. – mash5 Nov 10 '14 at 09:52