📄 usb_std.asm
字号:
;****************************************************************
; 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
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
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
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 ;
.LITERAL
.EP_INT_ENABLE:
jmp .EP0IntEnable ; Enable EP0
jmp .EP1IntEnable ; Enable EP1
jmp .EP2IntEnable ; Enable EP2
jmp .EP3IntEnable ; Enable EP1
jmp .EP4IntEnable ; Enable EP2
.ENDLITERAL
; Jump here to enable EP0 Interrupts
.EP0IntEnable:
M8C_EnableIntMask USB_INT_REG, USB_INT_EP0_MASK
jmp .contEP0
.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:
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
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_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:
;
;-----------------------------------------------------------------------------
.LITERAL
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
.ENDLITERAL
;-----------------------------------------------------------------------------
.LITERAL
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
.ENDLITERAL
;-----------------------------------------------------------------------------
.LITERAL
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::
mov A, REG[USB_EP0DATA + bRequest]
DISPATCHER USB_DT_d2h_std_ifc, USB_DT_d2h_std_ifc_Size, USB_Not_Supported
.ENDLITERAL
;-----------------------------------------------------------------------------
.LITERAL
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::
mov A, REG[USB_EP0DATA + bRequest]
DISPATCHER USB_DT_h2d_std_ifc, USB_DT_h2d_std_ifc_Size, USB_Not_Supported
.ENDLITERAL
;-----------------------------------------------------------------------------
.LITERAL
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::
mov A, REG[USB_EP0DATA + bRequest]
DISPATCHER USB_DT_d2h_std_ep, USB_DT_d2h_std_ep_Size, USB_Not_Supported
.ENDLITERAL
;-----------------------------------------------------------------------------
.LITERAL
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::
mov A, REG[USB_EP0DATA + bRequest]
DISPATCHER USB_DT_h2d_std_ep, USB_DT_h2d_std_ep_Size, USB_Not_Supported
.ENDLITERAL
; End of File USB_std.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -