📄 usb_drv.asm
字号:
TD_INDEX_TO_OFFSET USB_t2 ; Convert the index
SWAP A, X
ADD A, [USB_t2]
SWAP A, X
ADC A, 0 ; A:X now points to the descriptor table entry we want
; Flow here to load the Transfer Descriptor (TD_ENTRY)
MOV [USB_t2], USB_CurrentTD ; Use Temp as MVI pointer
CALL USB_GETBYTE ; Get the descriptor data source
CALL USB_GETWORD ; Get the descriptor size
CALL USB_GETWORD ; Get the descriptor address
CALL USB_GETWORD ; Get the Status Pointer
; Dispatch to InitControlRead or InitControlWrite based on d2h/h2d in the request
MOV A, REG[USB_EP0DATA+bmRequestType]; Get bmRequestType
AND A,0x80 ; Control Read or Write
JZ .control_write
JMP USB_InitControlRead
.control_write:
JMP USB_InitControlWrite
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_LOOKUP
;
; DESCRIPTION: Returns the address of an entry in a lookup table (LT_ENTRY)
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: A:X Point to the lookup table
; USB_t2 contain the table index
;
; RETURNS: Address of the LT_ENTRY in A:X
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT USB_LOOKUP
USB_LOOKUP:
INC X ; Point to the first table entry
ADC A, 0 ;
LT_INDEX_TO_OFFSET USB_t2 ; Convert the index
SWAP A, X
ADD A, [USB_t2] ;
SWAP A, X
ADC A, 0
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_GETWORD/USB_GETBYTE
;
; DESCRIPTION: Get a word value from ROM
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: A:X is the ROM Address
; USB_t2 is the destination address
;
; RETURNS: USB_t1
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
; USES USB_t2
; A:X points to the subsequent locaction ROM location
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT USB_GETWORD
USB_GETWORD:
PUSH A ; Don't loose the pointer MSB
ROMX ; Data source flag
MVI [USB_t2], A ; Save the data source
POP A ; Get the MSB back
INC X ; Point to the next entry
ADC A, 0 ;
EXPORT USB_GETBYTE
USB_GETBYTE:
PUSH A ; Don't loose the pointer MSB
ROMX ; Data source flag
MVI [USB_t2], A ; Save the data source
POP A ; Get the MSB back
INC X ; Point to the next entry
ADC A, 0 ;
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_GET_DEVICE_TABLE_ENTRY
;
; DESCRIPTION: Get the address of the current DEVICE_TABLE entry
; Not intended for use by C fucntions
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS: A:X points the the current DEVICE_TABLE entry
; Carry flag is set if the current device index is out of range
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT USB_GET_DEVICE_TABLE_ENTRY
USB_GET_DEVICE_TABLE_ENTRY:
MOV [USB_t2], [USB_bCurrentDevice] ; Use the UM temp var--Selector
MOV A,>USB_DEVICE_LOOKUP ; Get the ROM Address MSB
MOV X,<USB_DEVICE_LOOKUP ; Get the ROM Address LSB
ROMX ; First entry is the table size (only a byte)
CMP A, [USB_t2] ; Range check
MOV A,>USB_DEVICE_LOOKUP ; Get the ROM Address MSB
JC .exit
; Flow here if the index is valid
CALL USB_LOOKUP ; Look up the configuration
; Jump or flow here on exit
.exit:
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_GET_CONFIG_TABLE_ENTRY
;
; DESCRIPTION: Get the address of the current DEVICE_TABLE entry
; Not intended for use by C fucntions
; Does not do range checking on
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS: A:X points the the current CONFIG_TABLE entry
; Carry flag is set if the current device index is out of range
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
EXPORT USB_GET_CONFIG_TABLE_ENTRY
USB_GET_CONFIG_TABLE_ENTRY:
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
; A:X Points to the CONFIG_LOOKUP, so get the current entry
MOV [USB_t2], [USB_Configuration] ; Get the configuration number
DEC [USB_t2] ; We don't populate the 0th entry
CALL USB_LOOKUP ; Look up the configuration
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_UpdateStatusBlock
;
; DESCRIPTION: Update the Completion Status Block for a Request. The
; block is updated with the completion code from the
; argument (A) and the _TransferByteCount.
;
; The StatusBlock Pointer (_StatusBlockPtr) is set to NULL (0)
; to make sure no other updates are made to the StatusBlock by
; the USB User Module.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: A contains the Completion Status Code
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
USB_UpdateStatusBlock:
MOV X, [USB_StatusBlockPtr + 1];
SWAP A, X ; Don't loose the completion code
CMP A, 0 ; NULL?
JZ .done ; No update on NULL
; Flow here to update the VSR Completion Status Block
SWAP A, X ; Completion code A, Pointer in X
MOV [X + 0], A ; Update the completion Code
MOV A, [USB_TransferByteCount] ; Actual Byte Count MSB
MOV [X + 1], A
MOV A, [USB_TransferByteCount + 1] ; Actual Byte Count LSB
MOV [X + 2], A
MOV [USB_StatusBlockPtr + 1], 0; Clear the Block Pointer
.done:
RET ; All done
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_InitializeStatusBlock
;
; DESCRIPTION: Initialize the Completion Status Block for a Request.
; The completion code is set to USB_XFER_IDLE.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
USB_InitializeStatusBlock:
MOV A, [USB_StatusBlockPtr + 1];
CMP A, 0 ; NULL?
JZ .done ; No update on NULL
; Flow here to initialize the Completion Status Block
SWAP A, X ; Pointer in X
MOV [X + 0], USB_XFER_IDLE ; Initialize the completion code (0)
MOV [USB_TransferByteCount], 0 ; Clear the byte count
MOV [USB_TransferByteCount + 1], 0 ;
.done:
RET ; All done
;-----------------------------------------------------------------------------
; FUNCTION NAME: ; USB 1st Tier Dispactch Jump Table (based on bmRequestType)
;
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
MACRO BMREQUEST_DISPATCH
IF (USB_CB_@0_@1_@2 & 1)
jmp USB_DT_@0_@1_@2_Dispatch
ELSE
jmp USB_Not_Supported_Local_Drv
ENDIF
ENDM
USB_DT_bmRequestType::
BMREQUEST_DISPATCH h2d,std,dev
BMREQUEST_DISPATCH h2d,std,ifc
BMREQUEST_DISPATCH h2d,std,ep
BMREQUEST_DISPATCH h2d,std,oth
BMREQUEST_DISPATCH h2d,cls,dev
BMREQUEST_DISPATCH h2d,cls,ifc
BMREQUEST_DISPATCH h2d,cls,ep
BMREQUEST_DISPATCH h2d,cls,oth
BMREQUEST_DISPATCH h2d,vnd,dev
BMREQUEST_DISPATCH h2d,vnd,ifc
BMREQUEST_DISPATCH h2d,vnd,ep
BMREQUEST_DISPATCH h2d,vnd,oth
BMREQUEST_DISPATCH h2d,rsv,dev
BMREQUEST_DISPATCH h2d,rsv,ifc
BMREQUEST_DISPATCH h2d,rsv,ep
BMREQUEST_DISPATCH h2d,rsv,oth
BMREQUEST_DISPATCH d2h,std,dev
BMREQUEST_DISPATCH d2h,std,ifc
BMREQUEST_DISPATCH d2h,std,ep
BMREQUEST_DISPATCH d2h,std,oth
BMREQUEST_DISPATCH d2h,cls,dev
BMREQUEST_DISPATCH d2h,cls,ifc
BMREQUEST_DISPATCH d2h,cls,ep
BMREQUEST_DISPATCH d2h,cls,oth
BMREQUEST_DISPATCH d2h,vnd,dev
BMREQUEST_DISPATCH d2h,vnd,ifc
BMREQUEST_DISPATCH d2h,vnd,ep
BMREQUEST_DISPATCH d2h,vnd,oth
BMREQUEST_DISPATCH d2h,rsv,dev
BMREQUEST_DISPATCH d2h,rsv,ifc
BMREQUEST_DISPATCH d2h,rsv,ep
BMREQUEST_DISPATCH d2h,rsv,oth
USB_DT_End:
USB_DT_Size: equ (USB_DT_End-USB_DT_bmRequestType) / 2
USB_bmRequestType_Dispatch::
DISPATCHER USB_DT_bmRequestType, USB_DT_Size, USB_Not_Supported_Local_Drv
USB_Not_Supported_Local_Drv:
LJMP USB_Not_Supported
;-----------------------------------------------
; Add custom application code for routines
;-----------------------------------------------
;@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_drv.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -