5.4 Instructions for After and Instead Type User Interrupts

The user must tell Universal Driver to run the user's function when interrupts occur, and select either "after" or "instead" operating mode:
DSCUSERINTFUNCTION dscuserintfunction;
dscuserintfunction.func = (DSCUserInterruptFunction) MyUserInterruptFunction;
dscuserintfunction.int_mode = USER_INT_AFTER;
// or dscuserintfunction.int_mode = USER_INT_INSTEAD;
dscSetUserInterruptFunction(boardhandle, &dscuserintfunction);
Once dscSetUserInterruptFunction is called, the driver will know to use the user's interrupt function for all subsequent interrupt operations on the specified board that are initiated by the currently running program.
Now, to make use of the user interrupt function, you must call one of the many driver functions that use interrupts (dscADSampleInt, dscADScanInt, dscDAConvertScanInt, dscUserInt, etc.)
The user interrupt function will run only when interrupts occur. If the interrupt function terminates (for example if dscADSampleInt running in one-shot mode completes, or if dscCancelOp is called), then the user interrupt function will stop running as well.
To disable the user's interrupt function, you have two options:
A. Call dscSetUserInterruptFunction to cancel:
  • Set dscuserint.func = NULL.
  • Set dscuserint.int_mode = DSC_USER_INT_CANCEL.
  • Call dscSetUserInterrupt() again.
The example code below illustrates these 3 steps:
DSCUSERINTFUNCTION dscuserintfunction;
dscuserintfunction.func = NULL;
dscuserintfunction.int_mode = USER_INT_CANCEL;
dscSetUserInterruptFunction(boardhandle, &dscuserintfunction);
B. Call DscClearUserInterruptFunction:
If you try to clear the user interrupt function (using either method) while an "instead" interrupt routine is actively running, you will receive an error and the function will not be cleared. You are only allowed to clear an "after" interrupt function while the routine is running.
When the user calls one of these interrupt enabling functions, the behavior of the user interrupt function is determined by the "int_mode" parameter in the DSCUSERINTFUNCTION structure.
If USER_INT_AFTER is used, then the user's function will be called every time the standard kernel-mode interrupt routine breaks to user-mode, as described above.
If USER_INT_INSTEAD is used, then the user's function will completely bypass the kernel-mode routine. Instead, every interrupt request will directly call the user's interrupt function, and will not perform any internal board upkeep. For this reason, if the user is using "instead" user interrupt functions in an A/D interrupt mode, the user interrupt function must perform all necessary upkeep (reset the interrupt flipflop, checking/reseting overflow, reading data from the FIFO, etc.). This mode should only be used if you are extremely familiar with the board's operation and interrupt requirements.