How do I write my own ISRs (Interrupt Service Routines) and can I call an interrupt function from another function?
Cosmic includes and easy-to use extension to the ANSI standard C to support interrupt service routines (ISR). The @interrupt type qualifier is used to mark a function as an ISR. A function declared with the @interrupt is suitable for direct connection to a hardware or software interrupt. An @interrupt function may not return any value, but are allowed to have arguments, although hardware generated interrupts are not likely to supply anything meaningful. When you define an @interrupt function, the compiler uses the appropriate return from interrupt sequence in place of the return from function sequence. e.g. The compiler will push and pull any information that needs to be saved on interrupt and return via an rti instruction. You define an @interrupt function by using the type qualifier @interrupt to qualify the type returned by the function you declare. An example of such a definition is:
@interrupt void foo(void)
Cosmic compilers also allow you to call an @interrupt function directly from a C function. The compiler will simulate an interrupt stack frame before jumping into the interrupt function in order to allow the rti instruction to return properly.