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

📄 usb_std.asm

📁 基于Cypress CY3655开发工具的USB鼠标程序
💻 ASM
📖 第 1 页 / 共 3 页
字号:
; wLength        : SIZEOF_ENDPOINT_STATUS         = 0002h  
; 
; The GET_ENDPOINT_STATUS request returns status for the specified 
; endpoint.
;
;****************************************************************
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_d2h_std_ep_00 & USB_UM_SUPPLIED)
export  USB_CB_d2h_std_ep_00
USB_CB_d2h_std_ep_00:
    MOV     A, REG[USB_EP0DATA+wIndexLo]  ; Get the endpoint number
    AND     A, ~USB_DIR_IN             ; Strip off the direction bit
    CMP     A, USB_NUM_ENDPOINTS       ; Range check
    JNC     USB_Not_Supported

    MOV     X, A                       ; The endpoint number is the index

    MOV     [USB_t2], 0                ; Use the UM temp var--Selector

    MOV     [USB_TransferBuffer + 1], 0  ; Use the UM Transfer Buffer
    MOV     A, [X + USB_EndpointStatus]  ; Get the status
    MOV     [USB_TransferBuffer], A    ; Save it in the report

    MOV     A,>GetStatusTransferDescrTable  ; Get the ROM Address MSB
    MOV     X,<GetStatusTransferDescrTable  ; Get the ROM Address LSB

    JMP     USB_GetTableEntry_Local_Std
ENDIF

;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_h2d_std_ep_01
;
;  DESCRIPTION:   Clear Endpoint Feature
;
;****************************************************************
; STANDARD ENDPOINT OUT REQUEST: Clear_Endpoint_Feature
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | ENDPOINT)    = 02h
; bRequest       : CLEAR_FEATURE                  = 01h    
; wValue         : FEATURE_SELECTOR               = --xxh  
; wIndex         : ENDPOINT                       = 00xxh
; wLength        : RESERVED                       = 0000h  
; 
; The CLEAR_ENDPOINT_FEATURE request disables a particular 
; feature for an endpoint. 
;
; The only feature supported for an endpoint is the EP_HALT 
; feature.
;
;****************************************************************
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_h2d_std_ep_01 & USB_UM_SUPPLIED)
export  USB_CB_h2d_std_ep_01
USB_CB_h2d_std_ep_01:
    MOV     A, REG[USB_EP0DATA+wValueLo]  ; Get the feature selector
    CMP     A, USB_ENDPOINT_HALT       ; Halt is the only selector defined for endpoints
    JNZ     USB_Not_Supported

    MOV     A, REG[USB_EP0DATA+wIndexLo]  ; Get the Endpoint number
    AND     A, ~USB_DIR_IN             ; Strip off the direction bit
    CMP     A, 0                       ; Since we can't halt the Control Endpoint
    JZ      .done

    CMP     A, USB_NUM_ENDPOINTS       ; Range check
    JNC     USB_Not_Supported

    MOV     X, A                       ; Endpoint number is the index
    AND     [X+USB_EndpointStatus], ~USB_ENDPOINT_STATUS_HALT  ; Clear the endpoint halt

    TST     REG[USB_EP0DATA+wIndexLo], USB_DIR_IN  ; IN or OUT endpoint?
    JNZ     .in

    MOV     REG[X + USB_EP0MODE], USB_MODE_NAK_OUT  ; NAK the endpoint
    JMP     .done    
.in:
    MOV     REG[X + USB_EP0MODE], USB_MODE_NAK_IN  ; NAK the endpoint
.done:        
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_h2d_std_ep_03
;
;  DESCRIPTION:   Set Endpoint Feature
;
;****************************************************************
; STANDARD ENDPOINT OUT REQUEST: Set_Endpoint_Feature
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | ENDPOINT)    = 02h
; bRequest       : SET_FEATURE                    = 03h    
; wValue         : FEATURE_SELECTOR               = --xxh  
; wIndex         : ENDPOINT                       = 00xxh
; wLength        : RESERVED                       = 0000h  
; 
; The SET_ENDPOINT_FEATURE request enables a particular feature
; for a specific endpoint. The only feature supported for an 
; endpoint is the EP_HALT feature.
; 
;****************************************************************
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_h2d_std_ep_03 & USB_UM_SUPPLIED)
export  USB_CB_h2d_std_ep_03
USB_CB_h2d_std_ep_03:
    MOV     A, REG[USB_EP0DATA+wValueLo]  ; Get the feature selector
    CMP     A, USB_ENDPOINT_HALT       ; Halt is the only selector defined for endpoints
    JNZ     USB_Not_Supported

    MOV     A, REG[USB_EP0DATA+wIndexLo]  ; Get the Endpoint number
    AND     A, ~USB_DIR_IN             ; Strip off the direction bit
    CMP     A, 0                       ; Never halt the Control Endpoint
    JZ      .done

    CMP     A, USB_NUM_ENDPOINTS       ; Range check
    JNC     USB_Not_Supported

    MOV     X, A                       ; Endpoint number is the index

    OR      [X+USB_EndpointStatus], USB_ENDPOINT_STATUS_HALT  ; Halt the endpoint

    TST     REG[USB_EP0DATA+wIndexLo], USB_DIR_IN  ; IN or OUT endpoint?
    JNZ     .in

    MOV     REG[X + USB_EP0MODE], USB_MODE_STALL_DATA_EP | USB_MODE_ACK_OUT  ; Stall the endpoint
    JMP     .done    
.in:
    MOV     REG[X + USB_EP0MODE], USB_MODE_STALL_DATA_EP | USB_MODE_ACK_IN  ; Stall the endpoint
.done:        
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ConfigureEP
;
;  DESCRIPTION:   Configure an endpoint
;
;  ARGUMENTS:    A contains the endpoint direction
;                X contains the endpoint number
;
;  RETURNS:
;
;  SIDE EFFECTS:  The A REGISTER IS VOLATILE.  X REGISTER IS MAINTAINED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
ConfigureEP:
    CMP     A, USB_DIR_UNUSED          ; Is this endpoint unused?
    JNZ     .enable                    ; Only enable it if it is used
    RET                                ; Quick exit if this endpoint is unused

; Jump here to enable an endpoint
.enable:
    PUSH    A                          ; Save the endpoint direction
    MOV     A, X                       ; We are using a JACC to dispatch to enable the interrupt
    ASL     A                          ;  
    JACC    .EP_INT_ENABLE             ;  
.EP_INT_ENABLE:
    JMP     .EP0IntEnable              ; Enable EP0
    JMP     .EP1IntEnable              ; Enable EP1
    JMP     .EP2IntEnable              ; Enable EP2
; Jump here to enable EP0 Interrupts
.EP0IntEnable:
    M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_EP0
    JMP     .cont
.EP1IntEnable:
    M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_EP1
    JMP     .cont
.EP2IntEnable:
    M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_EP2
; Jump or flow here to continue configuring the endpoint    
.cont:

    MOV     A, X
    INDEX   USB_USB_EP_BIT_LOOKUP
    XOR     A, FFh
    AND     [USB_EPDataToggle], A ; Clear the data toggle

    POP     A                          ; Get the endpoint direction back
    AND     A, USB_DIR_IN              ; Is it an IN endpoint?
    JNZ     .in                        ; Jump on IN
; Flow here for an OUT Endpoint
    MOV     REG[X+EP0MODE], USB_MODE_NAK_OUT ; NAK the endpoint
    MOV     [X+USB_EndpointAPIStatus], NO_EVENT_PENDING ; For the API
    RET
; Jump here for an IN Endpoint
.in:
    MOV     REG[X+EP0MODE], USB_MODE_NAK_IN ; NAK the endpoint
    MOV     [X+USB_EndpointAPIStatus], EVENT_PENDING ; For the API
    RET
;-----------------------------------------------------------------------------
;  USB 2nd Tier Dispactch Jump Tables for Standard Requests (based on bRequest)
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ;  USB 2nd Tier Dispactch Jump Table
;
;  DESCRIPTION:   The following tables dispatch to the Standard request handler
;                 functions.  (Assumes bmRequestType(5:6) is 0, Standard)
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
USB_DT_d2h_std_dev:
;-----------------------------------------------------------------------------
    jmp     USB_CB_d2h_std_dev_00
    jmp     USB_CB_d2h_std_dev_01
    jmp     USB_CB_d2h_std_dev_02
    jmp     USB_CB_d2h_std_dev_03
    jmp     USB_CB_d2h_std_dev_04
    jmp     USB_CB_d2h_std_dev_05
    jmp     USB_CB_d2h_std_dev_06
    jmp     USB_CB_d2h_std_dev_07
    jmp     USB_CB_d2h_std_dev_08

USB_DT_d2h_std_dev_End:
USB_DT_d2h_std_dev_Size: equ (USB_DT_d2h_std_dev_End-USB_DT_d2h_std_dev) / 2
USB_DT_d2h_std_dev_Dispatch::
    MOV    A, REG[USB_EP0DATA + bRequest]
    DISPATCHER USB_DT_d2h_std_dev, USB_DT_d2h_std_dev_Size, USB_Not_Supported 
;-----------------------------------------------------------------------------
USB_DT_h2d_std_dev:
;-----------------------------------------------------------------------------
    jmp     USB_CB_h2d_std_dev_00
    jmp     USB_CB_h2d_std_dev_01
    jmp     USB_CB_h2d_std_dev_02
    jmp     USB_CB_h2d_std_dev_03
    jmp     USB_CB_h2d_std_dev_04
    jmp     USB_CB_h2d_std_dev_05
    jmp     USB_CB_h2d_std_dev_06
    jmp     USB_CB_h2d_std_dev_07
    jmp     USB_CB_h2d_std_dev_08
    jmp     USB_CB_h2d_std_dev_09

USB_DT_h2d_std_dev_End:
USB_DT_h2d_std_dev_Size: equ (USB_DT_h2d_std_dev_End-USB_DT_h2d_std_dev) / 2
USB_DT_h2d_std_dev_Dispatch::

    MOV     A, REG[USB_EP0DATA + bRequest]
    DISPATCHER USB_DT_h2d_std_dev, USB_DT_h2d_std_dev_Size, USB_Not_Supported 

;-----------------------------------------------------------------------------
USB_DT_d2h_std_ifc:
;-----------------------------------------------------------------------------
    jmp     USB_CB_d2h_std_ifc_00
    jmp     USB_CB_d2h_std_ifc_01
    jmp     USB_CB_d2h_std_ifc_02
    jmp     USB_CB_d2h_std_ifc_03
    jmp     USB_CB_d2h_std_ifc_04
    jmp     USB_CB_d2h_std_ifc_05
    jmp     USB_CB_d2h_std_ifc_06
    jmp     USB_CB_d2h_std_ifc_07
    jmp     USB_CB_d2h_std_ifc_08
    jmp     USB_CB_d2h_std_ifc_09
    jmp     USB_CB_d2h_std_ifc_10
USB_DT_d2h_std_ifc_End:
USB_DT_d2h_std_ifc_Size: equ (USB_DT_d2h_std_ifc_End-USB_DT_d2h_std_ifc) / 2
USB_DT_d2h_std_ifc_Dispatch::
    CMP     [USB_Configuration], 0     ; Is the device configured?
    JNZ     .configured                ; Jump on configured
    JMP    _USB_Not_Supported          ; Stall the request if not configured
; Jump here if the device is configured
.configured:
    MOV     A, REG[USB_EP0DATA + bRequest]
    DISPATCHER USB_DT_d2h_std_ifc, USB_DT_d2h_std_ifc_Size, USB_Not_Supported 

;-----------------------------------------------------------------------------
USB_DT_h2d_std_ifc:
;-----------------------------------------------------------------------------
    jmp     USB_CB_h2d_std_ifc_00

USB_DT_h2d_std_ifc_End:
USB_DT_h2d_std_ifc_Size: equ (USB_DT_h2d_std_ifc_End-USB_DT_h2d_std_ifc) / 2
USB_DT_h2d_std_ifc_Dispatch::
    CMP     [USB_Configuration], 0     ; Is the device configured?
    JNZ     .configured                ; Jump on configured
    JMP    _USB_Not_Supported          ; Stall the request if not configured
; Jump here if the device is configured
.configured:
    MOV     A, REG[USB_EP0DATA + bRequest]
    DISPATCHER USB_DT_h2d_std_ifc, USB_DT_h2d_std_ifc_Size, USB_Not_Supported 

;-----------------------------------------------------------------------------
USB_DT_d2h_std_ep:
;-----------------------------------------------------------------------------
    jmp     USB_CB_d2h_std_ep_00

USB_DT_d2h_std_ep_End:
USB_DT_d2h_std_ep_Size: equ (USB_DT_d2h_std_ep_End-USB_DT_d2h_std_ep) / 2
USB_DT_d2h_std_ep_Dispatch::
    CMP     [USB_Configuration], 0     ; Is the device configured?
    JNZ     .configured                ; Jump on configured

    MOV     A, REG[USB_EP0DATA + wIndexHi] ; Is the request for EP0?
    MOV     [USB_t2], A                ; Use the UM temp var--Selector
    MOV     A, REG[USB_EP0DATA + wIndexLo] ;
    OR      [USB_t2], A                ; Use the UM temp var--Selector
    JZ      .ep0_request

    JMP    _USB_Not_Supported          ; Stall the request if not configured
; Jump here if the device is configured or EP0 request
.configured:
.ep0_request:
    MOV     A, REG[USB_EP0DATA + bRequest]
    DISPATCHER USB_DT_d2h_std_ep, USB_DT_d2h_std_ep_Size, USB_Not_Supported 

;-----------------------------------------------------------------------------
USB_DT_h2d_std_ep:
;-----------------------------------------------------------------------------
    jmp     USB_CB_h2d_std_ep_00
    jmp     USB_CB_h2d_std_ep_01
    jmp     USB_CB_h2d_std_ep_02
    jmp     USB_CB_h2d_std_ep_03

USB_DT_h2d_std_ep_End:
USB_DT_h2d_std_ep_Size: equ (USB_DT_h2d_std_ep_End-USB_DT_h2d_std_ep) / 2
USB_DT_h2d_std_ep_Dispatch::
    CMP     [USB_Configuration], 0     ; Is the device configured?
    JNZ     .configured                ; Jump on configured

    MOV     A, REG[USB_EP0DATA + wIndexHi] ; Is the request for EP0?
    MOV     [USB_t2], A                ; Use the UM temp var--Selector
    MOV     A, REG[USB_EP0DATA + wIndexLo] ;
    OR      [USB_t2], A                ; Use the UM temp var--Selector
    JZ      .ep0_request

    JMP    _USB_Not_Supported          ; Stall the request if not configured
; Jump here if the device is configured or EP0 request
.configured:
.ep0_request:
    MOV     A, REG[USB_EP0DATA + bRequest]
    DISPATCHER USB_DT_h2d_std_ep, USB_DT_h2d_std_ep_Size, USB_Not_Supported 

USB_GetTableEntry_Local_Std:
    LJMP    USB_GetTableEntry

USB_NoDataStageControlTransfer_Local_Std:
    LJMP    USB_NoDataStageControlTransfer

;-----------------------------------------------
; Add custom application code for routines 
; redefined by USB_APP_SUPPLIED in USB_HID.INC
;-----------------------------------------------

   ;@PSoC_UserCode_BODY_1@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom code below this banner
   ;---------------------------------------------------

   ;---------------------------------------------------
   ; Insert your custom code above this banner
   ;---------------------------------------------------
   ;@PSoC_UserCode_END@ (Do not change this line.)

; End of File USB_std.asm

⌨️ 快捷键说明

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