interrupt return address and other questions

23 Oct 2011

Hi there

I am new to CortexM3 and was wondering a few of things:

  • Is there are way of finding out the interrupt return address? Where is it in my stack?
  • Does the code in mbed run generally run in Thread mode (except in callbacks called from ISRs)?
  • Is it running in privileged mode when in thread mode, and if not is there some way already of escalating?
  • For a CortexM3 is checking whether IPSR/ISR_NUMBER is 0 an appropriate way to decide whether you are in ISR or not. Background here is that I'd like a irq_save_off/irq_restore_on type of API which only disables interrupts if you are not already in an ISR, eg in thread mode (admittedly I am ignoring faults here, but assuming that irqs are also off in fault mode). Assuming the method above was valid it would go something like this:

(naked functions)

int irq_save_off() 
{
  asm("mrs r0, ipsr ");
  asm("ldr r1,=#0x1ff");
  asm("ands r0,r0,r1");
  asm("it ne");
  asm("movne pc,lr");
  asm("cpsid i");
  asm("mov pc,lr");
}

void irq_restore_on()
{
  asm("ldr r1,=#0x1ff");
  asm("ands r0,r0,r1");
  asm("it ne");
  asm("movne pc,lr");
  asm("cpsie i");
  asm("mov pc,lr");
}

Any help really appreciated

Cheers

Charles