'Switch context' on interrupt

Hi all,

I'm experimenting with multitasking on the Arduino. I've looked around a lot and I decided I want to experiment a bit with interrupts. I'd like to switch between a few contexts based on a timer which generates interrupts.

The common way to handle interrupts with the Arduino sdk is: attachInterrupt(interrupt, function, mode) When function exits, the 'normal' context - the loop() - continues executing.

I wonder if I can determine the context at the moment the interrupt happens: The instruction pointer and stack, etc. That way, I could store that information and resume it at another time, much like the Arduino sdk already does when the interrupt function exits.

Thanks in advance!

Erik

It's not a project for the faint-hearted, and not one I'd recommend without some form of debugger or simulator.

You will have to save all 32 regs plus the PC and SREG and maybe other stuff and I'm not sure you have access to all you need from C as this means dicking around on the stack.

I'm 99% sure you will need to drop into assembler.

As AWOL says though, this is not for the faint-hearted.


Rob