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

📄 usb_std.asm

📁 Cypress 的VOIP DEMO 研究VOIP终端的朋友可以研究研究
💻 ASM
📖 第 1 页 / 共 4 页
字号:
    MOV     X, 0                       ; Start the index at 0, but we INC first
.configure_next:
    INC     X                          ; Do the next one
    PUSH    X                          ; Save the endpoint number
    MOV     A, [USB_t1]                ; Get the CONFIG_LOOKUP ROM Address MSB
    MOV     X, [USB_t1+1]              ; Get the CONFIG_LOOKUP ROM Address LSB
    ROMX
    INC     [USB_t1+1]                 ; Point to the next 
    ADC     [USB_t1], 0                ;
    POP     X
    CALL    ConfigureEP                ; X contains the EP number
                                       ; A contains the EP Direction
    MOV     A, X                       ; 
    CMP     A, USB_MAX_EP_NUMBER       ; Configure each of the endpoints
    JNZ     .configure_next            ; Do another one?
; Flow here when we are done
    JMP     .done

; Jump here to unconfigure the endpoints
.unconfigure:
    M8C_SetBank1	; _EP1MODE is in Bank 1
    MOV     X, USB_MAX_EP_NUMBER       ; Configure each of the endpoints
.unconfigure_next:
    MOV     [X+USB_EndpointAPIStatus], NO_EVENT_ALLOWED ; For the API
    MOV     REG[X+USB_EP1MODE-1], USB_MODE_DISABLE ; Disable the endpoint
    DEC     X                          ; One more down
    JNZ     .unconfigure_next          ; Don't unconfigure EP0
	M8C_SetBank0
.done:
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF


;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ifc_00
;
;  DESCRIPTION:   Get Interface Status
;
;****************************************************************
; STANDARD INTERFACE IN REQUEST: Get_Interface_Status
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | INTERFACE)    = 81h    
; bRequest       : GET_STATUS                     = 00h    
; wValue         : RESERVED                       = 0000h  
; wIndex         : INTERFACE                      = --xxh
; wLength        : SIZEOF_INTERFACE_STATUS        = 0002h  
; 
; The GET_INTERFACE_STATUS request returns status for the 
; specified interface.
;
;****************************************************************
;-----------------------------------------------------------------------------
;
;  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_ifc_00 & USB_UM_SUPPLIED)
.LITERAL
GetInterfaceStatusTransferDescrTable:
    TD_START_TABLE  1                  ; One entry
    TD_ENTRY        USB_DS_RAM, 2, USB_TransferBuffer, NULL_PTR  ; Reuse the transfer buffer
.ENDLITERAL
export  USB_CB_d2h_std_ifc_00
USB_CB_d2h_std_ifc_00:

    MOV     [USB_TransferBuffer], 0    ; Zero the transfer buffer
    MOV     [USB_TransferBuffer+1], 0  ; 

    MOV     [USB_t2], 0                ; Use the UM temp var--Selector
    MOV     A,>GetInterfaceStatusTransferDescrTable  ; Get the ROM Address MSB
    MOV     X,<GetInterfaceStatusTransferDescrTable  ; Get the ROM Address LSB

    JMP     USB_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ifc_10
;
;  DESCRIPTION:   Get Interface
;
;****************************************************************
; STANDARD INTERFACE IN REQUEST: Get_Interface
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | INTERFACE)    = 81h
; bRequest       : GET_INTERFACE                  = 0Ah    
; wValue         : RESERVED                       = 0000h  
; wIndex         : INTERFACE                      = xxxxh
; wLength        : SIZEOF_GET_INTERFACE           = 0001h  
; 
; The GET_INTERFACE request returns the selected alternate 
; setting for the specified interface. 
;
;****************************************************************
;-----------------------------------------------------------------------------
;
;  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_ifc_10 & USB_UM_SUPPLIED)
.LITERAL
GetInterfaceTransferDescrTable:
    TD_START_TABLE  1                  ; One entry
    TD_ENTRY        USB_DS_RAM, 1, USB_TransferBuffer, NULL_PTR  ; Reuse the transfer buffer
.ENDLITERAL
export  USB_CB_d2h_std_ifc_10
USB_CB_d2h_std_ifc_10:
    MOV     A, REG[USB_EP0DATA+wIndexLo]  ; Get the interface number
    CMP     A, 1h                      ; Valid interface number? (UM Parameter: NumInterfaces)
    JNC     USB_Not_Supported

    MOV     X, A                       ; The interface number is the index into alternates settings table

    MOV     A, [X + USB_InterfaceSetting]  ; Save the current interface setting
    MOV     [USB_TransferBuffer], A    ; into the transfer buffer

    MOV     [USB_t2], 0                ; Use the UM temp var--Selector
    MOV     A,>GetInterfaceTransferDescrTable  ; Get the ROM Address MSB
    MOV     X,<GetInterfaceTransferDescrTable  ; Get the ROM Address LSB

    JMP     USB_GetTableEntry_Local_Std
ENDIF


;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ep_00
;
;  DESCRIPTION:   Get Endpoint Status
;
;****************************************************************
; STANDARD ENDPOINT IN REQUEST: Get_Endpoint_Status
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | ENDPOINT)     = 82h    
; bRequest       : GET_STATUS                     = 00h    
; wValue         : RESERVED                       = 0000h  
; wIndex         : ENDPOINT                       = 00xxh
; 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?
    M8C_SetBank1	                      ; For EP1_MODE register
    JNZ     .in

    MOV     REG[X + USB_EP1MODE - 1], USB_MODE_NAK_OUT  ; NAK the endpoint
    JMP     .done    
.in:
    MOV     REG[X + USB_EP1MODE - 1], USB_MODE_NAK_IN  ; NAK the endpoint
.done:
	M8C_SetBank0
    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?
    M8C_SetBank1	                      ; For EP1_MODE register
    JNZ     .in

    MOV     REG[X + USB_EP1MODE - 1], USB_MODE_STALL_DATA_EP | USB_MODE_ACK_OUT  ; Stall the endpoint
    JMP     .done    
.in:
    MOV     REG[X + USB_EP1MODE - 1], USB_MODE_STALL_DATA_EP | USB_MODE_ACK_IN  ; Stall the endpoint
.done:        
	M8C_SetBank0
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ConfigureEP
;
;  DESCRIPTION:   Configure an endpoint
;
;  ARGUMENTS:    A contains the endpoint direction

⌨️ 快捷键说明

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