📄 usbfs_1_std.asm
字号:
ROMX ; First entry is the table size (only a byte)
CMP A, [USBFS_1_t2] ; Range check
JC USBFS_1_Not_Supported
; Refactored from the two loops below
MOV [USBFS_1_Configuration],[USBFS_1_t2] ; Save the config number
CMP [USBFS_1_t2], 0 ; Unconfigure?
JZ .unconfigure
; Flow here to configure the endpoints
MOV A, [USBFS_1_t1] ; Get the CONFIG_LOOKUP ROM Address MSB
MOV X, [USBFS_1_t1+1] ; Get the CONFIG_LOOKUP ROM Address LSB
INC X ; Point to the first table entry
ADC A, 0 ;
MOV [USBFS_1_t2], USBFS_1_t1 ; Set up the destination
CALL USBFS_1_GETWORD ; Get the pointer to the CONFIG_LOOKUP table
; ITempW has the address
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, [USBFS_1_t1] ; Get the CONFIG_LOOKUP ROM Address MSB
MOV X, [USBFS_1_t1+1] ; Get the CONFIG_LOOKUP ROM Address LSB
ROMX
INC [USBFS_1_t1+1] ; Point to the next
ADC [USBFS_1_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+USBFS_1_EndpointAPIStatus], NO_EVENT_ALLOWED ; For the API
MOV REG[X+USBFS_1_EP1MODE-1], USB_MODE_DISABLE ; Disable the endpoint
DEC X ; One more down
JNZ .unconfigure_next ; Don't unconfigure EP0
M8C_SetBank0
.done:
JMP USBFS_1_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USBFS_1_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, USBFS_1_TransferBuffer, NULL_PTR ; Reuse the transfer buffer
.ENDLITERAL
export USBFS_1_CB_d2h_std_ifc_00
USBFS_1_CB_d2h_std_ifc_00:
MOV [USBFS_1_TransferBuffer], 0 ; Zero the transfer buffer
MOV [USBFS_1_TransferBuffer+1], 0 ;
MOV [USBFS_1_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 USBFS_1_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USBFS_1_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, USBFS_1_TransferBuffer, NULL_PTR ; Reuse the transfer buffer
.ENDLITERAL
export USBFS_1_CB_d2h_std_ifc_10
USBFS_1_CB_d2h_std_ifc_10:
MOV A, REG[USBFS_1_EP0DATA+wIndexLo] ; Get the interface number
CMP A, 1h ; Valid interface number? (UM Parameter: NumInterfaces)
JNC USBFS_1_Not_Supported
MOV X, A ; The interface number is the index into alternates settings table
MOV A, [X + USBFS_1_InterfaceSetting] ; Save the current interface setting
MOV [USBFS_1_TransferBuffer], A ; into the transfer buffer
MOV [USBFS_1_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 USBFS_1_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USBFS_1_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 USBFS_1_CB_d2h_std_ep_00
USBFS_1_CB_d2h_std_ep_00:
MOV A, REG[USBFS_1_EP0DATA+wIndexLo] ; Get the endpoint number
AND A, ~USB_DIR_IN ; Strip off the direction bit
CMP A, USB_NUM_ENDPOINTS ; Range check
JNC USBFS_1_Not_Supported
MOV X, A ; The endpoint number is the index
MOV [USBFS_1_t2], 0 ; Use the UM temp var--Selector
MOV [USBFS_1_TransferBuffer + 1], 0 ; Use the UM Transfer Buffer
MOV A, [X + USBFS_1_EndpointStatus] ; Get the status
MOV [USBFS_1_TransferBuffer], A ; Save it in the report
MOV A,>GetStatusTransferDescrTable ; Get the ROM Address MSB
MOV X,<GetStatusTransferDescrTable ; Get the ROM Address LSB
JMP USBFS_1_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USBFS_1_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 USBFS_1_CB_h2d_std_ep_01
USBFS_1_CB_h2d_std_ep_01:
MOV A, REG[USBFS_1_EP0DATA+wValueLo] ; Get the feature selector
CMP A, USB_ENDPOINT_HALT ; Halt is the only selector defined for endpoints
JNZ USBFS_1_Not_Supported
MOV A, REG[USBFS_1_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 USBFS_1_Not_Supported
MOV X, A ; Endpoint number is the index
AND [X+USBFS_1_EndpointStatus], ~USB_ENDPOINT_STATUS_HALT ; Clear the endpoint halt
TST REG[USBFS_1_EP0DATA+wIndexLo], USB_DIR_IN ; IN or OUT endpoint?
M8C_SetBank1 ; For EP1_MODE register
JNZ .in
MOV REG[X + USBFS_1_EP1MODE - 1], USB_MODE_NAK_OUT ; NAK the endpoint
JMP .done
.in:
MOV REG[X + USBFS_1_EP1MODE - 1], USB_MODE_NAK_IN ; NAK the endpoint
.done:
M8C_SetBank0
JMP USBFS_1_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USBFS_1_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 USBFS_1_CB_h2d_std_ep_03
USBFS_1_CB_h2d_std_ep_03:
MOV A, REG[USBFS_1_EP0DATA+wValueLo] ; Get the feature selector
CMP A, USB_ENDPOINT_HALT ; Halt is the only selector defined for endpoints
JNZ USBFS_1_Not_Supported
MOV A, REG[USBFS_1_EP0DATA+wIndexLo] ; Get the Endpoint number
AND A, ~USB_DIR_IN ; Strip off the direction bit
CMP A, 0 ; Never halt the Control Endpoint
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -