chipKIT® Development Platform

Inspired by Arduino™

Fast interrupt handling for waking from idle wait

Created Tue, 13 Nov 2012 06:44:48 +0000 by chrisbillington


Tue, 13 Nov 2012 06:44:48 +0000


I'm working on a project on a Chipkit Max32 that requires that the microcontroller wait until triggered by an external digital edge. It is important that the latency of this interrupt is reliably always the same duration, and to a lesser degree, that it is fast. Ideally I'd like to out-spec another device which has 250ns latency :p.

I'm using MPIDE, but am happy to modify the MPIDE libraries if it helps, my code does not need to be portable.

Having disabled all interrupts except mine, I've got it working reliably, but the lowest I've been able to get the latency to is 660 ns or so. The thing is, I don't actually want to execute an interrupt handler. I just want to resume from the "wait" assembly instruction. So I'm copping all this overhead of the CPU jumping to the interrupt vector, seeing that it's a goto statement, and jumping to the handler defined in WInterrupts.c, where presumably the interrupt prologue and epilogue execute also.

I got rid of some of the register-copying overhead by modifying WInterrupts.c to use priority level 7 for my interrupt, but that only chopped things down a little bit. I also ensured that the interrupt handler in WInterrupts.c isn't doing anything except clearing the interrupt flag - it's not calling a user interrupt handler like you normally get using attachInterrupt().

Ideally I'd like to put a single "eret" instruction in the interrupt vector table for external interrupt 0. That would be marvellous...anyone know how I might do that?

I tried:

#include <plib.h>
void __ISR_AT_VECTOR(_EXTERNAL_0_VECTOR, ipl7)ExtInt0Handler(void){asm ("eret");}

But I get "function at exception vector 3 too large" from the linker when I compile. I suppose I could increase the vector spacing, but it looks like the 32 byte spacing is fairly set in, and is not just a matter of changing a variable in the linker script. Also "eret" ought to be four bytes, I'm assuming the above macro is still inserting a prologue and epilogue that I don't want or need.

So yeah, anyone know how to write "eret" to the vector table in the right spot? Or any other suggestions?