📄 usbcmd.asm
字号:
;----------------------------------------------------------------------------
; Version : 0.11
; Copyright: (c)1997-1998, ScanLogic corporation
; Compiler: 2500 A.D. 8051 Macro Assembler V4.00g
;
; Revision: May/22/97 SNguyen Created
; Jun/09/98 SNguyen Updated
;
; - Add support on DMA (EP3) for ReadFile Host
; - Add support on EP2 for WriteFile from Host
; - Add support on EP1 for ReadFile from Host
;----------------------------------------------------------------------------
; Register Usage:
; Global:
; R3-R6 registers are not used
; R7 = USB address from host
; Local:
; R1-R0: General usage registers
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;SL11/SL811S ISR using Polling the SL11/SL811S Interrupt bit
; - Check all end point start here.
;----------------------------------------------------------------------------
ChkEndPoints:
Poll_IRQ
SL11Int: ;this is a entry of ISR
sRead IntStatus
anl a,#ReadMask
jz sIntExit ;EXIT the SL11Int Subroutine
jnb acc.6,CheckEP0
acall SL11Init ;reset SL11/SL811S Chip
sIntExit:
mEXIT
;--------------------------------------------------------------------------
;Process command from host for EndPoint 0
;-------------------------------------------------------------------------
CheckEP0:
jb acc.0,GotEP0 ;Chk if EP0 int goto GotEP0
ajmp CheckOther ;check other interrupts
GotEP0:
sWrite IntStatus,01h ;Clr the EP0 int.
sRead EP0Counter
mov R0,a ;Compare if base-length equals to
sRead EP0XferLen ;transfer length.
clr c
subb a,R0 ;R0 = sread(2)-sread(4)
jz SetReady ;if R0==0 goto SetReady
mov R0,a
sRead EP0Control ;Chk if last packet is Write.
jnb acc.2,ChkPacket ;if bit 2 is clear goto check packet
SetReady:
acall EP0Receive ;Set Ready to receive cmd from host
mEXIT
;-------------------------------------------------------------------------
ChkPacket:
sRead EP0Status ;Chk if setup packet.
jb acc.4,ChkPacketSize ;Otherwise It is a vendor try to transfer
ajmp SendNullPKG ;send null package and Exit
;-------------------------------------------------------------------------
SetStall:
sWrite EP0Control,23h
mEXIT
;--------------------------------------------------------------------------
;EndPoint 0, Configuration command table
;--------------------------------------------------------------------------
ConfCmdTable:
ajmp GetStatus ;GET_STATUS = 0
ajmp ClearFeature ;CLEAR_FEATURE = 1
ajmp SendNullPKG ;RESERVE0 = 2
ajmp SetFeature ;SET_FEATURE = 3
ajmp SendNullPKG ;RESERVE1 = 4
ajmp SetAddress ;SET_ADDRESS = 5
ajmp GetDescriptor ;GET_DESCRIPTOR= 6
ajmp SetDescriptor ;SET_DESCRIPTOR= 7
ajmp GetConfig ;GET_CONFIG = 8
ajmp SetConfig ;SET_CONFIG = 9
ajmp GetInterface ;GET_INTERFACE = ah
ajmp SetInterface ;SET_INTERFACE = bh
;--------------------------------------------------------------------------
;Check Packet size in EndPoint 0
;--------------------------------------------------------------------------
ChkPacketSize:
clr c
mov a,R0
subb a,#08h ;R0<8 ? goto ignore small packet
jc SetStall ;Abort and return
;--------------------------------------------------------------------------
;EndPoint 0: Process Configuration command
;--------------------------------------------------------------------------
acall GetCmd ;get 8 bytes command from host
mov R0,wLength0 ;get host transfer length
mov a,R0 ;R0 = current length size of the host
mov b,#EP0XferLen
acall SL11Write ;Setup EP0 Xfer length for re-send package
clr c
jb bmRequest.6,VendorCmd ;check Vendor Specific command
mov a,bRequest
subb a,#SET_INTERFACE+1 ;a<SET_INTERFACE then do ConfCmdTable
jc DoConfCmdTable
VendorCmd:
mov a,bRequest
subb a,#40h ;command offset
mov dptr,#CmdTable ;setup command table
anl a,#fh ;maximun 16 commands
rl a
jmp @a+dptr ;execute the command table and exit
DoConfCmdTable:
mov dptr,#ConfCmdTable ;setup command table
mov a,bRequest ;check command index
rl a
jmp @a+dptr ;execute the command table and exit
;--------------------------------------------------------------------------
;Chapter 9: Get Status command
; bmRequest
;--------------------------------------------------------------------------
GetStatus:
mov a,bmRequest
cjne a,#82h,elseChk82
Chk82:
mov a,wIndex0 ;endpoint number
anl a,#0fh ;a = (a&0x0f)*16 address EPxControl
swap a
mov b,a
acall SL11Read ;read EPx Control register
jnb acc.5,elseChk82 ;if STALL
sWrite EP0Buf,1h ; Send 1
ajmp SendStatus
elseChk82:
sWrite EP0Buf,0h
SendStatus:
sWrite EP0Buf+1,0h
sjmp Send47h
;--------------------------------------------------------------------------
;Chapter 9: All other unimplemented commands
;--------------------------------------------------------------------------
SetConfig:
mov ConfigReg,wValue0
SetDescriptor:
SetInterface:
SendNullPKG:
sWrite EP0XferLen,0
Send47h:
acall EP0Send ;sWrite EP0Control,47h
mEXIT
;--------------------------------------------------------------------------
;Chapter 9: SetFeature command
; bmRequest
;--------------------------------------------------------------------------
SetFeature:
mov a,bmRequest
cjne a,#02h,SendNullPKG
mov a,wIndex0
anl a,#0fh ;a = (a&0x0f)*16 address EPxControl
swap a
mov b,a
acall SL11Read ;Read EPxControl of A
orl a,#20h
acall SL11Write ;Set Stall
mov a,b
add a,#08h ;Read EPxControl of B
mov b,a
acall SL11Read
orl a,#20h
acall SL11Write
sjmp SendNullPKG ;toggle data0 and exit
;--------------------------------------------------------------------------
;Chapter 9: ClearFeature command
; bmRequestType
;--------------------------------------------------------------------------
ClearFeature:
mov a,bmRequest
cjne a,#02h,SendNullPKG
mov a,wIndex0
anl a,#0fh ;a=(a&0x0f)*16 address of EPxControl
swap a
mov b,a
acall SL11Read ;clear stall from endpoint A
anl a,#0dfh
acall SL11Write
mov a,b
add a,#08h ;clear stall from endpoint B
mov b,a
acall SL11Read
anl a,#0dfh
acall SL11Write
ajmp SendNullPKG
;--------------------------------------------------------------------------
;Chapter 9: GetInterface command
;--------------------------------------------------------------------------
GetInterface:
sWrite EP0Buf,0
ajmp GetCommon
;--------------------------------------------------------------------------
;Chapter 9: GetConfig command
;--------------------------------------------------------------------------
GetConfig:
mov a,ConfigReg
mov b,#EP0Buf
acall SL11Write
GetCommon:
ajmp Send47h
;--------------------------------------------------------------------------
;Chapter 9: GetDescriptor command
;--------------------------------------------------------------------------
GetDescriptor:
mov a,wValue1 ;Get the Descriptor type
cjne a,#DEVICE,ChkConfiguration
ajmp DoDevice
ChkConfiguration:
cjne a,#CONFIGURATION,ChkInterface
ajmp DoConfiguration
ChkInterface:
cjne a,#INTERFACE,ChkEndPoint
ajmp DoInterface
ChkEndPoint:
cjne a,#ENDPOINT,GetDefault
ajmp DoEndPoint
GetDefault:
ajmp SendNullPKG
;--------------------------------------------------------------------------
;Chapter 9: Setup to transfer the Device table
;--------------------------------------------------------------------------
DoDevice:
mov b,#12h
acall Min
mov dptr,#SL_DEV
SendDescriptor:
acall EP0SendPkg ;Send package from dptr to host
mEXIT
;--------------------------------------------------------------------------
;Chapter 9: Setup to transfer the Configuration table + EndPoints table
;--------------------------------------------------------------------------
DoConfiguration:
mov b,#TotalLen
acall Min
mov dptr,#SL_CONF
ajmp SendDescriptor
DoInterface:
mov b,#09h
acall Min
mov dptr,#SL_INTF
ajmp SendDescriptor
DoEndPoint:
mov b,#7 ;Setup the length
acall Min
mov a,wValue0 ;read endpoint number from buffer
cjne a,#1,ChkEndPoint2
ajmp SetEndPoint1
ChkEndPoint2:
cjne a,#2,ChkEndPoint3
ajmp SetEndPoint2
ChkEndPoint3:
cjne a,#3,EndPointOther
ajmp SetEndPoint3
EndPointOther:
ajmp SendNullPKG
SetEndPoint1:
mov dptr,#SL_EP1
ajmp SendDescriptor
SetEndPoint2:
mov dptr,#SL_EP2
ajmp SendDescriptor
SetEndPoint3:
mov dptr,#SL_EP3
ajmp SendDescriptor
;--------------------------------------------------------------------------
;Chapter 9: SetAddress command
;--------------------------------------------------------------------------
SetAddress:
mov R7,wValue0 ;r7=host assign the address
acall EP0Send ;send ACK
ChkAddress: ;program will loop here until
sRead IntStatus ;the set USBAdd done
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -