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

📄 usbcode.asm

📁 一个全面介绍cy7c6372 里面包概了芯片的USB编程的代码和功能介绍.
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;IMPORTANT!!!!!!!!!!!!
;This is a BETA version of Firmware that has not been
;fully tested.  PLEASE keep this in mind and use this
;firmware as REFERENCE.


;=======================================================================================================
;       MODULE Decode Request
;=======================================================================================================
; 	Change History
;	-------------------------
;	Revision:		0.1
;	Created DGW November 1999
;	Code structure original. Code incorpoatates fragments from many sources plus new code.
;	Issue Date:		DRAFT
;
;=======================================================================================================
; Note that this module is designed to work with a ROM table of 255 bytes or less.
; ALWAYS Check the length of the ROM table. If it is too long then it is recommended to either reduce the 
; length of the string descritors and/or split the table into two tables.

DecodeRequest:
	mov a, [bmRequestType]  			; is this a standard request ?
	and a, 60h						; if not check if its a class request
	jnz ClassRequest

;===================================================================
; Decode Standard Request
;===================================================================

StandardRequest:
	mov a, [bRequest]				
	asl a							;multiply index by 2 for jump table
	cmp a, (end_standard_request_table - standard_request_table + 1)
	jnc SendStall					; check request is in range

	jacc standard_request_table
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

XPAGEOFF
standard_request_table:
	jmp	GetStatus
	jmp	ClearFeature
	jmp	SendStall					;reserved
	jmp	SetFeature				
	jmp	SendStall					;reserved
	jmp	SetAddress
	jmp	GetDescriptor
	jmp	SetDescriptor
	jmp	GetConfiguration
	jmp	SetConfiguration
	jmp	GetInterface
	jmp	SetInterface
end_standard_request_table:				;synch frame not supported as 63xxx does not support ISO
XPAGEON

;===================================================================
; Decode HID Class Request
;===================================================================

ClassRequest:
	cmp a, 20h					
	jnz VendorRequest					; if not a class request then check for a vendor request

	mov a, [bRequest]					; check request is in range
	asl a							; multiply index by 2 for jump table
	cmp a, (end_HID_request_table - HID_request_table + 1)
	jnc SendStall

	jacc HID_request_table				; jump to the routine that handles that request type

	db	00,00,00,00,00,00,00,00,00,00

XPAGEOFF
HID_request_table:				
	jmp	SendStall					;reserved
	jmp	GetReport
	jmp	GetIdle
	jmp	GetProtocol
	jmp	SendStall					;reserved
	jmp	SendStall					;reserved
	jmp	SendStall					;reserved
	jmp	SendStall					;reserved
	jmp	SendStall					;reserved
	jmp	SetReport
	jmp	SetIdle
	jmp	SetProtocol
end_HID_request_table:
XPAGEON

;===================================================================
; Decode Vendor Request
;===================================================================
; Frameworks does not support a vendor request; The user may insert 
; code to do so here

VendorRequest:
	jmp SendStall					;no vendor requests supported in Frameworks
	
;=======================================================================================================
;       Handle Request - Get Status
;=======================================================================================================
; Device, Interface and Endpoint are all valid recipients for this request. 
 
GetStatus:
      mov A, 2                        		; send two bytes
      mov [data_count], A

	mov a, [bmRequestType]				;check recipient, and handle accordingly
	cmp a, DEVICE_TO_HOST
	jz GetDeviceStatus

	cmp a, ENDPOINT_TO_HOST
	jz GetEndpointStatus

	cmp a, INTERFACE_TO_HOST
	jnz SendStall					;80, 81, 82 are only valid bmRequestTypes for this request 

;===================================================================
; Recipient = Interface
;===================================================================
; The interface status is a 16-bit value (two bytes) that is always 
; zero for both bytes.

GetInterfaceStatus:
      mov A, (get_interface_status_table - control_read_table)
      jmp SendRomData                     	; send interface status to host

;===================================================================
; Recipient = Device
;===================================================================
; The device status is a 16-bit value (two bytes) with only D[1:0]
; defined.  D0=0 specifies bus-powered, which never changes.  D1
; reflects the status of the device_remote_wakeup feature.  This
; feature can either be disabled (D1=0) or enabled (D1=1).

GetDeviceStatus:
      mov A, (get_dev_status_table - control_read_table)
;     add A, [remote_wakeup_status]   		; get correct remote wakeup **** not yet supported
      jmp SendRomData                     	; send device status to host

;===================================================================
; Recipient = Endpoint
;===================================================================
; The endpoint status is a 16-bit value (two bytes) with only one
; bit (D0) defined.  If D0=0, then the selected endpoint is not
; stalled.  If D0=1, then the selected endpoint is stalled.

GetEndpointStatus:
	iord EP1_MODE
	and a, STALL_B
	jz .Send
	mov a, (stalled - get_endpoint_status_table)	;EP1 is stalled

.Send:
      add A, (get_endpoint_status_table - control_read_table)
      jmp SendRomData                     	; send endpoint status to host

;=======================================================================================================
;       Handle Request - Clear Feature
;=======================================================================================================
; Endpoint and Device are supported recipients for this request. Interface is valid, but not supported.

ClearFeature:
	mov a, [bmRequestType]
	cmp a, HOST_TO_DEVICE
	jz ClearRemoteWakeup			

	cmp a, HOST_TO_ENDPOINT
	jnz SendStall					;00, 02 are only valid bmRequestTypes for this request 

;===================================================================
; Recipient = Endpoint
;===================================================================
; Clear the endpoint stall feature for the selected endpoint.  This
; should also set the data 0/1 bit to Data0 if endpoint one is selected.

ClearEndpointStall:
	mov A, [wValue]                 		; 
      cmp A, EP1_STALLED	         		; test for valid feature
      jnz SendStall                   		; stall unsupported features

      call NoDataControl            		; handshake with host

      iord EP1_MODE          			
      and A, ~STALL_B		; clear stall and data 0/1 bits
      iowr EP1_MODE		
      iord EP1_COUNT
      and a, ~DATA01_B
      iowr EP1_COUNT

      iord USB_SCR					; Set up EP1 to NAK INs 	
      and A,0EFh						; INs are only ACKed when new data is
      iowr USB_SCR			  		; ready.

      ret                             

;===================================================================
; Recipient = Device
;===================================================================
; Remote Wakeup is the only Device feature 

ClearRemoteWakeup:
	jmp SendStall					;**** not yet supported

	call NoDataControl            		; handshake with host

      mov A, DISABLE_REMOTE_WAKEUP    		; disable remote wakeup
      mov [remote_wakeup_status], A

      ret                             		

;=======================================================================================================
;       Handle Request - Set Feature
;=======================================================================================================
; Endpoint and Device are supported recipients for this request. Interface is valid, but not supported.

SetFeature:
	mov a, [bmRequestType]
	cmp a, HOST_TO_DEVICE
	jz SetRemoteWakeup			

	cmp a, HOST_TO_ENDPOINT
	jnz SendStall					;00, 02 are only valid bmRequestTypes for this request 

;===================================================================
; Recipient = Endpoint
;===================================================================
; Set the endpoint stall feature for the selected endpoint.  

SetEndpointStall:
      mov A, [wValue]                 		
      cmp A, EP1_STALLED	         		; test for valid feature
      jnz SendStall                   		; stall unsupported features

      call NoDataControl            		; handshake with host

      mov A, 80h                    		; stall endpoint one 
      iowr EP1_MODE
      iord EP_IE				; and reenable endpoint 1
      or A, EP1_IE
      or A, EP2_IE
      iowr EP_IE                
      ret                             		

;===================================================================
; Recipient = Device
;===================================================================
; Remote Wakeup is the only Device feature 
; If the device does not support remote wakeup then replace this code 
; with <jmp SendStall>

SetRemoteWakeup:
      mov A, [wValue]                 
      cmp A, REMOTE_WAKEUP		     		; test for valid feature
      jnz SendStall                   		; stall unsupported features

      call NoDataControl            		; handshake with host

      mov A, ENABLE_REMOTE_WAKEUP     		; enable remote internal wakeup variable
      mov [remote_wakeup_status], A
      ret                             

;=======================================================================================================
;       Handle Request - Set Address
;=======================================================================================================
; Device is the only valid recipient for this request.

SetAddress:
	mov a, [bmRequestType]
	cmp a, HOST_TO_DEVICE
	jnz SendStall

	mov a, [wValue]			;check that the address is in range
	and a, 80h			;valid range is 0 to 7F
	jnz SendStall			;

      call NoDataControl            	; handshake with host

.wait:
	iowr WDT
	iord EP0_MODE			; Wait for the ACK.
	and A, 10h			; must wait for ACK before changing address
	jz .wait			; as the ACK will be sent to the old address.

      mov A, [wValue]                 	; write new USB device address
      or A, 80h 
      iowr USB_DA         				; 
      ret                             	

;=======================================================================================================
;       Handle Request - Get Descriptor
;=======================================================================================================
; There are five standard descriptor types and 3 HID class descriptor types. The descriptor type is in 
; the high byte of wValue.  The descriptor index is in the low byte of wValue.  The standard request to 
; a device supports three of these types: device, configuration, and string.  
; The standard request does not support interface or endpoint descriptor types

GetDescriptor:
	mov a, [bmRequestType]
	cmp a, DEVICE_TO_HOST
	jnz GetClassDescriptor				; If recipient is not device, then check for Interface

      mov A, [wValueHi]               		
	asl a							; multiply index by 2 for jump table
	cmp a, (end_desc_type_table - desc_type_table + 1)
	jnc SendStall					; check that the descritor type is valid

	jacc desc_type_table

GetClassDescriptor:
	mov a, [bmRequestType]
	cmp a, INTERFACE_TO_HOST
	jnz SendStall					; only valid recipient is Interface

      mov A, [wValueHi]               		; load descriptor type
	and a, dfh						; mask class bit	

⌨️ 快捷键说明

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