Training
×

Sample Interrupt Handler

Here is an example of the code for an interrupt handler. Since Visual Studio has no option to generate interrupt handler code, this must be done by _asm statements, and the _declspec (naked) control. To get an idea of the required prolog and epilog, let the INtime Application wizard generate an interrupt handler for you, and read the code and comments.
An interrupt handler does not execute in the same context as an INtime thread: instead, it runs in ring 0 (i.e., less protection!) and has all interrupts disabled.
You cannot debug an interrupt handler with Spider or Visual Studio. You must use the System Debug Monitor with a separate terminal.
To make coding an interrupt handler a bit easier, the include files contain a number of macro definitions: __INTERRUPT, __INTERRUPT_PROLOG, __INTERRUPT_RETURN, __SHARED_INTERRUPT_PROLOG, __SHARED_INTERRUPT_RETURN. See the include and help files for details.
 
EnterRtInterrupt(LEVEL) sets the execution context to that of the process which "owns" the interrupt handler. Specifically, it sets the data segment to that of the process so that process data may be accessed from the interrupt handler.
While LEVEL can be a constant, the programmer should determine the actual interrupt level by calling GetRtInterruptLevel.