INtime SDK Help
SetRtInterruptHandler
INtime SDK v7 > About INtime > INtime Kernel > Interrupts > SetRtInterruptHandler

Assigns an interrupt handler to the specified interrupt level, and optionally makes the calling thread the interrupt thread for that level. It is not necessary for the handler to have a thread.

BOOLEAN SetRtInterruptHandler(
  WORD wLevel,
  BYTE byMaxInt,
  LPPROC lpfnHandler,
);

Parameters

wLevel
Specifies the interrupt level to which the handler is to be assigned.
byMaxInt
Interrupt flags. If 0 is specified then no interrupt thread is to be associated with this handler, in other words the handler will never call SignalRtInterruptThread. If a non-0 value is specified then this is the number of outstanding SignalRtInterruptThread requests that can exist. When this limit is reached the interrupt is disabled. The maximum value possible is 255.
lpfnHandler
Pointer to the interrupt handler.

Remarks

The number of outstanding SignalRtInterruptThread requests that the handler can make before the associated interrupt level is disabled generally corresponds to the number of buffers used by the handler and interrupt thread.

If the byMaxInt parameter is non-zero, then the calling thread becomes the interrupt thread.

The interrupt handler has this general form:

__INTERRUPT void InterruptHandler(void)
{ // TODO: any local variables are declared here. __INTERRUPT_PROLOG(); // Before EnterRtInterrupt the data segment cannot be used, // so we have to obtain the level dynamically. EnterRtInterrupt(GetRtInterruptLevel()); // Interrupt handling statements __INTERRUPT_RETURN(); }

Note that any pointer to a variable on the stack in the interrupt handler cannot be dereferenced. This is because the interrupt handler runs in a privileged context which makes it impossible for the compiler to generate a correct stack-based address. Any attempt to do so will result in a page fault.

To uninstall an interrupt handler call ResetRtInterruptHandler. If a handler has an associated interrupt thread then an implicit call to ResetRtInterruptHandler is made on exit from the current process. If there is no interrupt thread then an explicit call to ResetRtInterruptHandler must be made before process termination. Failure to do so can cause system instability.

Return Values

TRUE
Success
FALSE
To determine the status, call GetLastRtError

Status

E_OK 0000
No exceptional conditions occurred.
E_LIMIT 0x0004
Both of these conditions exist:
  • byMaxInt contains a value other than 0 (zero).
  • The interrupt level has an associated priority which is greater (numerically less) than the maximum allowed by the calling thread's process. See SetRtProcessMaxPriority.
E_CONTEXT 0x0005
One of these conditions exist:
  • The thread is already an interrupt thread.
  • The specified level already has an interrupt handler assigned.
  • The process that contains the calling thread or the calling thread itself is being deleted.
E_PARAM 0x8004
One or more of these conditions exist:
  • wLevel is invalid.
  • The hardware configuration does not include a PIC for the specified level.
E_BAD_ADDR 0x800F
The pointer to the interrupt handler is invalid. One of these conditions exist:
  • All or part of the interrupt handler is outside the calling thread's virtual address space.
  • The virtual address space has no associated physical memory.

Requirements

Versions Defined in Include Link to
INtime 3.0 intime/rt/include/rtbase.h rt.h rt.lib
See Also

Processes