sleeping system with multiple interrupts

Ok guys, i got another one. My code is setup to execute the main loop once and go to sleep. I want the system to wake up via 3 external interrupts.

INT0 ->external wake up timer to run main loop again INT1 ->wake up and increment a counter (active low from IR gate) INT2 ->Wake up and process data available in the SPI bus

I know that this means that ill need another external interrupt pin, so i will enable digital pin 4 as an interrupt pin.

THe question is how do i wake up, service an interrupt, and go back to sleep? Do i put sleep_mode(); in the ISR? I guess my problem is that i do not have a good grasp of the program flow when sleep is implemented. Thanks!

Do i put sleep_mode(); in the ISR?

No. Return from the ISR as you would without the sleep.

After the ISR returns, execution resumes after the sleep. Simply loop and go back to sleep.

After the ISR returns, execution resumes after the sleep.

I do not want it to execute the main loop again until the external timer interrupt is triggered...but im worried that it is to long to be the ISR for that interrupt so i kept it in main.

I am following the logic of the ArduinoSleepCode in the Playground. In the WakeUp ISR it says "execute code here after wake-up before returning to the loop() function"... but i just want it to go back to sleep after the ISR is serviced for interrupts not related to the external timer.

I just thought of this...but it seems crude. Is this a good solution? The timer interrupt will trigger every 5 min. However, all other interrupts are completely asyncronus. Is there no way to get out of having to run the loop again after an interrupt? Is it even an issue if it does? Im going for max power effeciency here.

volitile boolean alarm = 0;

setup()
{
  attachInterrupt(0, WakeUp, FALLING);
  attachInterrupt(1, otherISR2, FALLING);
  attachInterrupt(2, otherISR3, FALLING);
}

void WakeUp()
{
  alarm=1;
}
void otherISR2()
{
  //ISR Code
}
void otherISR3()
{
  //ISR Code
}

loop()
{
  if(alarm)
  {
    //meat of main loop code
  }
  putToSleep();  
}

Is this a good solution?

Yes.

Is there no way to get out of having to run the loop again after an interrupt?

It is pointless to try. The extremely tiny amount of energy saved is not worth the dramatically more complex code.

Is it even an issue if it does?

No.

Im going for max power effeciency here.

Your time is better spent learning to turn things off (like the analog comparator) and learning to use deeper sleep modes.

attachInterrupt(2, otherISR3, FALLING);

Only two external interrupts (zero and one) are supported. You will have to use a pin-change interrupt for the third source.

Sounds good! I will give that a try. Thanks for the input!