📄 std1.asm
字号:
JMP ToStallPipe0 ; Yes: Error
MOV A,TEMP ;
get_status_pcl_5:
ADDM A,PCL ;
JMP DeviceStatusS ; 处理Recipient=Device
JMP InterfaceStatusS ; 处理Recipient=Interface
JMP EndpointStatusS ; 处理Recipient=Endpoint
JMP ToStallPipe0 ; 不处理Recipient=Other
;------------------------------------------------------------------------------
; Remark : Get endpoint status(属於Standard request)
;------------------------------------------------------------------------------
EndpointStatusS:
MOV A,FIFO_wIndexL ;
and a,01111111b ; 取出Endpoint number
SUB A,fifo_temp ;
SZ C ; 检查是否超过fifo_temp(若在address state,fifo_temp=1;否则fifo_temp=ENDPOINT_NO)
JMP ToStallPipe0 ; Yes: Error
;Don't care direction, maybe it's neccesary.
MOV A,0FH ;
AND A,FIFO_wIndexL ; 取出Endpoint number
CALL GetPipeBit ; 将ACC的对应bit设定为1
MOV FIFO_TEMP,A ;
MOV A,STALL ; ACC=get stall status
ShiftLoop:
RRC FIFO_TEMP ; Shift stall bit to D0
SZ C ;
JMP FoundStall ;
RR ACC ;
JMP ShiftLoop ;
FoundStall:
AND A,01H ;mask bits except stall bit
JMP SendEndpointStsS ;Send endpoint status
;------------------------------------------------------------------------------
; Remark : Get device status(属於Standard request)
;------------------------------------------------------------------------------
DeviceStatusS:
SZ FIFO_wIndexL ; 检查是否wIndex == 0 ?
JMP ToStallPipe0 ; No: Error
; Yes: Continue
clr acc ;
sz bRmtwakeup ; 决定要回传的RemoteWakeup的状态
set acc.1 ;
;------------------------------------------------------------------------------
; Remark : 将Get endpoint/device status的2-byte的结果传送给Host
;------------------------------------------------------------------------------
SendEndpointStsS:
MOV FIFO_OUT1,A ; low byte = (Device的RemoteWakeup和SelfPowered的状态)或(Endpoint的HALT状态)
CLR FIFO_OUT2 ; 固定将high byte = 00H
MOV A,02H ; 固定将data length = 2
JMP SendFIFOOut ; Send it
;------------------------------------------------------------------------------
; Remark : Get interface status(属於Standard request)
;------------------------------------------------------------------------------
InterfaceStatusS:
sz baddr_state ; 检查是否baddr_state=0(是否在address state)
jmp ToStallpipe0 ; Yes, Error
MOV A,FIFO_wIndexL ;
SUB A,INTERFACE_NO ; 检查是否超过2 Interface ?
SZ C ;
JMP ToStallPipe0 ; Yes, Error
;------------------------------------------------------------------------------
; Remark : 将Get interface status的2-byte(固定为00H)的结果传送给Host
;------------------------------------------------------------------------------
CLR FIFO_OUT1 ; 固定将low byte = 00H
CLR FIFO_OUT2 ; 固定将high byte = 00H
MOV A,02H ; 固定将data length = 2
JMP SendFIFOOut ; Send it
;------------------------------------------------------------------------------
; Remark : Get string descriptor(属於Standard request)
;------------------------------------------------------------------------------
std_des_start_pcl:
GetStringDes:
SZ FIFO_wIndexH ; 检查是否Language ID为0
JMP get_other_string ;
;FIFO_wIndexL = Language ID
sz fifo_wIndexL ; 检查是否Language ID为0
jmp get_other_string ;
sz fifo_wValuel ; 检查是否descriptor index为0
jmp Tostallpipe0 ; No, ToStallPipe0
get_string:
mov a,fifo_wValuel ;
sub a,3 ; 检查是否descriptor index大於3
sz c ;
jmp Tostallpipe0 ; 若descriptor index大於3,则ToStallPipe0
mov a,low LangID ; 要读取LangID
sz fifo_wValuel.0 ;
mov a,low ManufactureS ; 要读取ManufactureS
sz fifo_wValuel.1 ;
mov a,low ProductS ; 要读取ProductS
MOV TBLP,A ; TBLP=即将要读取的string descriptor
JMP ReadTableAndSendcnf ; 跳到ReadTableAndSendCnf,准备读取Host所要的string descriptor
get_other_string:
mov a,fifo_wIndexH ; 检查LanguageID_H是否相符
xor a,LAND_ID_H ;
snz z ;
jmp ToStallPipe0 ; 若不相符,则ToStallPipe0
mov a,fifo_wIndexl ; 检查LanguageID_L是否相符
xor a,LAND_ID_L ;
snz z ;
jmp TOStallpipe0 ; 若不相符,则ToStallPipe0
jmp get_string ; 跳到get_string,准备读取Host所要求的string
;------------------------------------------------------------------------------
; Remark : Get device descriptor(属於Standard request)
;------------------------------------------------------------------------------
GetDeviceDes:
SZ FIFO_wIndexH ; 检查是否wIndexH == 0 ?
JMP ToStallPipe0 ; No, Error
SZ FIFO_wIndexL ; 检查是否wIndexL == 0 ?
JMP ToStallPipe0 ; No, Error
MOV A,LOW DeviceD ; Set table pointer to device table
MOV TBLP,A ; TBLP=目标descriptor address
JMP ReadTableAndSendcnf ; Read Device table and send it
;------------------------------------------------------------------------------
; Remark : Get configuration descriptor(属於Standard request)
; 所有的Interface,HID和Endpoint descriptor都要回传到Host
;------------------------------------------------------------------------------
GetConfigurationDes:
SZ FIFO_wIndexH ; 检查是否wIndexH == 0 ?
JMP ToStallPipe0 ; No, Error
SZ FIFO_wIndexL ; 检查是否wIndexL == 0 ?
JMP ToStallPipe0 ; No, Error
MOV A,LOW ConfigurationD ; Set table pointer to configuration
MOV TBLP,A ; TBLP=目标descriptor address
MOV A,LOW GetInterfaceDes ; Save Return Address to ReturnAddr
MOV ReturnAddr,A ; ReturnAddr=GetInterfaceDes(ConfigurationDescriptor之後是InterfaceDescriptor)
JMP ReadTableAndSendCnf ; Read configuration table and send it
;------------------------------------------------------------------------------
; Remark : Get interface descriptor(属於Standard request)
;------------------------------------------------------------------------------
GetInterfaceDes:
call get_Interface_des_adr ; 根据descriptor index(des_count)取出目标descriptor address
MOV TBLP,A ; TBLP=目标descriptor address
MOV A,LOW GetHIDDes ; Save Return Address to ReturnAddr
MOV ReturnAddr,A ; ReturnAddr=GetHIDDes(InterfaceDescriptor之後是HIDDescriptor)
JMP GetTableLength ; 跳到GetTableLength
;------------------------------------------------------------------------------
; Remark : Get endpoint descriptor(属於Standard request)
;------------------------------------------------------------------------------
GetEndpointDes:
call get_endpt_des_adr ; 根据descriptor index(des_count)取出目标descriptor address
MOV TBLP,A ; configuration
inca des_count ; 将des_count加1的结果放到ACC(准备或许要要读取下一个Interface descriptor)
xor a,INTERFACE_NO ; 比对ACC和INTERFACE_NO
mov a,Low Endsend ; 假定Descriptor已经全部读完了
snz z ; 判断Descriptor是否全部读完了
mov a, LOW GetInterfaceDes ; 若尚未全部读完,则要准备再读下一个Interface descriptor
exit_of_ednpointDes:
MOV ReturnAddr,A ; ReturnAddr=GetInterfaceDes(准备读下一个Interface descriptor)
inc des_count ; des_count加1(descriptor index加1)
JMP GetTableLength ; 跳到GetTableLength
;------------------------------------------------------------------------------
; Remark : Get HID descriptor(属於Standard request)
;------------------------------------------------------------------------------
GetHIDDes:
call get_HID_des_adr ; 根据descriptor index(des_count)取出目标descriptor address
MOV TBLP,A ; TBLP=目标descriptor address
MOV A,LOW GetEndpointDes ; Set Return Address to ReturnAddr
MOV ReturnAddr,A ; ReturnAddr=GetEndpointDes(HIDDescriptor之後是EndpointDescriptor)
JMP GetTableLength ; 跳到GetTableLength
;------------------------------------------------------------------------------
; Remark : 准备将FIFO_OUTx的data,经由RequestResponse回传给Host(Standard和Class request共用)
;------------------------------------------------------------------------------
EndSend: ;
;----------------------------------------------------------------------
;SZ FIFO_SendLen ; 检查FIFO_SendLen是否为0
;jmp RequestResponse ; No,跳到RequestResponse,送出固定长度(FIFO_SendLen)的data到Host
;----------------------------------------------------------------------
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 ; Yes,准备离开USB INT ISR
;------------------------------------------------------------------------------
; Remark : Get HID descriptor(属於Standard request)
;------------------------------------------------------------------------------
GetHID:
MOV a,FIFO_wIndexL ; FIFO_wIndexL=Host欲读取的descriptor index
mov des_count,a ; des_count=descriptor index
call get_HID_des_adr ; 根据descriptor index(des_count)取出目标descriptor address
MOV TBLP,A ; TBLP=目标descriptor address
MOV A,LOW EndSend ;
MOV ReturnAddr,A ; 设定ReturnAddr=EndSend
jmp ReadTableAndSendcnf ; 读取HID table
;------------------------------------------------------------------------------
; Remark : Get entity(即Report) descriptor(属於Standard request)
;------------------------------------------------------------------------------
GetEntity:
MOV a,FIFO_wIndexL ; FIFO_wIndexL=Host欲读取的descriptor index
mov des_count,a ; des_count=descriptor index
call get_entity_des_adr ; 根据descriptor index(des_count)取出目标descriptor address
MOV TBLP,A ; TBLP=目标descriptor address
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -