00001 #ifndef __INTRS_H 00002 #define __INTRS_H 00003 00004 /**********************************************************/ 00005 /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/ 00006 /* 00007 Copyright: 1993 - Grupo de Voz (DAET) ETSII/IT-Bilbao 00008 00009 Nombre fuente................ INTRS.H 00010 Nombre paquete............... - 00011 Lenguaje fuente.............. C (Borland C/C++ 3.1) 00012 Estado....................... Completado 00013 Dependencia Hard/OS.......... Irqs, intrs 00014 Codigo condicional........... - 00015 00016 Codificacion................. Borja Etxebarria 00017 00018 Version dd/mm/aa Autor Proposito de la edicion 00019 ------- -------- -------- ----------------------- 00020 1.0.3 21/04/00 Borja INTERRUPT para djgpp 00021 1.0.2 18/02/96 Borja anyadir #include "tdef.h" 00022 1.0.1 26/07/94 Borja Soporte C y C++ para protot. rutina servicio. 00023 1.0.0 19/02/94 Borja Codificacion inicial. 00024 00025 ======================== Contenido ======================== 00026 Gestion de interrupciones y controlador de interrupciones. 00027 .................... 00028 Interrupt controller management macros. 00029 =========================================================== 00030 */ 00031 /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/ 00032 /**********************************************************/ 00033 00034 #include <dos.h> /* para enable(), disable()... */ 00035 00036 #include "tdef.h" 00037 #include "ports.h" 00038 00039 /**********************************************************/ 00040 /* keyword que identifica a una funcion como interrupcion */ 00041 00042 #ifdef __OS_MSDOS32__ 00043 #define INTERRUPT 00044 #else 00045 #define INTERRUPT interrupt 00046 #endif 00047 00048 /* tipo de las funciones de servicio de interrupcion */ 00049 #ifdef __cplusplus 00050 typedef VOID INTERRUPT (*IntrServiceFunc) ( ... ); 00051 #else 00052 typedef VOID INTERRUPT (*IntrServiceFunc) ( void ); 00053 #endif 00054 00055 /* habilitar y deshabilitar interrupciones. 00056 .................... 00057 enable and disable interrupts */ 00058 #define INT_ENABLE() _enable() 00059 #define INT_DISABLE() _disable() 00060 00061 /* {devuelve} (void interrupt far *) un puntero a la rutina de 00062 interrupcion que sirve la interrupcion numero {intno} (UINT16) 00063 .................... 00064 {returns} (void interrupt far *) a pointer to the interrupt 00065 service function for interrupt number {intno} (UINT16) */ 00066 #define INT_GET_VEC(intno) (IntrServiceFunc)_dos_getvect(intno) 00067 00068 /* pone la funcion {intfunc} (void interrupt far *) como rutina de 00069 servicio de la interrupcion numero {intno} (UINT16) 00070 .................... 00071 install the function {intfunc} (void interrupt far *) as an 00072 interrupt service function for interrupt number {intno} (UINT16) */ 00073 #define INT_SET_VEC(intno,intfunc) \ 00074 _dos_setvect(intno,(IntrServiceFunc)(intfunc)) 00075 00076 /**********************************************************/ 00077 /* {devuelve} en numero de interrupcion para la linea IRQ {irqn} 00078 {irqn} va de 0 a 15 00079 .................... 00080 {returns} the interrupt number for IRQ number {irqn}. 00081 0 <= {irqn} <=15 */ 00082 #define IRQ_INTN(irqn) ((irqn) + ((irqn < 8) ? 0x08 : 0x68)) 00083 00084 /* registros de programacion de los 2 PICs */ 00085 #define PIC1_REG0 0x20 00086 #define PIC1_REG1 0x21 00087 #define PIC2_REG0 0xA0 00088 #define PIC2_REG1 0xA1 00089 00090 #define PIC_EOI 0x20 00091 #define PIC_NOP 0x0B 00092 00093 /* envia fin de interrupcion al PIC, para la linea {irqn} (0 a 15) 00094 .................... 00095 Sends an EOI (end of interrupt) command to the PIC chip for 00096 IRQ interrupt number {irqn} (0 to 15) */ 00097 #define PIC_SEND_EOI(irqn) { \ 00098 if (irqn >= 8) { \ 00099 OUTPORT8(PIC2_REG0,PIC_EOI); \ 00100 OUTPORT8(PIC2_REG0,PIC_NOP); \ 00101 if (! INPORT8(PIC2_REG0)) \ 00102 OUTPORT8(PIC1_REG0,PIC_EOI); \ 00103 } \ 00104 else \ 00105 OUTPORT8(PIC1_REG0,PIC_EOI); \ 00106 } 00107 00108 /* conecta la linea IRQ numero {irqn} del PIC 00109 .................... 00110 enables (unmask) IRQ line {irqn} (0-15) */ 00111 #define PIC_ENABLE(irqn) { \ 00112 if (irqn<8) { \ 00113 INT_DISABLE(); \ 00114 OUTPORT8(PIC1_REG1, INPORT8(PIC1_REG1) & (~(0x01 << (irqn)))); \ 00115 INT_ENABLE(); \ 00116 } \ 00117 else { \ 00118 INT_DISABLE(); \ 00119 OUTPORT8(PIC2_REG1, INPORT8(PIC2_REG1) & (~(0x01 << ((irqn) - 8)))); \ 00120 INT_ENABLE(); \ 00121 } \ 00122 } 00123 00124 /* desconecta la linea IRQ numero {irqn} (0-15) del PIC 00125 .................... 00126 disables (masks) IRQ line {irqn} (0-15) */ 00127 #define PIC_DISABLE(irqn) { \ 00128 if (irqn<8) { \ 00129 INT_DISABLE(); \ 00130 OUTPORT8(PIC1_REG1, INPORT8(PIC1_REG1) | (0x01 << (irqn))); \ 00131 INT_ENABLE(); \ 00132 } \ 00133 else { \ 00134 INT_DISABLE(); \ 00135 OUTPORT8(PIC2_REG1, INPORT8(PIC2_REG1) | (0x01 << ((irqn) - 8))); \ 00136 INT_ENABLE(); \ 00137 } \ 00138 } 00139 00140 /**********************************************************/ 00141 00142 #endif