⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hub_ep0.asm

📁 mcs51,2051,x86系列MCU
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        anl     FIFLG,    #EP0_TX_CLR                 ; clear the interrupt bit
       ljmp     CheckInStatusPhase

ProcessHubInToken:
        anl     HIFLG,   #EP0_TX_CLR                 ; clear the interrupt bit

CheckInStatusPhase:

        mov     A,      gbSetupSeqTX                ; read state variable
        cjne    A,      #STATUS_PHASE,SendDataBack  ; Should this be the end to
                                                    ; a setup sequence


StatusPhaseDone:
        lCall   CompleteSetCommand
        mov     gbSetupSeqTX, #SETUP_PHASE          ; Set state var. to expect setup.
        mov     gbSetupSeqRX, #SETUP_PHASE

       sjmp     ReturnProcessIn

SendDataBack:
        cjne    A,      #DATA_PHASE, ReturnProcessIn
       lcall    LoadControlTXFifo

ReturnProcessIn:
        Ret


;COMMENT *------------------------------------------------------------
;Function name     : CompleteSetCommand
;Brief Description : Called after the status phase of a set command has
;                  : completed.  This is called everytime there is a
;                  : xmit status stage.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
CompleteSetCommand:
        mov     A,      bRequest                    ; If this was not a Std. Set
                                                    ; command then return.

        cjne    A,      #SET_ADDRESS, CheckNextCommand
   ;------------------------------------------------
   ;- SET ADDRESS
   ;------------------------------------------------
DoSetAddress:
        jnb     EPINDEX.7, SetFunctionAddress       ; Use EPINDEX to tell if this
SetHubAddress:                                      ; was a hub command or function command.

        mov     HADDR,     wValue+1                 ; Set to new address
       sjmp     ReturnCompleteSet

SetFunctionAddress:
        mov     FADDR,  wValue+1                    ; Set to new address
       sjmp     ReturnCompleteSet

CheckNextCommand:
ReturnCompleteSet:
        ret

;COMMENT *------------------------------------------------------------
;Function name     : SetUpControlWriteStatusStage
;Brief Description : Sets the status in the IN buffer.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
SetUpControlWriteStatusStage:
        mov     TXCNTL, #00                      ; Setup Null Packet
;        setb    TXOE0                            ; Enable data transmit
        Ret

;COMMENT *------------------------------------------------------------
;Function name     : LoadControlTXFifo
;Brief Description : Copy data from the location pointed to by
;                  : the three byte value gbFControlBufferLocation.
;                  : The number of bytes left to transmit are stored in
;                  : gbFControlBufferBytesLeft.  If zero bytes are left then
;                  : a Null packet is loaded even if the null/short packet is
;                  : not needed.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
LoadControlTXFifo:
        push    R0                                  ; Need to save this register
        push    DPX
        mov     DPXL,   gbFControlBufferLocation    ; Get location of data to send.
        mov     DPH,    gbFControlBufferLocation+1
        mov     DPL,    gbFControlBufferLocation+2



        mov     A,      gbFControlBufferBytesLeft   ; First check to sei if any data is availble
        orl     A,      gbFControlBufferBytesLeft+1 ; to send.
        jnz     CntlDataAvail

        mov     R0,     #0                          ; if there is data do normal flow
        ljmp    ControlArmTx                        ; if none, do null packet

CntlDataAvail:
        mov     R0,     #0                          ; Number of bytes in FIFO- Awlays <=16
        mov     A,      DPXL
        JZ      DataInRAM

;-----------------------------------------------
; Data is in ROM, use instrcutions to pull from ROM.
;-----------------------------------------------
DataInROM:
        mov     A,      #00h
        movc    A,      @A+DPTR                     ; Get Data to transmit
        mov     TXDAT, A
        inc     DPTR
        inc     R0                                  ; Increment the number of bytes in FIFO
        djnz    gbFControlBufferBytesLeft+1, ROMCheckMaxPacket        ; If not zero, the continue.

ROMCheckUpper1:
        mov     A,       gbFControlBufferBytesLeft  ; If upper byte of wLength is also zero, buffer is empty.
        jz      ControlTxUpd                        ; Are we done with the buffer
        dec     A                                   ; If it's not zero dec. the upper byte as well.
        mov     gbFControlBufferBytesLeft, A        ; And store it.

ROMCheckMaxPacket:
        cjne    R0,      #EP0_MAX_PACKET_SIZE, DataInROM    ; Loop until FIFO is Full
        ljmp     ControlTxUpd                       ; Done with this FIFO.


;-----------------------------------------------
; Data is in RAM, use instrcutions to pull from RAM.
;-----------------------------------------------

DataInRAM:


        movx    A,      @DPTR                       ; Get Data to transmit
        mov     TXDAT, A
        inc     DPTR
        inc     R0                                  ; Increment the number of bytes in FIFO
        djnz    gbFControlBufferBytesLeft+1, RAMCheckMaxPacket        ; If not zero, the continue.

RAMCheckUpper1:
        mov     A,       gbFControlBufferBytesLeft  ; If upper byte of gbFControlBufferBytesLeft is also zero, buffer is empty.
        jz      ControlTxUpd                        ; Are we done with the buffer
        dec     A                                   ; If it's not zero dec. the upper byte as well.
        mov     gbFControlBufferBytesLeft, A        ; And store it.

RAMCheckMaxPacket:
        cjne    R0,      #EP0_MAX_PACKET_SIZE, DataInRAM    ; Loop until FIFO is Full


ControlTxUpd:
        mov     gbFControlBufferLocation+1, DPH      ; Update read pointers.
        mov     gbFControlBufferLocation+2, DPL

ControlArmTx:
        mov     TXCNTL, R0                          ; Write count into TXCNT register
        setb    TXOE                                ; Enable data transmit
ReturnLoadCntl:
        pop     DPX
        pop     R0
        Ret


;COMMENT *------------------------------------------------------------
;Function name     : GetOUTData
;Brief Description : takes data from the FIFO, Puts it in memory and
;                  : then updates writes it to the fifo.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
;GetOUTData:
;        mov     WR26, #LOW16(OUT_BUFFERS)
;        mov     R7, RXCNTL                      ; Read count of bytes rec'd
;        mov     @WR26, R7                       ; Store the count in the OUT_BUFFERS space.
;        add     WR26, #01h                      ; Increment mem pointer

;        orl     R7, R7                          ; Set flags
;        je      Return

;WriteToOUTBuffer:
;        mov     R8, RXDAT
;        mov     @WR26, R8
;        inc     WR26, #01h
;        djnz    R7, WriteToOUTBuffer

;Return:
;        Ret



;COMMENT *------------------------------------------------------------
;Function name     : INIT_USB
;Brief Description : Initialize USB SFRs
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
INIT_USB:                          ; EP0 Comes up as it should except that
                                   ; all flow control is turned off except for
                                   ; OE bits.  This will turn them on so we can
                                   ; accept all data.
                                   ; All other endpoints should not be configured
                                   ; until a Set Configuration command is given.
        mov     EPINDEX, #80
        mov     TXCON,   #0$$HTXCON$h
        mov     RXCON,   #0$$HRXCON$h
        mov     EPCON,   #0$$HEPCON$h

ReturnInitUSB:
        Ret

;COMMENT *------------------------------------------------------------
;Function name     : INIT_VARIABLES
;Brief Description : Initializes global variables
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
INIT_VARIABLES:
;Init SETUP VARIABLES

        mov     R0, #00h
        mov     Heart1, R0
        mov     Heart1+1, R0
        mov     gbSetupSeqRX, R0                       ; SetupSeq is set to

        mov     gbSetupSeqTX, R0                       ; STATUS_PHASE
        mov     gbFControlBufferLocation, R0
        mov     gbFControlBufferLocation+1, R0
        mov     gbFControlBufferLocation+2, R0

        mov     gbFControlBufferBytesLeft, R0
        mov     CurrentConfiguration, R0
        mov     CurrentConfig1Interface, R0
        mov     WR0, #0                    ; Zero Out Counter
        mov     WR2, WR0

ReturnInit:
        Ret

;========================================================================
;====================== RightCylon ======================================
;========================================================================
;This routine does a cylon pattern to the right.  The time between steps is
; contained in WR2.  Only the flag register is modified during this routine.

RightCylon:
        push   WR2
        push   ACC
        mov    A,   #80h
CylonRightLoop:
        dec   WR2, #1
        cmp   R2,  #00h
        jne   CylonRightLoop
        srl   R11
        mov   P1, A
        pop   WR2
        push  WR2
        jnb   ACC.0, CylonRightLoop
        pop   ACC
        pop   WR2
        ret

;========================================================================
;====================== LeftCylon ======================================
;========================================================================
;This routine does a cylon pattern to the left.  The time between steps is
; contained in WR2.  Only the flag register is modified during this routine.

LeftCylon:

        push   WR2
        push   ACC

        mov    A,   #01h
CylonLeftLoop:
        dec   WR2, #1
        cmp   R2,  #0h
        jne   CylonLeftLoop
        sll   R11
        mov   P1, A
        pop   WR2
        push  WR2
        jnb   ACC.7, CylonLeftLoop
        pop   ACC
        pop   WR2
        ret

;========================================================================
;====================== Delay ======================================
;========================================================================
; This routine delays by the delay specified in DR0.
; If Fixed delay is called, the

FixedDelay:
        mov   WR2, #0
        mov   WR0, #20h

VaraibleDelay:
delay1:
        dec   DR0, #01
        jne   delay1
        ret

;************************************************************************
;************* DEVICE DESCRIPTOR ****************************************
;************************************************************************


; NOTE!!!!! '251 is a Big Endian machine. Words and DWords are stored with the
; LSB in the numerically higher address.


;------------------------------------------------
;-------- HUB DESCRIPTOR ------------------------
;------------------------------------------------

;
; NOTE!!!!! '251 is a Big Endian machine. Words and DWords are stored with the
; LSB in the numerically higher address.
;
Header:     db "HUB FIMRWARE 2",10,13,00

BEGIN_DEVICE_DESCRIPTOR:
        gDevice_bLength:            db  12h;   DEVICE_DESCRIPTOR_LENGTH
        gDevice_bDescriptorType:    db  DEVICE_DESCR
        gDevice_bcdUSB:             db  LOW(00$$DEVBCDUSB$h)
                     db HIGH(00$$DEVBCDUSB$h)
        gDevice_bDeviceClass:       db  0$$DEVDEVCLASS$h
        gDevice_bDeviceSubClass:    db  0$$DEVDEVSUBCLASS$h
        gDevice_bDeviceProtocol:    db  0$$DEVDEVPROTOC$h
        gDevice_wMaxPacketSize0:    db  08h
        gDevice_widVendor:          db  LOW(00$$DEVVENDOR$h)
                     db HIGH(00$$DEVVENDOR$h)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -