PIC32MX Port Interrupts question

spawner wrote on Monday, January 17, 2011:

I downloaded the FreeRTOS port and I made a simple interrupt driven UART. While looking through the example I noticed that the demo defines an InterruptHandler and an InterruptWrapper. The wrapper is declared as an interrupt like this void __attribute__( (interrupt(ipl2), vector(_UART1_VECTOR))) vU1InterruptWrapper( void ); and is defined in a .S file like this:

    .set        noreorder
    .set         noat
    .ent        vU1InterruptWrapper


    jal vU1InterruptHandler

    .end        vU1InterruptWrapper

The InterruptHandler is a regular function ( void vU1InterruptHandler(void) ). As far as I know, the compiler generates prologue and epilogue for functions with the interrupt attribute (there is an attribute which tells him not to) and I’m worried that what I’m actually getting here, is saving the context twice, and restoring it twice.
Any thoughts?

rtel wrote on Monday, January 17, 2011:

I’m not quite following your question here.

The wrapper is an assembly function, so not compiled at all and will therefore not have a compiler generated prologue or epilogue sequence.  The FreeRTOS provided prologue/epilogue in the portSAVE_CONTEXT() and portRESTORE_CONTEXT() macros switches the stack to an interrupt stack to save RAM (each task does not need to have a stack large enough to handle all the nested interrupts).

The function vU1InterruptHandler is just a standard function.  The prologue generated for that will be much smaller than that generated for an interrupt function written in C, and will use the interrupt stack, not the task stack.

Hopefully I will have answered your question but I’m not sure.  In any case, if you want to know what is being saved and restored by the compiler just look at the code it generates.