📄 usb_std.asm
字号:
jmp USB_GetTableEntry
ENDIF
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_CB_d2h_std_dev_08
;
; DESCRIPTION: Get Device Configuration
;
;****************************************************************
; STANDARD DEVICE IN REQUEST: Get_Device_Configuration
;****************************************************************
;
; bmRequestType : (IN | STANDARD | DEVICE) = 80h
; bRequest : GET_CONFIGURATION = 08h
; wValue : RESERVED = 0000h
; wIndex : RESERVED = 0000h
; wLength : SIZEOF_DEVICE_CONFIGURATION = 0001h
;
; The GET_DEVICE_CONFIGURATION request returns the currently
; selected device configuration number.
;
; request_value and request_index contain 0000h. request_length
; contains 0001h and the one-byte configuration number is returned
; in a separate data transfer.
;
;-----------------------------------------------------------------------------
;
; 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_dev_08 & USB_UM_SUPPLIED)
.LITERAL
GetConfigTransferDescrTable:
TD_START_TABLE 1 ; One entry
TD_ENTRY USB_DS_RAM, 1, USB_Configuration, NULL_PTR ; Current configuration
.ENDLITERAL
export USB_CB_d2h_std_dev_08
USB_CB_d2h_std_dev_08:
mov [USB_t2], 0 ; Use the UM temp var--Selector
mov A,>GetConfigTransferDescrTable ; Get the ROM Address MSB
mov X,<GetConfigTransferDescrTable ; Get the ROM Address LSB
jmp USB_GetTableEntry
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_CB_h2d_std_dev_01
;
; DESCRIPTION: Clear Device Feature
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Clear_Device_Feature
;****************************************************************
;
; bmRequestType : (OUT | STANDARD | DEVICE) = 00h
; bRequest : CLEAR_FEATURE = 01h
; wValue : FEATURE_SELECTOR = --xxh
; wIndex : RESERVED = 0000h
; wLength : RESERVED = 0000h
;
; The CLEAR_DEVICE_FEATURE request disables a particular feature
; for a device. The only feature supported for a device is the
; REMOTE_WAKEUP 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_dev_01 & USB_UM_SUPPLIED)
export USB_CB_h2d_std_dev_01
USB_CB_h2d_std_dev_01:
mov A, REG[USB_EP0DATA+wValueLo] ; Get the Feature Selector
; Check against valid features
; for device receipient
cmp A, USB_DEVICE_REMOTE_WAKEUP ; Only remote wakeup is defined for clear
jnz USB_Not_Supported ;
and [USB_DeviceStatus], ~USB_DEVICE_STATUS_REMOTE_WAKEUP
jmp USB_NoDataStageControlTransfer
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_CB_h2d_std_dev_03
;
; DESCRIPTION: Set Device Featue
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Set_Device_Feature
;****************************************************************
;
; bmRequestType : (OUT | STANDARD | DEVICE) = 00h
; bRequest : SET_FEATURE = 03h
; wValue : FEATURE_SELECTOR = --xxh
; wIndex : RESERVED = 0000h
; wLength : RESERVED = 0000h
;
; The SET_DEVICE_FEATURE request enables a particular feature
; on a device. The only feature supported for a device is the
; REMOTE_WAKEUP 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_dev_03 & USB_UM_SUPPLIED)
export USB_CB_h2d_std_dev_03
USB_CB_h2d_std_dev_03:
mov A, REG[USB_EP0DATA+wValueLo] ; Get the Feature Selector
; Check against valid features
; for device receipient
cmp A, USB_DEVICE_REMOTE_WAKEUP ; Remote wakeup?
jz .remote_wakeup
cmp A, USB_TEST_MODE ; Test Mode
jz .test_mode
; Flow here for any other selector is invalid for device receipient
jmp USB_Not_Supported
; Jump here to enable remote wake up
.remote_wakeup:
OR [USB_DeviceStatus], USB_DEVICE_STATUS_REMOTE_WAKEUP
jmp .finish
; Jump here to enable test mode
.test_mode:
jmp USB_Not_Supported
.finish:
jmp USB_NoDataStageControlTransfer
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_CB_h2d_std_dev_05
;
; DESCRIPTION: Set Device Address
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Set_Device_Address
;****************************************************************
;
; bmRequestType : (OUT | STANDARD | DEVICE) = 00h
; bRequest : SET_ADDRESS = 05h
; wValue : DEVICE_ADDRESS = 00xxh
; wIndex : RESERVED = 0000h
; wLength : RESERVED = 0000h
;
; The SET_DEVICE_ADDRESS request sets the USB device address
; for all future USB accesses.
;
;****************************************************************
;
;-----------------------------------------------------------------------------
;
; 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_dev_05 & USB_UM_SUPPLIED)
export USB_CB_h2d_std_dev_05
USB_CB_h2d_std_dev_05:
mov [USB_fDataPending], USB_ADDRESS_CHANGE_PENDING
mov A, REG[USB_EP0DATA+wValueLo]
mov [USB_TransferBuffer],A
jmp USB_NoDataStageControlTransfer
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_CB_h2d_std_dev_09
;
; DESCRIPTION: Set Configuration
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Set_Device_Configuration
;****************************************************************
;
; bmRequestType : (OUT | STANDARD | DEVICE) = 00h
; bRequest : SET_CONFIGURATION = 09h
; wValue : CONFIGURATION_VALUE = --xxh
; wIndex : RESERVED = 0000h
; wLength : RESERVED = 0000h
;
; The SET_DEVICE_CONFIGURATION request selects a device
; configuration to be activated as the current configuration.
;
;****************************************************************
;-----------------------------------------------------------------------------
;
; 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_dev_09 & USB_UM_SUPPLIED)
export USB_CB_h2d_std_dev_09
USB_CB_h2d_std_dev_09:
call USB_GET_DEVICE_TABLE_ENTRY ; Get the selected device
mov [USB_t2],USB_t1 ; Set the GETWORD destination
call USB_GETWORD ; Get the pointer to the CONFIG_LOOKUP table
; ITempW has the address
mov A, REG[USB_EP0DATA+wValueLo] ; Get the configuration number
mov [USB_t2],A ; Save it
mov A, [USB_t1] ; Get the CONFIG_LOOKUP ROM Address MSB
mov X, [USB_t1+1] ; Get the CONFIG_LOOKUP ROM Address LSB
romx ; First entry is the table size (only a byte)
cmp A, [USB_t2] ; Range check
jc USB_Not_Supported
; Refactored from the two loops below
mov [USB_Configuration],[USB_t2] ; Save the config number
cmp [USB_t2], 0 ; Unconfigure?
jz .unconfigure
; Flow here to configure the endpoints
mov A, [USB_t1] ; Get the CONFIG_LOOKUP ROM Address MSB
mov X, [USB_t1+1] ; Get the CONFIG_LOOKUP ROM Address LSB
inc X ; Point to the first table entry
adc A, 0 ;
mov [USB_t2], USB_t1 ; Set up the destination
call USB_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, [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
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:
Ljmp USB_NoDataStageControlTransfer
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
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, 1 ; 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
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_CB_d2h_std_ep_00
;
; DESCRIPTION: Get Endpoint Status
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -