?? usbcmd.asm
字號:
jnb acc.6,ChkAddress1
acall SL11Init
mEXIT
;-------------------------------------------------------------------------
; Wait for host to assign the USB address
;--------------------------------------------------------------------------
ChkAddress1:
sRead IntStatus ;the set USBAdd done
jb acc.0,SetAddress0
ajmp ChkAddress ;loop until set address done
SetAddress0:
sWrite IntStatus,01h
sRead EP0Control
jb acc.2,SetAddress1
mEXIT
;-------------------------------------------------------------------------
SetAddress1:
mov a,R7
mov b,#USBAdd
acall SL11Write
ajmp SetReady ;acall SetReady And EXIT
;--------------------------------------------------------------------------
; R0 = min(R0,b)
;--------------------------------------------------------------------------
Min:
clr c
mov a,R0
subb a,b
jc MinRet
mov R0,b
MinRet:
ret
;--------------------------------------------------------------------------
; This must be other interrupts
;--------------------------------------------------------------------------
CheckOther:
jnb acc.2,ExitInt
ajmp GotEP2 ;Chk if EP2 int goto GotEP2
ExitInt:
jnb acc.1,ExitInt0 ;Chk if EP1 int
ajmp GotEP1
ExitInt0:
mEXIT
;--------------------------------------------------------------------------
; Host interface: command table
;--------------------------------------------------------------------------
CmdTable:
AJMP Send47h ;40h
AJMP StepRead ;41h
AJMP EPPDataRead ;42h
AJMP Send47h ;43h
AJMP Send47h ;44h
ajmp ReadLine ;45h HostWrite: Read Image Line use EP3 DMA
ajmp WriteLine ;46h HostWrite: Write Image Line use EP2 IO
AJMP Send47h ;47h
AJMP Send47h ;48h
AJMP Send47h ;49h
ajmp ReadLine ;4ah HostWrite: Read Image Line use EP1
ajmp WriteLine ;4bh HostRead: Write Image Line use EP2 IO
AJMP Send47h ;4ch
AJMP EPPByteWrite ;4dh: Single Byte Write
AJMP InitScanner ;4eh
AJMP InitScanner ;4fh
;--------------------------------------------------------------------------
; INIT SCANNER FOR SPP TO EPP
;--------------------------------------------------------------------------
InitScanner:
call INIT_SCANNER ;Call to init scanner
ajmp Send47h
;--------------------------------------------------------------------------
; Genernal EPP Data Read
; require bmRequestType = 0xc0
; bRequest = 0x42
; wValue = EPP Address Register
; wIndex = 0
; wLength = 1-64 max
;--------------------------------------------------------------------------
EPPDataRead:
MOV P1,wValue0 ;Write EPP Address
CALL EPPAddrWr
mov A,#EP0Buf ;Setup SL11/SL811S Memory address
call FIFO2SL11 ;copy data from EPP to SL11/SL811S
ajmp Send47h ;send and exit
;--------------------------------------------------------------------------
; Genernal EPP Byte Write
; require bmRequestType = 0x40
; bRequest = 0x4d
; wValue = EPP Address Register
; wIndex = Data Byte
; wLength = 0
;--------------------------------------------------------------------------
EPPByteWrite:
MOV P1,wValue0 ;Write to EPP address
call EPPAddrWr
mov P1,wIndex0
call EPPDataWr ;Write the Data
ajmp Send47h
;--------------------------------------------------------------------------
; ReadLine:
; EPP Block Read
; require bmRequestType = 0x40
; bRequest = 0x45
; wValue = EPP Address Register
; wIndex = Total length for EP1 data read
; wLength = 0
; EP1 will be used for Send data to host
;--------------------------------------------------------------------------
ReadLine:
clr cmd1
rdDMAcom
acall ReadDMALine
mEXIT
StepRead:
setb cmd1
acall MovStepper
sjmp rdDMAcom
;--------------------------------------------------------------------------
; ReadLine1: using EP1
;--------------------------------------------------------------------------
ReadLine1:
clr cmd1
rdCommon:
sWrite EP1AControl,0eh ;default EP1A is DATA0
sWrite EP1BControl,046h ;default EP1B is DATA1
clr EP1DataFlag
sRead DATASet ;check current DATA bit
jnb acc.1,ep1DATA0
setb EP1DataFlag
ep1DATA0:
acall SetupSendBuf ;prepare buffer to send
ajmp Send47h ;After the host rec 64 bytes, the EP1
;interrupt will be called
;--------------------------------------------------------------------------
; WriteLine
; require bmRequestType = 0x40
; bRequest = 0x46
; wValue = EPP Address Register
; wIndex = Total length for EP2 data Write
; wLength = 0
; EP2 will be used for Receive data from host
;--------------------------------------------------------------------------
WriteLine:
acall SetupRecBuf
ajmp Send47h ;After the host send 64 bytes, the EP2
;interrupt will beacalled
;--------------------------------------------------------------------------
; SetupRecBuff: Setup Receiving buffer
;--------------------------------------------------------------------------
SetupRecBuf:
clr EP2DataFlag ;Start DATA0
MOV P1,wValue0 ;Write to EPP Address
call EPPAddrWr
mov ImSize0,LineSize0 ;copy image size
mov ImSize1,LineSize1
ajmp SetupEP2
;--------------------------------------------------------------------------
; SetupSendBuff: Pre Copy buffer from FIFO to SL11/SL811S Memory
;--------------------------------------------------------------------------
SetupSendBuf:
acall MovStepper
mov ImSize0,LineSize0 ;copy image size
mov ImSize1,LineSize1
mov p1,wValue0
call EPPAddrWr
acall ChkSize80h ;R0 return the length of availabe size
cjne r0,#0h,Cpy0 ;attempt to copy all 128 bytes to SL11/SL811S
ret
Cpy0:
mov r1,#uBufA
jnb EP1DataFlag,cData0
mov r1,#uBufB
mov a,r0
clr c
subb a,#40h
jc cData0
jz cData0
mov b,a
mov a,r1 ;buffer start at 0xc0
mov r0,#40h
acall FIFO2SL11
mov r0,b
mov r1,#uBufA
cData0: ;Copy from EPP to SL11/SL811S (bufferA+BufferB)
mov a,r1
acall FIFO2SL11 ;Double buffer copied for Ping-pong buffer
acall Update40h ;update current sent counter
ajmp SetupEP1 ;ARM to send the data to host
;--------------------------------------------------------------------------
; GotEP1
;--------------------------------------------------------------------------
GotEP1:
sWrite IntStatus,02h ;Clr the EP1 int.
mov a,ImSize0
orl a,ImSize1
jnz ChkFlag1
acall SetupSendBuf
mEXIT
ChkFlag1:
acall Update40h ;Check if all data has been transfered
acall SetupEP1
acall ChkSize40h
cjne r0,#0h,ChkFlag2 ;R0 contain the remainder
mEXIT
ChkFlag2:
mov a,#uBufA
jnb EP1DataFlag,EP1Data0
mov a,#uBufB
EP1Data0:
acall FIFO2SL11 ;Double buffer copied for Ping-pong buffer
mEXIT
;--------------------------------------------------------------------------
; GotEP2
;--------------------------------------------------------------------------
GotEP2:
sWrite IntStatus,04h ;Clr the EP2 int.
acall SetupEP2 ;Setup to ARM for pingpong buffer
acall Update40h ;Check if all data has been transfered
cjne r0,#0h,ChkEP2Flag ;ImSize -= 64
sjmp EP2Exit ;all done then exit
ChkEP2Flag:
mov a,#uBufA
jnb EP2DataFlag,EP2Data0 ;data has been received from DATA0
mov a,#uBufB
EP2Data0:
acall SL112FIFO ;Copy from SL11/SL811S buffer to FIFO
mov a,ImSize0 ;check if more transfer data
orl a,ImSize1
jnz EP2Exit1
EP2Exit:
acall SetupRecBuf ;next line xfer
EP2Exit1:
mEXIT
;--------------------------------------------------------------------------
; iSize = iSize - R0
; R1 = pointer to Word iSize
;--------------------------------------------------------------------------
ChkSize40h:
mov r0,#uXferLen
jmp ChkCommon
ChkSize80h:
mov r0,#(uXferLen+uXferLen)
ChkCommon:
mov iSize0,ImSize0
mov iSize1,ImSize1
mov r1,#iSize0
jmp ChkSize
;--------------------------------------------------------------------------
; ImSize = ImSize - R0
; R1 = pointer to Word LineSize
;--------------------------------------------------------------------------
Update40h:
mov r0,#uXferLen
mov r1,#ImSize0
;--------------------------------------------------------------------------
; If (LineSize<R0) R0 = LineSize, LineSize = 0
; else LineSize = LineSize - R0, R0 = R0
; R1 = pointer to Word LineSize
;--------------------------------------------------------------------------
ChkSize:
clr c
mov a,@r1
mov b,a
subb a,r0
mov @r1,a
inc r1
mov a,@r1
subb a,#0
mov @r1,a
jnc UpdateRet
mov @r1,#0
dec r1
mov r0,b
mov @r1,#0
UpdateRet:
ret
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -