Programming Examples
Appendix B
B-28
ktx_int.c file
/***************************************************************************
**
** FILE – ktx_int.c
**
** This file contains a routine for initializing and enabling
** interrupts to service KTX interrupts and a routine that is a
** boilerplate for a KTX scanner interrupt service routine
**
***************************************************************************/
#include <dos.h>
#include <assert.h>
#include ”ktx_dp.h” /* 1784–KTX Scanner Dualport definition */
#include ”ktx_err.h” /* 1784–KTX Scanner error codes */
#include ”ktxconst.h” /* 1784–KTX Scanner constants */
#define LowPICPort 0x20
/* Port address for Prog. Interrupt Controller for ints 0–7 */
#define HighPICPort 0xA0
/* Port address for Prog. Interrupt Controller for ints 8–15 */
#define EOI 0x20
/* End Of Interrupt to PIC */
#define INT_PENDING_BIT 0x01
/* bit mask for interrupt pending bit in status register */
extern KTX_DUALPORT far *dp;
/* pointer to KTX’s dualport */
/***************************************************************************
**
** void Init_interrupt (unsigned char InterruptNumber, void interrupt
**
(*InterruptServiceRoutine)())
**
** This routine sets the interrupt vector and enables interrupts.
** The host passes in two parameters: the interrupt number and
** the interrupt service routine that will handle KTX interrupts.
** The interrupt number must match the interrupt number selected
** for this channel using the jumper on the KTX hardware.
**
** INPUTS
** KTX_DUALPORT far *dp – points to the base of the KTX dualport
** UBYTE trans_num – transaction_number
** USHORT timeout – time (in seconds) to wait for completion
**
** OUTPUT
** Interrupt Vector for KTX installed
**
***************************************************************************/
void interrupt (*OldInterruptServiceRoutine)(); /* pointer to store old interrupt handler */
void InitInterrupt(unsigned char InterruptNumber, void interrupt (*InterruptServiceRoutine)())
{
unsigned char
PICMask,
/* storage for prog. interrupt controller mask */
PICPortBase,
/* Port address of either first PIC or second PIC */
SWInterruptNumber;
/* Software Interrupt number, converted from HW */
/* Insure that InterruptNumber is valid one for KTX – leave in for debug only */
assert((InterruptNumber > 2) && (InterruptNumber < 16));
/* Set the base port of the Programmable Interrupt Controller depending on
whether the interrupt is on the first or second PIC */
if (InterruptNumber < 8) PICPortBase = LowPICPort;
else PICPortBase = HighPICPort;
/* Convert from hardware interrupt numbers (0–7) to software interrupt numbers
0x8–0xf and hardware interrupt numbers (8–15) to software interrupt
numbers 0x70–0x78 */