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

📄 decode.a51

📁 u-boot for Linux platform. you can test it
💻 A51
字号:
; This module is common to all of the examples.
; It decodes the USB Setup Packets and generates appropriate responses.
; Interpretation of Reports is handled by MAIN
;
 	CSEG
ServiceSetupPacket:
	MOV	A, RequestType
	MOV	C, ACC.7		; Bit 7 = 1 means IO device needs to send data to PC Host
	MOV	SendData, C
	ANL	A, #01011100b		; IF RequestType[6.4.3.2] = 1 THEN goto BadRequest
	JNZ	BadRequest
	MOV	A, RequestType		; IF RequestType[1&0] = 1 THEN goto BadRequest
	MOV	C, ACC.0
	ANL	C, ACC.1
	JC	BadRequest
	JNB	ACC.5, NotB5		; IF RequestType[5] = 1 THEN RequestType[1,0] = [1,1]
	MOV	A, #00000011b
NotB5:	ANL	A, #00000011b		; Set CommandIndex[5,4] = RequestType[1,0]
	SWAP	A
	MOV	R7, A			; Save HI nibble of CommandIndex
					; Set CommandIndex[3,0] = Request[3,0]
	MOV	A, Request
	ANL	A, #11110000b		; Check if Request > 15
	JNZ	BadRequest
	MOV	A, Request
	ANL	A, #00001111b		; Only 13 are defined today, handle in table
	ORL	A, R7	
;	CALL	CorrectSubroutine	; goto CommandTable(CommandIndex)
CorrectSubroutine:			; Jump to the subroutine that DPTR is pointing to
	MOV	ReplyCount, #1		; Set up a default reply
	MOV	ReplyBuffer, #0
	MOV	ReplyBuffer+1, #0
	CLR	SetAddress		; Clear all flags
	CLR	STALL
	CLR	IsDescriptor
	MOV	DPTR, #CommandTable
	CALL	BumpDPTR		; Point to entry
	MOVX	A, @DPTR		; Get the offset
	MOV	DPTR, #Subroutines
	JMP 	@A+DPTR			; Go to the correct Subroutine

BadRequest:				; Decoded a Bad Request, STALL the Endpoint
	SETB	STALL
	RET
					; Support routines
NextDPTR:				; Returns (DPTR + byte DPTR is pointing to)
	MOVX	A, @DPTR
BumpDPTR:				; Returns (DPTR + ACC)
	ADD	A, DPL
	MOV	DPL, A
	JNC	Skip
	INC	DPH			; Need 16 bit arithmetic here
Skip:	RET

; Since the table only contains byte offsets, it is important that all these routines are
; within one page (100H) of Subroutines
; V3.0 - CommandTable moved outside of this one page limited space
CommandTable:
; First 16 commands are for the Device
	DB LOW(Device_Get_Status - Subroutines)
	DB LOW(Device_Clear_Feature - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Device_Set_Feature - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Set_Address - Subroutines)
	DB LOW(Get_Descriptor - Subroutines)
	DB LOW(Set_Descriptor - Subroutines)
	DB LOW(Get_Configuration - Subroutines)
	DB LOW(Set_Configuration - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
; Next 16 commands are for the Interface
	DB LOW(Interface_Get_Status - Subroutines)
	DB LOW(Interface_Clear_Feature - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Interface_Set_Feature - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Get_Class_Descriptor - Subroutines)
	DB LOW(Set_Class_Descriptor - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Get_Interface - Subroutines)
	DB LOW(Set_Interface - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
; Next 16 commands are for the Endpoint
	DB LOW(Endpoint_Get_Status - Subroutines)
	DB LOW(Endpoint_Clear_Feature - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Endpoint_Set_Feature - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Endpoint_Sync_Frame - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
; Next 16 commands are Class Requests
	DB LOW(Invalid - Subroutines)
	DB LOW(Get_Report - Subroutines)
	DB LOW(Get_Idle - Subroutines)
	DB LOW(Get_Protocol - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Set_Report - Subroutines)
	DB LOW(Set_Idle - Subroutines)
	DB LOW(Set_Protocol - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)
	DB LOW(Invalid - Subroutines)

Subroutines:
;
; Many requests are INVALID for this example
Get_Protocol:			; We are not a Boot device
Set_Protocol: 			; We are not a Boot device
Set_Descriptor:			; Our Descriptors are static
Set_Class_Descriptor:          	; Our Descriptors are static
Set_Interface:			; We only have one Interface
Get_Interface:			; We do not have an Alternate setting
Set_Idle:			; V3.0 Optional command, not supported
Get_Idle:			; V3.0 Optional command, not supported
Device_Set_Feature: 		; We have no features that can be set or cleared
Interface_Set_Feature: 		; We have no features that can be set or cleared
Endpoint_Set_Feature: 		; We have no features that can be set or cleared
Endpoint_Clear_Feature: 	; V3.0 We have no features that can be set or cleared
Device_Clear_Feature:		; We have no features that can be set or cleared 
Interface_Clear_Feature: 	; We have no features that can be set or cleared
Endpoint_Sync_Frame:		; We are not an Isonchronous device

Invalid:			; Invalid Request made, STALL the Endpoint
	SETB	STALL
Reply:	RET

Set_Address:			; Set the address that the SIE will respond to
	SETB	SetAddress
	RET

Set_Report:				; Host wants to sent us a Report. 
; The ONLY case in this example where host sends data to us
	JNB	Configured, Invalid	; Need to be Configured to do this command
	CALL	GetOutputReport		; Handled in EZUSB.A51
	JMP	ProcessOutputReport	; RETurn via this subroutine
Get_Report:				; Host wants a Report
	JNB	Configured, Invalid	; Need to be Configured to do this command 
	MOV	ReplyBuffer, #42H  	; Reply with a recognizable (arbitary) value
	RET
Get_Configuration:			; Respond with CurrentConfiguration
	MOV	ReplyBuffer, CurrentConfiguration
	RET	
Device_Get_Status:			; Only two bits of Device Status are defined
	MOV	ReplyBuffer, #1		; Bit 1=Remote Wakeup(=0), Bit 0=Self Powered(=1)
	RET
Interface_Get_Status:			; Interface Status is currently defined as 0
Endpoint_Get_Status:
        MOV	ReplyCount, #2		; Need a two byte 0 response
	RET
Set_Configuration:   			; Valid values are 0 and 1
	MOV	A, wValueLow
	JZ	Deconfigured
	DEC	A
	JNZ	Invalid
	SETB	Configured
	MOV	CurrentConfiguration, #1
	RET
Deconfigured:
	CLR	Configured
	MOV	CurrentConfiguration, A
	RET
Get_Descriptor:		   		; Host wants to know who/what we are
	SETB	IsDescriptor
	MOV	A, wValueHigh
	DEC	A			; Valid Values are 1, 2 and 3
	MOV	DPTR, #DeviceDescriptor
	JZ	ReturnLength
	DEC	A
	MOV	DPTR, #ConfigurationDescriptor
	JNZ	TryString
	MOV	A, #ConfigLength
	RET
TryString:
	DEC	A
	JNZ	Invalid
; Request is for a String Descriptor
	MOV	DPTR, #String0		; Point to String 0
	MOV	A, wValueLow		; Get String Index
NextString:
	JZ	ReturnLength
	MOV	R7, A			; Save String Index
	CALL	NextDPTR
	MOVX	A, @DPTR		; Get the String Length (= 0 means we're at Backstop)
	JZ	Invalid			; Asked for a string I don't have 
	MOV	A, R7
	DEC	A
	JMP	NextString		; Check if we are there yet
Get_Class_Descriptor: 			; Valid values are 21H, 22H, 23H for Class Request
	SETB	IsDescriptor
	MOV	A, wValueHigh
	CLR	C
	SUBB	A, #21H
	MOV	DPTR, #HIDDescriptor
	JZ	ReturnLength
	DEC	A
	MOV	DPTR, #ReportDescriptor
	JZ	ReturnRDlength
;	DEC	A			; This example does not use Physical Descriptors
;	JZ	Send_Physical_Descriptor
	JMP	Invalid
;
ReturnLength:
	MOVX	A, @DPTR		; Get Descriptor Length (first byte)
	RET
ReturnRDlength:				; Report Descriptor is different format
	MOV	A, #ReportLength
	RET
; Error check: this MUST be on within a page of Subroutines
WithinSamePage EQU $ - Subroutines	
;

⌨️ 快捷键说明

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