home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name issetisr -- Install C-TOOLS-2-style interrupt service
- * routine.
- * (Formerly called PCSETISR.)
- *
- * Synopsis ercode = issetisr(intype,pfunc,stksize,pvector,ppisrblk);
- *
- * int ercode Error return code
- * unsigned (*pfunc)()
- * Pointer to interrupt service routine
- * int intype Interrupt type number (0 to 255)
- * int stksize Stack size (in bytes) needed for ISR
- * (at least 128)
- * ADS *pvector Previous interrupt vector for the
- * specified interrupt type.
- * ISRCTRL **ppisrblk
- * Address of pointer to ISR control block
- *
- * Description ISINSTAL installs a C-TOOLS-2-style interrupt service
- * routine (ISR) in the interrupt vector of the specified
- * type. This includes (1) allocating an ISR control block
- * and setting its values; (2) arranging for ISCT2INT to
- * pass control to the ISR; (3) storing the address of the
- * ISR control block in the interrupt vector.
- *
- * The ISR is in effect (and may be invoked) as soon as
- * operation (3) is complete, i.e., even before ISSETISR
- * returns to its caller.
- *
- * The calling function must first use ISISRSTK (formerly
- * called PCISRSTK) to allocate space to be used for the
- * ISR's stack.
- *
- * The previous value of the interrupt vector is returned
- * in the ADS structure pointed to by pvector. This may be
- * used to restore the previous handling of this type of
- * interrupt.
- *
- * The address of the ISR control block is returned in
- * *ppisrblk. The space occupied by the control block may
- * be freed after the ISR is no longer in use (see example
- * below).
- *
- * ISISRSTK and ISSETISR provide compatibility with ISRs
- * built with C TOOLS 2. Newer programs should use
- * ISINSTAL instead.
- *
- * Limitations Since C TOOLS 2 ISRs were not re-entrant, only one level
- * of call is allowed to ISRs installed by ISSETISR. If
- * the ISR is called while it is already executing, the
- * second call just returns without taking any action.
- *
- * ISISRSTK allocates a pool of space to all C TOOLS 2
- * ISRs. Under C TOOLS 2 this space was used dynamically
- * by all ISRs. Now under C TOOLS PLUS each ISR installed
- * by ISSETISR is allocated a fixed section of that pool.
- * Therefore this pool must contain enough space for all
- * ISRs installed by ISSETISR or ercode will be returned
- * with a value of 3.
- *
- * Example The following code fragment illustrates one way to
- * declare the arguments to ISSETISR, to use ISSETVEC to
- * restore the contents of the interrupt vector when the
- * ISR is no longer in use, and to free the space allocated
- * to the control block.
- *
- * #include <bisr.h>
- * #if LAT300
- * #include <stdlib.h>
- * #endif
- * #if MSC300
- * #include <malloc.h>
- * #include <process.h>
- * #endif
- *
- * #define MY_INTYPE 0x60
- * #define MY_STK_SIZE 2000
- *
- * unsigned my_isr(void);
- * ISRCTRL *pisrblk;
- * ADS prev_vector;
- *
- * if (isisrstk(MY_STK_SIZE))
- * exit(4);
- *
- * if (issetisr(MY_INTYPE,my_isr,MY_STK_SIZE,
- * &prev_vector,&pisrblk))
- * exit(5);
- *
- * ....... (Use the ISR.)
- *
- * issetvec(intype,&prev_vector);
- * free((char *) pisrblk);
- *
- * Returns ercode The return code is 0 if the vector is
- * is successfully set; other values are:
- * 1 - Interrupt type out of range
- * 2 - Cannot allocate space for ISR control
- * block
- * 3 - Insufficient stack space allocated
- * by ISISRSTK
- * *pvector Previous contents of interrupt vector
- * *ppisrblk Address of ISR control block
- * b_istksize The size (in bytes) of the remaining
- * stack space for C TOOLS 2 ISRs.
- * b_isrpstk Pointer to next available stack space.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bisr.h>
-
- #if LAT300
- #include <stdlib.h>
- #endif
- #if MSC300
- #include <malloc.h>
- #endif
-
- #define OK 0 /* Error return codes */
- #define BAD_INTYPE 1
- #define NO_HEAP_LEFT 2
- #define NO_STACKS_LEFT 3
-
- int issetisr(intype,pfunc,stksize,pvector,ppisrblk)
- int intype;
- unsigned (*pfunc)();
- int stksize;
- ADS *pvector;
- ISRCTRL **ppisrblk;
- {
- extern void isct2int(); /* Interface routine for */
- /* C-TOOLS-2-style ISRs. */
- int result;
-
- if (isretvec(intype,pvector)) /* Fetch previous value of */
- return BAD_INTYPE; /* interrupt vector. */
-
- if (b_istksize < stksize) /* Make sure there's enough */
- return NO_STACKS_LEFT; /* space for this ISR's stack. */
-
- /* Create the control block. */
- if (NIL == (*ppisrblk = utalloc(ISRCTRL)))
- return NO_HEAP_LEFT;
-
- /* Address of the ISR itself. */
- utcodptr(pfunc,&(*ppisrblk)->ct2_isr);
-
- /* Install the ISR. */
- result = isinstal(intype,
- isct2int,
- CT2ISR_IDENT,
- *ppisrblk,
- b_isrpstk,
- stksize,
- 1);
-
- if (result == 0) /* If successfully installed, */
- { /* record change in available */
- b_istksize -= stksize; /* stack area. */
- b_isrpstk += stksize;
- }
-
- return result;
- }