user10037: I'm working with Arduino's libraries. And my interest in the possibility to change the call stack of the SPI interrupt, this because I want: after the interrupt happen, the program could jump to other function and not to the interrupted address.
I mean:
This is the Main code.
void loop ()
{
    func();
}

void func()
{
   // code
   // here happens the ISR interrupt
}

ISR happens inside func()
ISR(SPI_STC_vect)
{
    // code
    // SPDR = 0x00; // MY ANSWER to SPI
    // MODIFY CALL STACK TO GO TO LOOP()
}

Now, after answering the SPI, I want to go back to loop() instead of continue func().
How can I do this?
Thanks for your help.

user-1: Arduino is open source, so just modify the ISR to set a global flag when ran. Within func() just check for this flag and return when the condition is met. Little can be offered as little contextual information is given. To modify the stack you would have to work with avr assembly, but either way you must modify the ISR
Something like the following would work, but performance depends heavily on your application. 
#define SPI_ISR_RAN 0x00
static volatile uint8_t flagByte;

void loop(){
    func();
}

void func(){
    uint8_t indicator;
    do {
        // Do something

        //Check for SPI condition
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ //Atomic access is required
            indicator = flagByte;
        }
    }while( !(indicator & 1<<SPI_ISR_RAN) );

    ATOMIC_BLOCK(ATOMIC_RESTORESTATE){
        flagByte &= ~(1<<SPI_ISR_RAN); //Don't forget to clear the flag!
    }
}

ISR(SPI_STC_vect){
    // Do ISR necessities

    // Set flag when appropriate            
    flagByte & 1<<SPI_ISR_RAN;            
}    


10037: <p>I'm working with Arduino's libraries. And my interest in the possibility to change the call stack of the SPI interrupt, this because I want: after the interrupt happen, the program could jump to other function and not to the interrupted address.</p>

<p>I mean:
This is the Main code.</p>

<pre><code>void loop ()
{
    func();
}

void func()
{
   // code
   // here happens the ISR interrupt
}
</code></pre>

<p>ISR happens inside <code>func()</code></p>

<pre><code>ISR(SPI_STC_vect)
{
    // code
    // SPDR = 0x00; // MY ANSWER to SPI
    // MODIFY CALL STACK TO GO TO LOOP()
}
</code></pre>

<p><strong>Now, after answering the SPI, I want to go back to <code>loop()</code> instead of continue <code>func()</code>.</strong></p>

<p><strong>How can I do this?</strong></p>

<p>Thanks for your help.</p>
 -1: <p>Arduino is open source, so just modify the ISR to set a global flag when ran. Within func() just check for this flag and return when the condition is met. Little can be offered as little contextual information is given. To modify the stack you would have to work with avr assembly, but either way you must modify the ISR</p>

<p>Something like the following would work, but performance depends heavily on your application. </p>

<pre><code>#define SPI_ISR_RAN 0x00
static volatile uint8_t flagByte;

void loop(){
    func();
}

void func(){
    uint8_t indicator;
    do {
        // Do something

        //Check for SPI condition
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ //Atomic access is required
            indicator = flagByte;
        }
    }while( !(indicator &amp; 1&lt;&lt;SPI_ISR_RAN) );

    ATOMIC_BLOCK(ATOMIC_RESTORESTATE){
        flagByte &amp;= ~(1&lt;&lt;SPI_ISR_RAN); //Don't forget to clear the flag!
    }
}

ISR(SPI_STC_vect){
    // Do ISR necessities

    // Set flag when appropriate            
    flagByte &amp; 1&lt;&lt;SPI_ISR_RAN;            
}    
</code></pre>
