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

📄 usb_std.asm

📁 Cypress 的VOIP DEMO 研究VOIP终端的朋友可以研究研究
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;                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
    JMP     .EP3IntEnable              ; Enable EP3
    JMP     .EP4IntEnable              ; Enable EP4

; Jump here to enable EP0 Interrupts
.EP0IntEnable:
    M8C_EnableIntMask USB_INT_REG, USB_INT_EP0_MASK
;    JMP   .exit2
    JMP   .cont
.EP1IntEnable:
    M8C_EnableIntMask USB_INT_REG, USB_INT_EP1_MASK
    JMP   .cont
.EP2IntEnable:
    M8C_EnableIntMask USB_INT_REG, USB_INT_EP2_MASK
    JMP   .cont
.EP3IntEnable:
    M8C_EnableIntMask USB_INT_REG, USB_INT_EP3_MASK
    JMP   .cont
.EP4IntEnable:
    M8C_EnableIntMask USB_INT_REG, USB_INT_EP4_MASK  
	JMP   .cont

; Jump or flow here to continue configuring the endpoint    
;.contEP0:
;    POP   A                           ; Get the endpoint direction back
;    AND   A, USB_DIR_IN               ; Is it an IN endpoint?
;    JNZ   .inEP0                      ; Jump on IN
; Flow here for an OUT Endpoint
;    MOV   [USB_TempMode], USB_MODE_NAK_OUT ; NAK the endpoint
;    JMP   .exit2
; Jump here for an IN Endpoint
;.inEP0:
;    MOV   [USB_TempMode], USB_MODE_NAK_IN ; NAK the endpoint
;	JMP   .exit2
.cont:
    MOV     A, X	                      ; Get the endpoint number from X
    INDEX   USB_USB_EP_BIT_LOOKUP	     ; Find bit position for endpoint
    XOR     A, FFh
    AND     [USB_EPDataToggle], A ; Clear the data toggle for this endpoint

; if endpoint 0 set EP0MODE
; then exit
;    MOV     A, X	                     ; Get the endpoint number from X
;    CMP     A, EP0	                   ; Is this endpoint zero?
;    JNZ     .enable                   ; Only enable it if it is used

    M8C_SetBank1
    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+USB_EP1MODE-1], USB_MODE_NAK_OUT ; NAK the endpoint
    MOV   [X+USB_EndpointAPIStatus], NO_EVENT_PENDING ; For the API
    JMP   .exit1
; Jump here for an IN Endpoint
.in:
    MOV   REG[X+USB_EP1MODE-1], USB_MODE_NAK_IN ; NAK the endpoint
; Jump or flow here to set the API event and exit    
.exit1:
	M8C_SetBank0
.exit2:
;    MOV   [X+USB_EPDataToggle], 0      ; Clear all EP data toggles?  Is this right?
    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]
    
   ;---------------------------------------------------
   ;@PSoC_UserCode_BODY_2@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom code below this banner
   ;---------------------------------------------------
   
   
	cmp 	A, USB_SET_INTERFACE
	jnz		NotSetInterface
	
	; Get the interface number
	mov		A, REG[USB_EP0DATA+wIndexLo]
	cmp		A, 2
	jnz		SetupInInterface
	
SetupOutInterface:
    mov   	A, REG[USB_EP0DATA+wValueLo] ; Get the alternate setting
    ; A = 0 - go to zero bandwidth setting
    ; A = 1 - normal operation

;rwf    mov [_OutInterfaceEnabled], a
    ; We don't use an interrupt for the OUT endpoint, so we don't need to worry about that
    jmp AltDone

SetupInInterface:
    mov   	A, REG[USB_EP0DATA+wValueLo] ; Get the alternate setting
    ; A = 0 - go to zero bandwidth setting
    ; A = 1 - normal operation
;rwf    mov [_InInterfaceEnabled], a
    cmp a, 1
    jnz DisableInInterrupt
    jmp AltDone
DisableInInterrupt: 
;ndx  	and reg[USB_INT_REG], ~USB_INT_EP1_MASK   
  	  	
AltDone:
    jmp  	USB_NoDataStageControlTransfer

NotSetInterface:
   

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

    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 + -