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

📄 emb_f.asm

📁 mcs51,2051,x86系列MCU
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        setb    ACC.5                            ; xx6x107x
 CheckBit5:                                      ; Bit 5 is currently at 7 position
        jnb     ACC.7,  CheckValidType           ; Convert it to bit 4 position
        setb    ACC.4                            ; xx65107x

CheckValidType:                                  ;
        jnb     ACC.5,  GoodCommand              ; If this bit (6) is clear we know
                                                 ; it's a valid value
        jb      ACC.4,  ReservedCommand          ; Bit (6) was set, if bit 5 is set it's
                                                 ; a reserved command.
        jmp     GoodCommand

ReservedCommand:
;        push    EPINDEX
;        mov     EPINDEX, #01
;        mov     TXDAT,  #11h
;        mov     TXCNT, #01h
;        pop     EPINDEX

        orl     EPCON , #0C0h                     ; Stall EP0.
        ret


                                                     ; THis code will branch to the correct jump statement
                                                     ; in the bmRequestJumpTable below.
GoodCommand:                                         ; Code added to convert AJMP table to LJMP table.
        anl     A, #3Eh                              ; Multiply SJMP offset by 3/2 to get LJMP offsett.
        mov     B, A                                 ; Save the original
        rr      A                                    ; Divide origianl by two
        anl     A, #1fH                              ;
        clr     CY                                   ;
        ADD     A, B                                 ; 2/2 + 1/2 = 3/2

        mov     DPTR,   #bmRequestJumpTable
        mov     DPXL,   #LOW HIGH16(GoodCommand)     ; Get Page of Jump Table.
                                                     ; Low byte of the upper 16 bits of the 32 bit address of the
                                                     ; jump table.
                                                     ; Is this code in RAM or ROM
        jmp     @A+DPTR                              ; Used because I use RISM sometimes
                                                     ; which places code in RAM

;---------------------------------------
;-- bmRequest Jump Table ---------------
;-- The order of these are based on the
;-- compresion algorythm used above.
;-- Each of these instructions occupy two bytes of
;-- ROM.  Do not change AJMP to LJMP as the algorytm depends on the
;-- 2 byte length of AJMP.  LJMP is 3 bytes long
;-- ------------------------------------
bmRequestJumpTable:
        LJMP    StandardSetDeviceCommand
        LJMP    StandardGetDeviceCommand
        LJMP    StandardSetInterfaceCommand
        LJMP    StandardGetInterfaceCommand
        LJMP    StandardSetEndpointCommand
        LJMP    StandardGetEndpointCommand
        LJMP    StandardSetOtherCommand
        LJMP    StandardGetOtherCommand

        LJMP    ClassSetDeviceCommand
        LJMP    ClassGetDeviceCommand
        LJMP    ClassSetInterfaceCommand
        LJMP    ClassGetInterfaceCommand
        LJMP    ClassSetEndpointCommand
        LJMP    ClassGetEndpointCommand
        LJMP    ClassSetOtherCommand
        LJMP    ClassGetOtherCommand

        LJMP    VendorSetDeviceCommand
        LJMP    VendorGetDeviceCommand
        LJMP    VendorSetInterfaceCommand
        LJMP    VendorGetInterfaceCommand
        LJMP    VendorSetEndpointCommand
        LJMP    VendorGetEndpointCommand
        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

⌨️ 快捷键说明

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