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

📄 ax_enum.asm

📁 mcs51,2051,x86系列MCU
💻 ASM
📖 第 1 页 / 共 5 页
字号:

;-----------------------------------------------------------------
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs
;S
;S          STANDARD TYPE COMMANDS FIRST
;S
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs
;-----------------------------------------------------------------

;COMMENT *------------------------------------------------------------
;Function name     : GetStandardDeviceCommand:
;Brief Description : Process a Get Standard Device Command Setup Token
;                  : This can only be a Get (Device or Configuration) Descriptor,
;                  : or Get Device Status, Get Configuration.
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

StandardGetDeviceCommand:
        mov     A,     bRequest
        cjne    A,     #GET_DESCRIPTOR, CheckGetConfiguration

        mov     A,     bDescriptorType
        cjne    A,     #DEVICE_DESCR, CheckConfigDescriptor

        ; ********************** GET DESCRIPTOR,  DEVICE *******************
        mov     gbFControlBufferLocation,   #LOW HIGH16(BEGIN_DEVICE_DESCRIPTOR)
        mov     gbFControlBufferLocation+1, #HIGH LOW16(BEGIN_DEVICE_DESCRIPTOR)
        mov     gbFControlBufferLocation+2, #LOW  LOW16(BEGIN_DEVICE_DESCRIPTOR)
        mov     A,  #12h
        mov     B,  #00h
        sjmp    LoadBuffer

CheckConfigDescriptor:
        cjne    A,     #CONFIG_DESCR, CheckStringDescriptor

        ; ********************** GET DESCRIPTOR,  CONFIGURATION ************
        mov     gbFControlBufferLocation,   #LOW HIGH16(BEGIN_CONFIG_DESCRIPTOR_1)
        mov     gbFControlBufferLocation+1, #HIGH LOW16(BEGIN_CONFIG_DESCRIPTOR_1)
        mov     gbFControlBufferLocation+2, #LOW  LOW16(BEGIN_CONFIG_DESCRIPTOR_1)
        mov     A,  #LOW  (END_CONFIG_DESCRIPTOR_1 - BEGIN_CONFIG_DESCRIPTOR_1)
        mov     B,  #HIGH (END_CONFIG_DESCRIPTOR_1 - BEGIN_CONFIG_DESCRIPTOR_1)
        sjmp    LoadBuffer

CheckStringDescriptor:
        cjne    A,     #STRING_DESCR, ReturnBADSTDGetDeviceCommand
        ; ********************** GET DESCRIPTOR,  CONFIGURATION ************
        mov     gbFControlBufferLocation,   #LOW HIGH16(STRING_1)
        mov     gbFControlBufferLocation+1, #HIGH LOW16(STRING_1)
        mov     gbFControlBufferLocation+2, #LOW  LOW16(STRING_1)

        mov     A,     #LOW (STRING_2-STRING_1)
        mov     B,     #HIGH(STRING_2-STRING_1)
        sjmp    LoadBuffer



LoadBuffer:                                      ; Compare to see which is shorter.
                                                 ; The amount asked for or the amount
                                                 ; availible.

        push    ACC
        push    B
        clr     CY                               ; A=Actual-wLength=AskedFor
        subb    A,  wLength+1
        mov     A,  B
        subb    A,  wLength
        jc      AskedFor_IsLarger

LengthsMatch:
wLengthIsSmaller:                                ; If Asked for is smaller, replace
                                                 ; actual with asked for.
        pop     B
        pop     ACC
        mov     B,  wLength
        mov     A,  wLength+1
        sjmp    LoadIt

AskedFor_IsLarger:
        pop     B
        pop     ACC
LoadIt:                                          ; From now on,
                                                 ; wLength = bytes remaining.
        mov     gbFControlBufferBytesLeft,   B
        mov     gbFControlBufferBytesLeft+1, A
        LCall   LoadControlTXFifo
        sjmp    ReturnSTDGetDeviceCommand





CheckGetConfiguration:
        cjne    A,     #GET_CONFIGURATION, CheckGetStatus
                   ;------------------------------------------------
                   ;- GET CONFIGURATION
                   ;------------------------------------------------
        mov     R11,    CurrentConfiguration
        mov     TXDAT,  A
        mov     TXCNTL, #01
        sjmp    ReturnSTDGetDeviceCommand

CheckGetStatus:
        cjne    A,     #GET_STATUS, ReturnSTDGetDeviceCommand
                   ;------------------------------------------------
                   ;- GET DEVICE STATUS
                   ;------------------------------------------------
        mov     A,      #01h        ; Not RWU and seld powered
        mov     TXDAT,  A
        mov     TXDAT,  #00h
        mov     TXCNTL, #02
        sjmp    ReturnSTDGetDeviceCommand

ReturnBADSTDGetDeviceCommand:
        orl     EPCON,  #0C0h                   ; Stall EP0

ReturnSTDGetDeviceCommand:
        ret


;COMMENT *------------------------------------------------------------
;Function name     : StandardGetEndpointCommand:
;Brief Description : Process a Standard Set Endpoint Command Setup Token
;                  : This can only be a Set,Clear Feature - Endpoint Stall
;                  :
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

StandardGetEndpointCommand:

        mov     A,     bRequest
        cjne    A,     #GET_STATUS,    ReturnBadSTDGetEPCommand
                   ;------------------------------------------------
                   ;- GET ENDPOINT STATUS
                   ;------------------------------------------------
        mov     A,      wIndex + 1
        anl     A,      #0Fh                     ; Mask off all but the endpoint value
        mov     EPINDEX,A                        ; Point the Index register at the

        mov     A,      wIndex + 1               ; Start by clearing out R0
        jb      ACC.7,  GetInStallStatus

GetOutStallStatus:
        mov     A,      EPCON
        jnb     ACC.7,  NotStalled
        mov     A,      #01                      ; Return Stalled
        sjmp    DoneWithCommand

GetInStallStatus:
        mov     A,      EPCON
        jnb     ACC.6,  NotStalled
        mov     A,      #01
        sjmp    DoneWithCommand

NotStalled:
        mov     A,      #00h

DoneWithCommand:
        anl     EPINDEX,#80h                     ; Point the index back to EP0
        mov     TXDAT,  A
        mov     TXDAT,  #00h
        mov     TXCNTL, #02
        ret

ReturnBadSTDGetEPCommand:

        orl     EPCON,  #0C0h                    ; Stall EP0
ReturnSTDGetEPCommand:
        Ret

;COMMENT *------------------------------------------------------------
;Function name     : SetUpSinglePacketControlReadStatusStage
;Brief Description : Sets the status in the IN buffer and initilizes all the
;                  : registers needed to do a single packet control read.
;                  : This needs to be done so the IN token is processed correctly.
;                  :
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

SetUpSinglePacketControlReadStatusStage:

        mov     wLength,      #00
        mov     wLength+1,    #00
        mov     gbSetupSeqRX, #STATUS_PHASE      ; Advance State Machine to next state
        mov     gbSetupSeqTX, #DATA_PHASE
        setb    TXOE                             ; Enable data transmit
        Ret

;COMMENT *------------------------------------------------------------
;Function name     : StandardSetEndpointCommand:
;Brief Description : Process a Standard Set Endpoint Command Setup Token
;                  : This can only be a Set,Clear Feature - Endpoint Stall
;                  :
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

StandardSetEndpointCommand:
        push    EPINDEX
        mov     A,      wIndex+1                 ; Get the endpoint of the stall to clear
        anl     A,      #0Fh                     ; Find out if this is an EP0 CLear Stall Command.
        orl     EPINDEX,A                        ; Setup the EPINDEX to point at correct index.

                               ; Check to make sure this is an Endpoint Stall.
                               ; If it is not then it's a wrong command plus you
                               ; save a few bytes doing it in this order.

        mov     A,      wValue+1
        cjne    A,      #ENDPOINT_STALL, ReturnBadSTDSetEPCommand

        mov     A,      bRequest
        cjne    A,      #CLEAR_FEATURE,  CheckSetEndpointFeature

ClearEndpointFeature:
                   ;------------------------------------------------
                   ;- CLEAR ENDPOINT STALL
                   ;------------------------------------------------
ClearEndpointStall:
        mov     A,      wIndex+1                 ; Get the endpoint of the stall to clear
        anl     A,      #0Fh                     ; Find out if this is an EP0 CLear Stall Command.
        JNZ     ClearNonEP0Stall

        anl     EPCON,  #03Fh                    ; For EP0 Clear both TX & RX stall bits
        sjmp    ReturnSTDSetEPCommand

ClearNonEP0Stall:
        mov     A,      wIndex+1                 ; Get the endpoint of the stall to clear
        JB      ACC.7,  ClearInStall             ; For Non EP0, examing the direction bit as well.
ClearOutStall:
        anl     EPCON,  #CLEAR_OUT_STALL_MASK
        sjmp    ReturnSTDSetEPCommand
ClearInStall:
        anl     EPCON,  #CLEAR_IN_STALL_MASK
        sjmp    ReturnSTDSetEPCommand


CheckSetEndpointFeature:
        cjne    A,      #SET_FEATURE, ReturnBadSTDSetEPCommand


SetEndpointFeature:
                   ;------------------------------------------------
                   ;- SET ENDPOINT STALL
                   ;------------------------------------------------
SetEndpointStall:
        mov     A,      wIndex+1                 ; Get the endpoint to stall
        JB      ACC.7,  SetInStall
SetOutStall:
        orl     EPCON,  #SET_OUT_STALL_MASK
        sjmp    ReturnSTDSetEPCommand
SetInStall:
        orl     EPCON,  #SET_IN_STALL_MASK
        sjmp    ReturnSTDSetEPCommand

ReturnBadSTDSetEPCommand:

        orl     EPCON,  #0C0h                    ; Stall EP0
ReturnSTDSetEPCommand:
        pop     EPINDEX
        ljmp    SetUpControlWriteStatusStage



;COMMENT *------------------------------------------------------------
;Function name     : StandardSetDeviceCommand:
;Brief Description : Process a Standard Set Device Command Setup Token
;                  : The only valid commands are Set Address,
;                  : Set Configuration.  Other commands which have this
;                  : field but are un-defined are
;                  : ClearDeviceFeature, SetDescriptor, SetDeviceFeature.
;                  :
;Regs preserved    : No reg. is saved
;--------------------------------------------------------------------*

StandardSetDeviceCommand:

        mov     A,      bRequest
        cjne    A,      #SET_CONFIGURATION, CheckSetDeviceAddress
SetDeviceConfiguration:
                   ;------------------------------------------------
                   ;- SET DEVICE CONFIGURATION
                   ;------------------------------------------------

        ; Check to see what configuration we should take on.
        mov      A,    wValue+1

CheckConfig0:
        cjne     A,    #0, CheckConfig1
        mov      CurrentConfiguration, R11   ; Set up the variables
        push     EPINDEX
        LCall     ResetFifos                  ; Empty out all of the FIFOs and return to
                                             ; the un configuraed state.
        pop      EPINDEX
        jb       LC, ReturnSTDSetDevice      ; Are we in low power state?
        setb     LC                          ; If not then goto low power state.
        sjmp     ReturnSTDSetDevice

CheckConfig1:
        cjne     A,    #1, CheckConfig2
        mov      CurrentConfiguration, R11   ; Set up the variables
        lCall    SetUpConfiguration1
        sjmp     ReturnSTDSetDevice

CheckConfig2:
        cjne     A,    #2, ReturnBadSetDeviceCommand

        sjmp     ReturnSTDSetDevice

CheckSetDeviceAddress:
        cjne    A,      #SET_ADDRESS, CheckSetDeviceRWU
                   ;------------------------------------------------
                   ;- SET DEVICE ADDRESS
                   ;------------------------------------------------

        ; Set Address should just return.  The command will be executed
        ; following the status stage
        sjmp    ReturnSTDSetDevice

CheckSetDeviceRWU:
        cjne    A,      #SET_FEATURE, CheckClearDeviceRWU
        mov     A,      wValue+1
        cjne    A,      #DEVICE_REMOTE_WAKEUP, ReturnBadSetDeviceCommand
        ; Call user function to enable RWU
        sjmp    ReturnSTDSetDevice

CheckClearDeviceRWU:
        cjne    A,      #CLEAR_FEATURE, ReturnBadSetDeviceCommand
        mov     A,      wValue+1
        cjne    A,      #DEVICE_REMOTE_WAKEUP, ReturnBadSetDeviceCommand
      

⌨️ 快捷键说明

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