Detecting 8250 versus 16550 com port 
Author Message
 Detecting 8250 versus 16550 com port

Anyone help with some code to sort this little problem out...

Thanks in Advance



Mon, 26 Jul 1999 03:00:00 GMT  
 Detecting 8250 versus 16550 com port



Quote:

>Anyone help with some code to sort this little problem out...

Hello.

This is a code that was posted in the FidoNet 80XXX folder. It was
written by Yousuf Khan, which I think I saw participating in this
newsgroup.

--------------- cut here -------------

comment *

        Determines the type of UART in each serial port

        *

.model tiny

bdseg   segment at 40h  ;BIOS data segment
        com1    dw      ?
        com2    dw      ?
        com3    dw      ?
        com4    dw      ?
        ends

.data
        uart1   db      0
        uart2   db      0
        uart3   db      0
        uart4   db      0
        no_of_comports  db      ?       ;# of active comports found

.code
        org     100h
start:
        mov     ax, bdseg
        mov     es, ax          ;ES := Bdseg
        assume  es:bdseg
        xor     bl, bl          ;zero the comport counter
        ;start by searching first comport i/o addr
        mov     dx, [com1]
        mov     di, offset uart1
        call    searchport
search_com2:                    ;search 2nd comport i/o addr
        mov     dx, [com2]
        mov     di, offset uart2
        call    searchport
search_com3:                    ;search 3rd comport i/o addr
        mov     dx, [com3]
        mov     di, offset uart3
        call    searchport
search_com4:                    ;search 4th comport i/o addr
        mov     dx, [com4]
        mov     di, offset uart4
        call    searchport
eoproc:
        mov     [no_of_comports], bl
        call    disp
        mov     al, [no_of_comports]
        mov     ah, 4ch
        int     21h

searchport      proc
comment *

        Purpose:
        To check current comport entry in BIOS data segment to see if a
        comport is using it, and if so, what type UART is controlling
        it.

        Entry:
        DX=value of base i/o addr of comport
        DI->points to UART type storage location
        BL=# of comports found thus far

        Return:
        BL incr if comport found, unchanged if not

        *
        cmp     dx, 0
        je      endsearch       ;BIOS says no comport, so skip testing
        inc     bl
        push    ax
        call    UARTdet
        mov     [di], al
        pop     ax
endsearch:
        ret
        endp

uartdet proc    near
Comment *

        Purpose:
        To detect UART type

        Entry:
        nothing

        Return:
        AL=UART type

        *
        UART8250        equ     1
        UART16450       equ     2
        UART16550       equ     3
        UARTType3       equ     4

        push    bx
        push    cx
        mov     bx, dx          ;save starting i/o addr

        ;modem control register port (4 offsets away from base):
        ;       Loop: loops the output of the transmitter back to
        ;               reciever.
        ;       Out2: must be set if UART is to interrupt processor,
        ;               regardless of the state of the Interrupt Enable
        ;               register.
        ;       Out1: not used in PCs.
        ;       RTS: Request To Send (ie. computer requesting)
        ;       DTR: Data Terminal Ready (ie. computer ready to receive)
        ctrl_reg        record serloop:1,out2:1,out1:1,rts:1,dtr:1

        add     dx, 4           ;point to modem ctrl reg
        in      al, dx          ;read state of mdm ctrl reg
        push    ax              ;save state
        and     al, not mask out2
        out     dx, al          ;clear all serial interrupts
        mov     ch, UART8250    ;assume original 8250
        mov     dx, bx
        ;original 8250 didn't have a scratch reg, see if it exists
        add     dx, 7           ;scratch reg 7 offsets away from base
        mov     al, 55h         ;random test value
        out     dx, al          ;write to scratch reg
        in      al, dx          ;read back
        cmp     al, 55h         ;if not equal, no scratch reg,
        jne     foundtype       ; must be original 8250.
        ;try another random test value to be sure
        mov     al, 0AAh
        out     dx, al          ;write to scratch reg
        in      al, dx          ;read back
        cmp     al, 0AAh        ;if not equal, no scratch reg,
        jne     foundtype       ; must be original 8250.
        comment \
                * End of original 8250 testing routine *
                \
        mov     ch, UART16450
        mov     dx, bx

        ;FIFO control register port (2 offsets from base port
        ; during port writes only):
        ;       Fifosize: sets the # of chars in FIFO buffer before
        ;        UART interrupts (16550A+)
        ;               00 1 byte
        ;               01 4 bytes
        ;               10 8 bytes
        ;               11 14 bytes
        ;       Fifo_rsv: 3 reserved bits (16550A+)
        ;       Trans_reset: resets transmit FIFO (16550A+)
        ;       Rcv_reset: resets receive FIFO (16550A+)
        ;       Fifoenable: entirely enables or disables FIFOs (16550A+)
        fifo_ctrl_reg   record fifosize:3,fifo_rsv:3=0,trans_reset:1,\\
                        rcv_reset:1,fifoenable:1

        add     dx, 2           ;point to FIFO ctrl reg
        ;attempt to enable FIFOs
        mov     al, fifo_ctrl_reg <0,0,1,1,1>
        out     dx, al
        in      al, dx          ;read interrupt ID reg
        ;strip all but UART_MODE bits
        and     al, mask uart_mode
        jz      foundtype       ;if mode=0, then 16450
        mov     ch, UART16550   ;assume we have 16550A for now
        mov     dx, bx
        add     dx, 8003h       ;point to enhanced reg 1
        in      al, dx
        push    ax

        ;DMA Function 1 register port (8003h offsets from base port,
        ; read/write, Type 3 UART only):
        ;       DR: Enable DMA receive mode
        ;       DMTR: Enable DMA transmit mode
        ;       RS: Store Status with received data
        ;       TCR: Enable receive terminal count int
        ;       TCT: Enable transmit terminal count int
        ;       SE: Stop transmission on receive error
        ;       TE: Enable transmitter empty int
        ;       RC: Enable receive CHAR count int
        dma_func1       record
dr:1,dmtr:1,rs:1,tcr:1,tct:1,se:1,te:1,rc:1

        or      al, mask dmtr   ;enable DMA transmission
        out     dx, al
        push    dx
        mov     dx, bx
        add     dx, 2           ;read Int ID reg
        in      al, dx          ;read status of Int ID reg
        mov     cl, al          ;save AL in CL
        pop     dx              ;restore enhanced reg 1
        pop     ax
        out     dx, al

        ;Interrupt ID register port (2 offsets from base port during
        ; port reads only):
        ;       uart_mode: char mode, DMA mode, or FIFO mode
        ;               00 Char mode (all)
        ;               01 DMA mode (Type 3 only)
        ;               11 FIFO mode (16550A+)
        ;       iid_rsv: 2 reserved bits (all)
        ;       Int_ID: reason why UART interrupted
        ;               000 look in Modem Status Reg (all)
        ;               001 Transmit data (16550A+)
        ;               010 Received data (16550A+)
        ;               110 FIFO timeout (16550A+)
        ;       Int_pending: interrupt is pending
        int_id_reg      record uart_mode:2,iid_rsv:2=0,Int_ID:3,\\
                        Int_pending:1

        ;strip all but UART_MODE bits
        and     cl, mask uart_mode
        cmp     cl, Int_id_reg <1,0,0,0>
        jne     foundtype       ;must be FIFO
        mov     ch, UARTType3   ;must be DMA
foundtype:
        pop     ax
        mov     dx, bx
        add     dx, 4           ;point to modem ctrl reg
        out     dx, al          ;restore initial condition
        xor     ax, ax
        mov     al, ch
        mov     dx, bx
        pop     cx
        pop     bx
        ret
        endp

disp    proc
comment *

        Purpose:
        To display written information to the user

        Entry:
        nothing

        Return:
        nothing
        destroys many general purpose registers, don't assume anything
         is safe.

        *
        .data
        CRLF            equ     13,10,"$"
        copyright       db      "SERTYPE 2.0 (c) 1992, Yousuf J.
Khan",CRLF
        portmsg         db      "COM0: $"
        pas_de_ports    db      "none",CRLF
        x8250           db      "non-FIFO: 8250",CRLF
        x16450          db      "non-FIFO: 16450",CRLF
        xfifo           db      "FIFO: 16550A",CRLF
        xdma            db      "FIFO/DMA: IBM type 3",CRLF
        .code
        ;display copyright message
        mov     dx, offset copyright
        mov     ah, 9
        int     21h
        ;display actual info
        mov     cx, 4                   ;# of comports-1, # of loops
        mov     bx, offset uart1        ;offset of UART type field
portdisplay:
        inc     [portmsg][3]
        mov     dx, offset portmsg
        mov     ah, 9
        int     21h
        cmp     byte ptr [bx], 0
        jne     is8250
        mov     dx, offset pas_de_ports
        jmp     showmsg
is8250:
        cmp     byte ptr [bx], uart8250
        jne     is16450
        mov     dx, offset x8250
        jmp     showmsg
is16450:
        cmp     byte ptr [bx], uart16450
        jne     isfifo
        mov     dx, offset x16450
        jmp     showmsg
isfifo:
        cmp     byte ptr [bx], uart16550
        jne     isdma
        mov     dx, offset xfifo
        jmp     showmsg
isdma:
        mov     dx, offset xdma
showmsg:
        mov     ah, 9
        int     21h
        inc     bx      ;do the next comport uart
        loop    portdisplay
        ret
        endp

        end     start

--------------- cut here -------------

Inbar.



Fri, 30 Jul 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to detect COM port settings in Windows?

2. RXASYNC and 8250/16450

3. 8250 + 8259

4. 8250 UART

5. 8250 registers

6. 8259/8250 in VHDL for FPGA Synthesis

7. A problem with interfacing with UART 16550

8. 16550 register compatible UART

9. 16550 UART Model

10. synthesizable 16550 Verilog model

11. 16550 UART

12. 16550 Model

 

 
Powered by phpBB® Forum Software