/* Definiciones para control mediante puerto paralelo 2002 Víctor R. González */ #define TRUE 1 #define FALSE 0 /* Dirección E/S base del puerto seleccionado */ #define LPT_NUM 1 #define LPT_BASE _lpt_dir[LPT_NUM] /* Direcciones E/S de los registros del puerto estándar */ #define DATOS LPT_BASE #define ESTADO LPT_BASE + 1 #define CONTROL LPT_BASE + 2 /* Direcciones E/S de los primer y último registros adicionales del puerto EPP */ #define REG_EPP_PRI LPT_BASE + 3 #define REG_EPP_ULT LPT_BASE + 7 /* Direccion E/S del registro de control extendido (ECR) del puerto ECP */ #define CONTROL_EXT LPT_BASE + 0x402 /* Tipo de puerto */ #define LPT_NINGUNO 0 /* no hay puerto instalado */ #define LPT_SPP 1 /* puerto estándar */ #define LPT_BIDIR 2 /* puerto bidireccional */ #define LPT_EPP 3 /* puerto EPP */ #define LPT_ECP 4 /* puerto ECP */ #define LPT_OTROS -1 /* puerto desconocido */ /* Bits de CONTROL */ #define C0_ON 0x01 /* Bit 0 de CONTROL a 1 */ #define C2_ON 0x04 /* Bit 2 de CONTROL a 1 */ #define C5_ON 0x20 /* Bit 5 de CONTROL a 1 */ /* Bits de ESTADO */ #define S3_ON 0x08 /* Bit 3 de ESTADO a 1 */ /* Bits del ECR */ #define ECR5_ON 0x20 /* Bit 5 de ECR a 1 */ #define ECR6_ON 0x40 /* Bit 6 de ECR a 1 */ #define ECR7_ON 0x80 /* Bit 7 de ECR a 1 */ /* Contenedor de las direcciones E/S base de los puertos paralelo instalados */ unsigned int _lpt_dir[4]; unsigned int _lpt_tipo; /* tipo de puerto instalado */ #define LPT_TIPO _lpt_tipo unsigned char _control_valor, _estado_valor, _ECR_valor; /* Lectura de datos de los reg. de datos y de estado */ #define DATOS_lee() inportb(DATOS) #define ESTADO_lee() inportb(ESTADO) /* Escritura de datos a los reg. de datos y de control */ #define DATOS_fija(valor) outportb(DATOS, valor) #define CONTROL_fija(valor) outportb(CONTROL, valor) /* Toma el estado actual del reg. de control */ #define CONTROL_estad() (_control_valor = inportb (CONTROL)) /* Restaura el estado del reg. de control */ #define CONTROL_rest() outportb( CONTROL, _control_valor ) /* Toma el estado actual del reg. de control */ #define CONTROL_EXT_estad() (_ECR_valor = inportb (CONTROL_EXT)) /* Restaura el estado del reg. de control */ #define CONTROL_EXT_rest() outportb( CONTROL_EXT, _ECR_valor ) /* Pone C5 = 1 -bit 5 de CONTROL- (DATOS en modo entrada) */ #define DATOS_in() outportb (CONTROL, inportb (CONTROL) | C5_ON) /* Pone C5 = 0 -bit 5 de CONTROL- (DATOS en modo salida) */ #define DATOS_out() outportb (CONTROL, inportb (CONTROL) & (~C5_ON)) /* Fija el modo bidireccional compatible en puerto ECP bits ECR 765 = 001 */ #define ECP_bidir() outportb (CONTROL_EXT, inportb (CONTROL_EXT) | ECR5_ON | (~ECR6_ON) | (~ECR7_ON)) /* Activa colectores abiertos altos en CONTROL y deshabilita interrupciones */ #define CONTROL_in() (outportb(CONTROL, 0x04))