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

📄 usbfs_1.asm

📁 cypresscy74294ic键盘和鼠标原码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;
;  ARGUMENTS:    A contains the endpoint number
;
;  RETURNS:      A contains the endpoint state
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
 USBFS_1_bGetEPState:
_USBFS_1_bGetEPState:
    RAM_PROLOGUE RAM_USE_CLASS_3
        RAM_SETPAGE_IDX >USBFS_1_EndpointAPIStatus
    cmp     A, (USB_MAX_EP_NUMBER + 1) ; Range check
    jnc     .invalid_ep                ; Bail out
; Flow here to enable an endpoint
    mov     X, A                       ; Endpoint number is the index
    mov     A, [X+USBFS_1_EndpointAPIStatus]; Get the state
    jmp     .exit                      ; Go to the common exit
; Jump here for an invalid endpoint
.invalid_ep:
    mov     A, 0                       ; Return 0 for an invalid ep
; Jump or flow here for a common exit
.exit:
    RAM_EPILOGUE RAM_USE_CLASS_3
    ret                                ; All done
.ENDSECTION



;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_bRWUEnabled
;
;  DESCRIPTION:   Returns 1 if Remote Wake Up is enabled, otherwise 0
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:   None
;
;  RETURNS:     A: 1--Remote Wake Up Enabled
;                  0--Remote Wake Up Disabled
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
 USBFS_1_bRWUEnabled:
_USBFS_1_bRWUEnabled:
    TST     [USBFS_1_DeviceStatus], USB_DEVICE_STATUS_REMOTE_WAKEUP
    JNZ     .enabled                   ; Jump if enabled
; Flow here if RWU is disabled
    MOV     A, 0                       ; Return disabled
    JMP     .exit                      ; Go to the common exit
; Jump when RWU is enabled
.enabled:
    MOV     A, 1                       ; Return enabled
; Jump or flow here for a common exit
.exit:
    RET                                ; All done
.ENDSECTION

;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_bGetEPCount
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A contains the Endpoint Number
;
;  RETURNS:              A and X contain a WORD that indicate the values stored in the
;                Count registers of the Endpoint
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
.SECTION
 USBFS_1_wGetEPCount:
_USBFS_1_wGetEPCount:
    RAM_PROLOGUE RAM_USE_CLASS_1
    cmp     A, (USB_MAX_EP_NUMBER + 1) ; Range check
    jnc     .invalid_ep                ; Bail out
; Flow here to get the endpoint count
    asl     A                          ; Multiply the index by two to get to the value
    mov     X, A                       ; Endpoint number is the index
    mov     A, reg[X+USBFS_1_EP1CNT1 - 1] ; Here is the count
        sub     A, 2
    push    A
        dec     X
        mov     A, reg[X+USBFS_1_EP1CNT1 - 1] ; Here is the count
        and     A, 0x01
    mov     X, A
        pop     A
    jmp     .exit                      ; Go to the common exit
; Jump here for an invalid endpoint
.invalid_ep:
    mov     A, 0                       ; Return 0 for an invalid ep
; Jump or flow here for a common exit
.exit:
    RAM_EPILOGUE RAM_USE_CLASS_1
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_LoadInEP and USBFS_1_LoadInISOCEP
;
;  DESCRIPTION:    This function loads the specified USB endpoint with
;                  the data specified.
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     [SP-8] Toggle
;     [SP-7] MSB of Count to send
;     [SP-6] LSB of Count to send
;     [SP-5] MSB of data array address
;     [SP-4] LSB of data array address
;     [SP-3] Endpoint Number
;
;  RETURNS:
;     none
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
;    Currently only the page pointer registers listed below are modified:
;          CUR_PP
;          IDX_PP
;
EP_TYPE:        equ -1
; -2 and -3 is the return address to caller
EP_NUM:     equ -4                       ; Endpoint Number
DATA_LSB:   equ -5           ; LSB pointer of data
DATA_MSB:   equ -6           ; MSB pointer of data
CNTLEN_LSB: equ -7
CNTLEN_MSB: equ -8           ; Length of data to send
TOGGLE:     equ -9

 USBFS_1_LoadInISOCEP:
_USBFS_1_LoadInISOCEP:
        mov             A, USB_MODE_ISO_IN
        push    A
        jmp             BodyLoadIN_USBFS_1
 USBFS_1_LoadInEP:
_USBFS_1_LoadInEP:
        mov             A, USB_MODE_ACK_IN
        push    A
BodyLoadIN_USBFS_1:
    RAM_PROLOGUE RAM_USE_CLASS_4
    RAM_PROLOGUE RAM_USE_CLASS_3
        RAM_SETPAGE_CUR >USBFS_1_bCurrentDevice ; Set the CUR_PP to the right page
    RAM_SETPAGE_IDX2STK
        mov     X, SP
        mov     A, [X+EP_NUM]
        cmp     A, USB_MAX_EP_NUMBER+1 ; Range check
    jnc     .exit                      ; Bail out

    ;SET THE COUNT
        mov     A, [X+CNTLEN_MSB]      ; Get the MSB of the Count
        and     A, 0x01                ; Mask off the count bit
        mov     [USBFS_1_APITemp+1], A ; Save the count
        mov     A, [X+CNTLEN_LSB]      ; Get the LSB of the Count
        mov     [USBFS_1_APITemp], A   ; Save the count


        ;  Perform normal data toggle or bypass?
        mov     A, [X+TOGGLE]
        jnz      .normalToggle

		; the endpoint ISR automatically toggles the endpoint, so to support
		; the idea of not having the toggle change we must untoggle here.
        mov     A, [X+EP_NUM]           ; Get the Endpoint number
        INDEX   USBFS_1_USB_EP_BIT_LOOKUP ; Get the bit mask
        XOR     [USBFS_1_EPDataToggle], A ; Retoggle the toggle

.normalToggle:              
        mov     A, [X+EP_NUM]           ; Get the Endpoint number
        INDEX   USBFS_1_USB_EP_BIT_LOOKUP ; Get the bit mask
        AND     A, [USBFS_1_EPDataToggle]
        JZ      .toggle0

        OR      [USBFS_1_APITemp+1],USB_CNT_TOGGLE ; Set the data toggle
        JMP     .toggle_done
.toggle0:
        AND     [USBFS_1_APITemp+1],~USB_CNT_TOGGLE
                
.toggle_done:

    RAM_SETPAGE_IDX2STK
    mov     X, SP
        mov     A, [X+EP_NUM]           ; Get the Endpoint number
        asl     A                       ; Double the ep number for proper cnt access
        mov     X, A                    ; Make it into an index
        mov     A, [USBFS_1_APITemp]    ; Retrieve the saved MSB
    mov     reg[X+USBFS_1_EP1CNT1 - 1], A   ; Write it into the register
    dec     X                           ; Decrement the index to access the LSB
        mov     A, [USBFS_1_APITemp+1]  ; Retrieve the saved LSB
        mov     reg[X+USBFS_1_EP1CNT1 - 1], A   ; Write it into the register

; It's Time to move the data

; First we need to determine where within the PMA the EP Start Address is
        mov     X, SP                   ; Get the Stack Pointer
        mov     A, [X+EP_NUM]           ; Get the Endpoint number
        mov     X, A                    ; Use the EP number as an index
        mov     A, reg[X+TMP_DR0-1]     ; Get the address of ep from tmp register
        M8C_SetBank1
        mov     reg[PMA0_WA], A         ; Set the Write pointer of our pma to ep space
        M8C_SetBank0

; Now we are ready to start moving data
    mov     X, SP
        and     [X+CNTLEN_MSB], 0x01    ; Mask off the MSB bit
        jnz     .start_send             ; If it is high then we have 256 bytes
        mov     A, [X+CNTLEN_LSB]       ; Check the LSB register
        jz      .done                   ; If it is 0 then we have a 0 length packet
.start_send:
        mov     A, [X+DATA_LSB]
        push    A
IF SYSTEM_LARGE_MEMORY_MODEL
        mov     A, [X+DATA_MSB]
        mov     reg[IDX_PP], A
ENDIF
        pop     X

.loop:
        mov             A, [X]
        mov     reg[PMA0_DR], A
        inc     X
        dec     [USBFS_1_APITemp]
        jnz     .loop

        RAM_SETPAGE_IDX2STK
.done:
    mov     X, SP
        mov     A, [X+EP_NUM]
        mov     X, A
        RAM_SETPAGE_IDX >USBFS_1_EndpointAPIStatus
    mov     [X + USBFS_1_EndpointAPIStatus], NO_EVENT_PENDING ; Set the state
        M8C_SetBank1
        mov     A, reg[X+TMP_DR0-1]    ; Get the value of the PMA start Address
        mov     reg[X + PMA0_RA], A    ; Load it into EP PMA so pre-fetch occurs

        push    X
        RAM_X_POINTS_TO_STACKPAGE
    mov     X, SP
    mov         A, [X+EP_TYPE-1]
        pop             X
    mov     reg[X + USBFS_1_EP1MODE-1], A ; Enable the endpoint

        M8C_SetBank0

.exit:
        pop             A              ; Clean up EP_TYPE
    RAM_EPILOGUE RAM_USE_CLASS_3
        RAM_EPILOGUE RAM_USE_CLASS_4
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_EnableOutEP and
;                                 USBFS_1_EnableOutISOCEP
;
;  DESCRIPTION:    This function enables an OUT endpoint.  It should not be
;                  called for an IN endpoint.
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:      A contains the endpoint number
;
;  RETURNS:        None
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's

⌨️ 快捷键说明

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