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

📄 emb_f.asm

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





;-----------------------------------------------------------------
;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
;--------------------------------------------------------------------*
;SCOPE
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
        jmp     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)
        jmp     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)
        jmp     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
        jmp     LoadIt

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





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


        ;------- TBD -------
        jmp     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


        ;------- TBD -------
        jmp     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
;--------------------------------------------------------------------*
;SCOPE
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
        jmp     DoneWithCommand

GetInStallStatus:
        mov     A,      EPCON
        jnb     ACC.6,  NotStalled
        mov     A,      #01
        jmp     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
;--------------------------------------------------------------------*
;SCOPE
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
;--------------------------------------------------------------------*
;SCOPE
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
        jmp     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
        jmp     ReturnSTDSetEPCommand
ClearInStall:
        anl     EPCON , #CLEAR_IN_STALL_MASK
        jmp     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
        jmp     ReturnSTDSetEPCommand
SetInStall:
        orl     EPCON , #SET_IN_STALL_MASK
        jmp     ReturnSTDSetEPCommand

ReturnBadSTDSetEPCommand:

        orl     EPCON , #0C0h                  ;Stall EP0
ReturnSTDSetEPCommand:
        pop     EPINDEX
        jmp     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
;--------------------------------------------------------------------*
;SCOPE
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
        Call     ResetFifos                  ; Empty out all of the FIFOs and return to
                                             ; the un configuraed state.
        jb       LC, ReturnSTDSetDevice      ; Are we in low power state?
        setb     LC                          ; If not then goto low power state.
        jmp      ReturnSTDSetDevice
CheckConfig1:
        cjne     A,    #1, CheckConfig2
        mov      CurrentConfiguration, R11   ; Set up the variables

        Call     SetUpConfiguration1
        jmp      ReturnSTDSetDevice

CheckConfig2:
        cjne     A,    #2, ReturnBadSetDeviceCommand


        jmp      ReturnSTDSetDevice

CheckSetDeviceAddress:

⌨️ 快捷键说明

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