Vistas de página en total

Mostrando entradas con la etiqueta PioConfig. Mostrar todas las entradas
Mostrando entradas con la etiqueta PioConfig. Mostrar todas las entradas

lunes, 2 de diciembre de 2013

LIBRERÍA 48IOCENT

   
   Ya estamos listos para crear las funciones de control de la tarjera de 48 E/S. Esta librería la asociaremos a la general o crearemos una nueva para  nuestro hard.


    Dado que las funciones van asociadas al puerto paralelo, y dado que solo existe uno normalmente en los ordenadores, no defino dos puertos y trabajo directamente con el lpt1. Por eso en el programa trabajo directamente con las direcciones del puerto centronics, ya que crear variables y asignarlas a diferentes direcciones, creo que resulta un trabajo innecesario, dado el uso que haremos de las funciones.

    
48IOCENT.ASM
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/


;CONTROL DE ACCIONES SOBRE LOS 8255
;ESTAS VARIABLES MUEVEN ELAS SEÑALES DE CONTROL
;DE LOS BUFER Y LATCH DE LA TARJETA PARA ABRIR
;PASO A LOS DATOS DENTRO ENTRE EL CENTRONICS Y
;LOS PUERTOS DE LOS 8255
RDL   EQU 0010b     ;LECTURA DE NIBLE BAJO
RDH   EQU 0100B     ;LECTURA DEL NIBLE ALTO
WR    EQU 0001B     ;ESCRITURA
ENDIR EQU 1000B     ;DIRECCIONAMIENTO

.model compact,pascal
.code
        public _inpio
        public _outpio
;lee un dato del puero 8255 indicado y lo devuelve en al
_inpio proc near uses bx cx dx,PUERTO
      
        push PUERTO             ;Selecciona el puerto indicado
        call _selecreg
        add sp,2
        mov al,RDH               ;Activa la orden RDh lectura parte alta
        out dx,al
        mov bx,379h
        xchg bx,dx
        in al,dx                ;lee el pueto 379h
        shl al,1                ; sube 1 bit lo leido para dejarlo como parte
        and al,0f0h
        mov ch,al               ;alta
        xchg bx,dx
        mov al,RDL              ;activa la orden RDl lectura parte baja
        out dx,al
        xchg bx,dx
        in al,dx                ;lee el puerto 379h y toma la parte baja
        mov bl,al
        mov cl,3
        shr bl,cl               ;traslada los bit abajo para posicionarlos
        and bl,0fh              ;elimina la posible basura
        or ch,bl                ;une lo leido a lo leido anteriormente
        mov al,ch               ;pasa el resulatado a al
        ret
_inpio endp

 ;envío  un dato del puero 8255 indicado
_outpio proc near   uses bx cx dx,PUERTO,DATO:byte

        push PUERTO             ;Selecciona el puerto indicado
        call _selecreg
        add sp,2
        mov dx,378h             ;lanzo el numero
        mov al,DATO
        out dx,al
        mov dx,37ah
        mov al,WR               ;indico WR
        out dx,al
        xor al,al               ;desactivo WR
        out dx,al

        ret
_outpio endp

        
;selecciona un registro interno de la targeta
; ESTA FUNCIÓN ES INTERNA A ESTA LIBRERÍA Y PERMITE
; ESCRIBIR LA DICRECIÓN DEL PUERTO ACTIVADA, PARA QUE
; SE GUARDE EN EL REGISTRO DE DIRECCIONES
; INTERNO DE LA TARJETA 48IOCENT
_selecreg proc near uses dx bx,puerto:byte    ;registro indicado en pila

        mov dx,37ah     ;elijo puerto de control del centronics
        mov al,ENDIR
        out dx,al        ;activo lach de direccion y desactivo resto
        mov bx,378h
        xchg bx,dx
        mov al,puerto
        out dx,al        ;lanzo la direccion indicada
        xchg dx,bx
        xor al,al
        out dx,al       ;deselecciono el lach de direccion

        ret
_selecreg endp

end



viernes, 29 de noviembre de 2013

CABECERA 48IOCENT

   Una vez que tenemos la tarjeta de E/S lista y hemos probado que llegan todas las señales correctamente y funcionan todas sus puertas, podemos comenzar a realizar el driver, o la librería para su control directo.
   Con esta librería podremos manejar ya sus puertos de forma transparente y configurar de forma sencilla la tarjeta.

    Para ello, como siempre, primero crearemos la cabecera con las constantes de control y configuración y las funciones de llamada.

    Para manejar los puertos de esta tarjeta necesitaremos:
                         Una función de configuración de tarjeta que llamaremos PioConfig.
                         Una función de envío a puerto que llamaremos OutPio.
                         Una función de lectura de puerto que llamaremos InPio.



    Aquí pongo la definición de la cabecera. En la siguiente entrada pondré la definición de las funciones que aquí llamo.



48IOCENT.ASM
; Copyright (C) 2013  José Ángel Moneo Fernández

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;   (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/

;DIRECCIONAMENTO DE PUERTOS DE LA TARJETA 48IOCENT
;USART 1
PA0 EQU 0
PB0 EQU 1
PC0 EQU 2
P0 EQU 3        ;REGISTRO DE CONTROL
;USART 2
PA1 EQU 4
PB1 EQU 5
PC1 EQU 6
P1 EQU 7        ;REGISTRO DE CONTROL

;CONFIGURACIONES DE LOS PUERTOS
PSALIDA EQU 80H
PA EQU  10010000B
PB EQU  10000010B
PCH EQU 10001000B
PCL EQU 10000001B

;lee un dato del puero 8255 indicado y lo devuelve en al o en la variable indicada
InPio macro dest,puerto
ifndef _inpio
        extrn _inpio:near
endif
        mov ax,puerto
        push ax
        call _inpio
ifdif <reg>,<al>
        mov dest,al
endif
endm

;envío  un dato del puero 8255 indicado
OutPio macro puerto,dato
ifndef _outpio
        extrn _outpio:near
endif

        mov ax,puerto
        push ax
        mov al,dato
        push ax
        call _outpio

 endm

;CONFIGURA UN PUERTO 8255 DE LA TARJETA
 ;PARA DEFINIR LOS MODOS DE FUNCIONAMIENTO DE LOS PUERTOS BASTARA
;INDICAR LOS QUE SEAN DE ENTRADA, LOS DEMAS SERAN DE SALIDA
;ASI PA-I PB-O PCH-I SE INDICARA COMO.. "PA" OR "PCH"
;EN EL CASO DE TODO COMO SALIDA SE INDICARA "PSALIDA"
; PIOCONFIG P0,PA,PB ESTO CONFIGURARIA EL 8255 0 CON LOS PUERTOS
; A Y B COMO ENTRADA
; el puerto C podrá ser definido por nible como entrada o salida
PioConfig macro pio,cnfg0,cnfg1,cnfg2,cnfg3
ifndef _outpio
        extrn _outpio:near
endif
        mov ax,pio
        push ax
ifnb <cnfg3>
        mov al,cnfg0 or cnfg1 or cnfg2 or cnfg3
else
  ifnb <cnfg2>
        mov al,cnfg0 or cnfg1 or cnfg2
else
  ifnb <cnfg1>
        mov al,cnfg0 or cnfg1
else
        mov al,cnfg0
endif
endif
endif
        push ax
        call _outpio
endm