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

📄 std1.asm

📁 基于HT82K96E的usb鼠标实现源程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
                MOV     A,LOW GetHIDDes    		;Save Return Address
                MOV     ReturnAddr,A          	;to ReturnAddr
                JMP     GetTableLength
;----------------------------------------------------------------------------------------------

GetHIDDes:
                ;HID
				call	get_HID_des_adr
                MOV     TBLP,A                  ;  configuration
                MOV     A,LOW GetEndpointDes    ;Set Return Address
                MOV     ReturnAddr,A          	;  to ReturnAddr
                JMP     GetTableLength
;----------------------------------------------------------------------------------------------

GetEndpointDes:
                ;Endpoint
				call	get_endpt_des_adr
                MOV     TBLP,A                  ;  configuration

				MOV		A,LOW EndSend

				sz		des_count.0				;
				jmp		exit_of_ednpointDes
				mov		a,GetInterfaceDes
exit_of_ednpointDes:
                MOV     ReturnAddr,A          	;  to ReturnAddr
				inc		des_count
                JMP     GetTableLength
;----------------------------------------------------------------------------------------------

EndSend:
                sz     	bFLAG_RsqF
                set     bFLAG_SndFC 			;clear continue send flag

				SZ      FIFO_SendLen
                jmp    	out_of_RequestResponse         ;Responde
				jmp		SendHandshake

out_of_RequestResponse:
				set		bwait_setup
				jmp		RequestResponse

GetEnd:
                JMP     ExitExt


;Class-----------------------------------------------------------------------
GetHID:
				MOV		a,FIFO_wIndexL			;
				mov		des_count,a
				call	get_HID_des_adr
				MOV     TBLP,A                  ;HID
                MOV     A,LOW EndSend          	;Set Return Address
                MOV     ReturnAddr,A          	;to ReturnAddr
				jmp		ReadTableAndSendcnf	

;----------------------------------------------------------------------------------------------
				                
GetEntity:
				MOV		a,FIFO_wIndexL			;
				mov		des_count,a
				call	get_entity_des_adr
                MOV     TBLP,A                  ;  Entity
                MOV     A,LOW EndSend           ;Set Return Address
                MOV     ReturnAddr,A          	;  to ReturnAddr
                JMP     ReadEntityAndSendCnf    ;Read Entity table
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ReadTASTag:
                SET     bFLAG_RsqF	;Send Request
ReadNextCnfLp:
                CLR     bFLAG_SndFC ;clear continue send flag
                SZ      TableLength             ;Finished read ?
                JMP     ReadAgain               ;No

;Write next descriptor
                MOV     A,ReturnAddr          	;Get return address
;!!!!! Need in same page
std_des_end_pcl:
                MOV     PCL,A                   ;  & return
                ;Return
;----------------------------------------------------------------------------------------------
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SetFeature:
                SZ      FIFO_wValueH          	;wValueH == 0 ?
                JMP		ToStallPipe0            ;No

                SZ      FIFO_wIndexH          	;wIndexH == 0 ?
                JMP		ToStallPipe0            ;No

                MOV     A,FIFO_Type           	;Type (Device, Interface or
                AND     A,Setup_Rev             ;   Endpoint)
                MOV     TEMP,A                	;
                SUB     A,04H                   ;Over 4 item ?
                SZ      Z                       ;
                JMP		ToStallPipe0            ;Yes
;!!!!! Need in same page
                MOV     A,TEMP                	;
set_feature_pcl_5:
                ADDM    A,PCL
                JMP     DeviceStatusSF
                JMP     TostallPipe0
                JMP     EndpointStatusSF
                JMP		ToStallPipe0
;-----------------------------------------------------------------------------
EndpointStatusSF:                               ;clear stall flag
                SZ      FIFO_wValueL          	;ENDPOINT_STALL = 0 ?
                JMP		ToStallPipe0            ;No

;Check	Endpoint Number
;				snz		fifo_windexL.7
;				jmp		ToStallpipe0

                MOV     A,FIFO_wIndexL        	;Get endpoint number
				and		a,01111111b
				SUB		A,FIFO_temp
				SZ		C
				JMP		ToStallPipe0

                MOV     A,FIFO_wIndexL        	;Get endpoint number
                AND     A,0FH                   ;  Ignore direction
				call	GetPipeBit
                CALL    SetStall                ;Set endpoint stall
                JMP     SendHandshake           ;send handshake flag
;-----------------------------------------------------------------------------
DeviceStatusSF:
                MOV     A,FIFO_wValueL        	;DEVICE_REMOTE_WAKEUP = 1 ?
                XOR     A,01H                   ;
                SNZ     Z                       ;
                JMP		ToStallPipe0            ;No

                SZ      FIFO_wIndexL          	;Is wIndex == 0 ?
                JMP		ToStallPipe0            ;No
       ;enable remote wakeup           			;Yes
                SET     bRmtWakeup   	;enable remote wakeup (flag)
				rla		cmd_addr
				and		a,11111110b
				mov		fifo_addr,a
                SET     ADDR_Wake  	;Set remote wakeup flag
SetAddrWake:
                MOV     A,USB_ADDR_WAKE     	;Address & Remote wakeup address
                MOV     MP1,A               	;
                MOV     A,FIFO_ADDR       		;Write to Address Register
                MOV     R1,A                	;
                JMP     SendHandshake       	;send handshake flag
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SetConfiguration:  			;(ok)
				mov		a,1
				sub		a,FIFO_wValueL			;1 - FIFO_wValueL 
				snz		c
				jmp		ToStallPipe0			; other value except 0,1
				clr		baddr_state	
				snz		z						;fifo_wvaluel=1 ?
				set		baddr_state					

				mov		a,11111000b
				mov		STALL,a
                MOV     A,USB_STALL             ;
                MOV     MP1,A                   ;
                CLR     R1                      ;
                CLR     bFLAG_HvRpt 			;reset to nonreport

				sz		FIFO_wvalueL
				jmp		set_cfg
				clr		bcfgvalue
                JMP     SendHandShake

set_cfg:
				set		bcfgvalue
                JMP     SendHandShake

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GetDescriptor:  ;No check bmRequestType D4..0
                ;Check bmRequestType direction
                SNZ     FIFO_Type.@Setup_D    	;device to host ?
                JMP		ToStallPipe0            ;No:Error

				MOV		A,FIFO_Type				;only (device,interface & endpoint)
				AND		A,Setup_Rev
				SUB		A,03H
				SZ		C
				JMP		ToStallPipe0

				mov		a,fifo_wlengthh
				mov		lengthh,a
				mov		a,fifo_wlengthl
				mov		lengthl,a
				MOV		A,LOW EndSend
                MOV     ReturnAddr,A  

				MOV		A,FIFO_Type
				and		a,00011110b
				snz		z
				jmp		Tostallpipe0

				clr		brd_h_table
				clr		des_count
				sz		fifo_type.0
                JMP     ClassDst_Interface      ;   Class (new)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

StandardDst:
                MOV     A,FIFO_wValueH        	;Descriptor
                AND     A,wValueH_Dst           ;  Stanard, Class & Vendor
                MOV     TEMP,A                	;
                SUB     A,04H                   ;Over 4 item ?
                SZ      C                       ;
                JMP		ToStallPipe0            ;Yes
                MOV     A,TEMP
std_device_pcl_5:
                ADDM    A,PCL
                JMP		ToStallPipe0            ;Reserve
                JMP     GetDeviceDes            ;Get device descriptor
                JMP     GetConfigurationDes     ;Get configuration descriptor
                JMP     GetstringDes           	;Get string descriptor

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


GetTableBeg:
                MOV     A,OFFSET FIFO_OUT1  ;Let MP0 pointer to FIFO_OUT1
                MOV     MP0,A           	;
                CLR     FIFO_SendLen       	;Send data length = 0
;Check whether all data is written
GetTableLp:
				sz		tablelength			;check whether out of number to send
				jmp		read_data_again		
				MOV		A,LOW EndSend
                MOV     ReturnAddr,A 
				ret
;----------------------------------------------------------------------------------------------
read_data_again:

				snz		brd_h_table								
				jmp		read_L_table_byte
;read_H_byte
				clr		brd_h_table
				TABRDL	R0
				INC		TBLP
				mov		a,tblh
				and		a,00111111b
				xor		a,3FH
				sz		z
				jmp		read_data_again			;GetTableTag	
				mov		a,tblh
				and		a,00111111b
				mov		R0,a
				jmp		read_next_table
read_L_table_byte:
				set		brd_h_table
                TABRDL  R0          		;Get table and write FIFO_OUTx
read_next_table:
                INC     MP0         		;Update memory pointer 0
                INC     FIFO_SendLen  		;Update send FIFO length
				sz		lengthl
				jmp		skip_check_lengthh	
				sz		lengthH
				jmp		check_length_data
out_descript:								;out_of_number to send
				MOV		A,LOW EndSend
                MOV     ReturnAddr,A 					
				jmp		get_table_lp
skip_check_lengthh:
				dec		lengthl
get_table_lp:
                SDZ     TableLength 		;end_of_Tablelength
                JMP     GetTableTag
                RET

check_length_data:
				set		lengthl
				dec		lengthH
				jmp		get_table_lp		


;Check whether FIFO_SIZE data has written
GetTableTag:
                MOV     A,FIFO_SendLen     	;
                XOR     A,FIFO_SIZE         ;
                SNZ     Z                   ;
                JMP     GetTableLp          ;No
                RET							;FIFO FULL





;----------------------------------------------------------------------------------------------

;stack 1
;!!!!! Must in same page with caller
ReadEntityAndSendCnf:
				MOV		a,FIFO_wIndexL			;
				mov		des_count,a
				call	get_entity_length

                MOV     TableLength,A         	; in entity table)
				jmp		SendCnf

;----------------------------------------------------------------------------------------------
;stack 1
ReadTableAndSendCnf:
                TABRDL  TableLength    			;table length from TBLP
SendCnf:
				call	gettablenolength
				call	GetTableBeg
	            JMP     ReadNextXX
;----------------------------------------------------------------------------------------------
;input point for get the next table data
GetTableLength:
				clr		brd_h_table
                TABRDL  TableLength   			;table length
                CALL    GetTableNoLength        ;
gettablelength_cont:
                SZ      bFLAG_RsqF	
                JMP     ReadAgain
                CALL    GetTableLp
                JMP     ReadNextXX
;----------------------------------------------------------------------------------------------
;out_of_send_data_subroutine
ReadAgain:
				clr     bFLAG_RsqF
                SET     bFLAG_SndFC 			;Set continue send flag
                MOV     A,TBLP                  ;Save TBLP
                MOV     FIFO_TBLP,A             ;
                JMP     RequestResponse		

;----------------------------------------------------------------------------------------------
;input point of the get next 8-byte table data
ReadNextCnf:
                MOV     A,FIFO_TBLP           	;Restore TBLP
                MOV     TBLP,A                  ;
                CALL    GetTableBeg             ;Read next

;Check Whether FIFO data is FULL
ReadNextXX:
                MOV     A,FIFO_SendLen        	;FIFO full ?
                XOR     A,FIFO_SIZE             ;
                SZ      Z                       ;
                JMP     ReadTASTag              ;Yes
                JMP     ReadNextCnfLp			;NO


;---------------------------------------------------------------------------------------------
;stack 1
GetTableNoLength:
                SZ      LengthH      		;Table length >= wLengthH ?
				ret					        ;No
                MOV     A,TableLength      	;Table length >= wLengthL ?
                SUB     A,LengthL    		;
                SNZ     C                   ;
				ret
set_tablelength:
                MOV     A,LengthL     		;Yes
                MOV     TableLength,A     	;Update Tablelength by FIFO_wLengthL
				ret

;---------------------------------------------------------------------------------------------
ClassDst_Interface:
				MOV		A,FIFO_wIndexL
				SUB		A,INTERFACE_NO
				SZ		C
				JMP		ToStallPipe0
Skip_Check_Endpoint:
                MOV     A,FIFO_wValueH        	;Descriptor
                AND     A,wValueH_Dst           ;  Stanard, Class & Vendor
                MOV     TEMP,A                	;
                SUB     A,04H                   ;Over 4 iteM ?
                SZ      C                       ;
                JMP		ToStallPipe0            ;Yes
				
                MOV     A,TEMP
class_des_pcl_5:
                ADDM    A,PCL
                JMP		ToStallPipe0            ;Designator set no support
                JMP     GetHID                  ;Get HID descriptor
                JMP     GetEntity               ;Get entity descriptor
                JMP		ToStallPipe0            ;No support designator set

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			

PUBLIC			StandardRequest
PUBLIC			GetEnd
PUBLIC			ReadNextCnf
public			std_request_pcl_14
public			clear_feature_pcl_5
public			set_feature_pcl_5
public			std_des_start_pcl
public			std_des_end_pcl
public			GetStringDes
public			std_device_pcl_5
public			class_des_pcl_5
public			get_status_pcl_5
public			get_interface_pcl_3
public			get_endpt_pcl_3
public			get_entity_pcl_3
public			get_HID_pcl_3
public			get_entity_len_pcl_3
END

⌨️ 快捷键说明

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