📄 emb_f.asm
字号:
cjne A, #SET_ADDRESS, CheckSetDeviceRWU
;------------------------------------------------
;- SET DEVICE ADDRESS
;------------------------------------------------
; Set Address should just return. The command will be executed following
; the status stage
jmp ReturnSTDSetDevice
CheckSetDeviceRWU:
cjne A, #SET_FEATURE, CheckClearDeviceRWU
mov A, wValue+1
cjne A, #DEVICE_REMOTE_WAKEUP, ReturnBadSetDeviceCommand
; Call user function to enable RWU
jmp ReturnSTDSetDevice
CheckClearDeviceRWU:
cjne A, #CLEAR_FEATURE, ReturnBadSetDeviceCommand
mov A, wValue+1
cjne A, #DEVICE_REMOTE_WAKEUP, ReturnBadSetDeviceCommand
;Call user code to disable RWU capibility
jmp ReturnSTDSetDevice
ReturnSTDSetDevice:
jmp SetUpControlWriteStatusStage
ReturnBadSetDeviceCommand:
; push EPINDEX
; mov EPINDEX, #01
; mov TXDAT, #20h
; mov TXCNT, #01h
; pop EPINDEX
orl EPCON , #0C0h ; Stall Endpoint
ret
StandardSetInterfaceCommand:
mov A, bRequest
cjne A, #SET_INTERFACE, ReturnBadSetDeviceCommand
mov A, wValue+1
orl A, wIndex+1
jnz ReturnBadSetDeviceCommand
mov CurrentConfig1Interface, R11
sjmp ReturnSTDSetDevice
StandardGetInterfaceCommand:
mov A, bRequest
cjne A, #GET_INTERFACE, ReturnBadSetDeviceCommand
mov A, wValue+1
jnz ReturnBadSetDeviceCommand
mov R11, CurrentConfig1Interface
mov TXDAT , A
mov TXCNTL, #01
ret
StandardSetOtherCommand:
StandardGetOtherCommand:
;------------------------------------------
; - Unknown Standard Command -- STALL ENDPOINT
;------------------------------------------
orl EPCON , #0C0h ; Stall Endpoint
ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpConfiguration1
;Brief Description : Setup the endpoints to the parameters specified in the
; : configuration 1 descriptor.
; :
; : See below for the actual values.
; :
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
SetUpConfiguration1:
push EPINDEX
clr LC ; High MIPs & Power mode
call ResetFifos ; Place all FIFOs in known state
mov EPINDEX, #01h ; EP1
mov TXCON, #04h ; TX FIFO
mov RXCON, #04h ; RX FIFO
mov EPCON, #0Fh ; EP Control
mov EPINDEX, #02h ; EP2
mov TXCON, #04h ; TX FIFO
mov RXCON, #04h ; RX FIFO
mov EPCON, #0Fh ; EP Control
mov EPINDEX, #03h ; EP3
mov TXCON, #0ch ; TX FIFO
mov RXCON, #0ch ; RX FIFO
mov EPCON, #0Fh ; EP Control
pop EPINDEX
ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpConfiguration0
;Brief Description : Setup the endpoints to the parameters specified in the
; : configuration 1 descriptor.
; :
; : See below for the actual values.
; :
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
ResetFifos:
; This routine flushes and clears all of the fifos.
; THe routine also sets data toggle back to zero as
; defined in the USB spec. This routine would be called
; when ever you change configurations.
; Subsets of this routine sould be called when changing interfaces.
anl FIE, #03h
anl FIFLG, #03h
mov A, #03h ; Number of FIFOS
ResetFifoLoop:
mov EPINDEX, A
orl TXCON, #80h ; Flush the TX FIFOs
orl RXCON, #80h ; Flush the RX FIFOs
orl TXSTAT, #04h ; Reset data toggle back to zero
orl RXSTAT, #04h ; Reset data toggle back to zero
mov EPCON , #040h ; Reset value
djnz ACC, ResetFifoLoop
ret
;-----------------------------------------------------------------
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs
;S
;S END OF STANDARD TYPE COMMANDS
;S
;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs
;-----------------------------------------------------------------
;-----------------------------------------------------------------
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;C
;C START OF CLASS COMMANDS
;C
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;-----------------------------------------------------------------
ClassGetDeviceCommand:
ClassGetOtherCommand:
ClassSetDeviceCommand:
ClassSetEndpointCommand:
ClassSetOtherCommand:
ClassSetInterfaceCommand:
ClassGetInterfaceCommand:
ClassGetEndpointCommand:
orl EPCON , #0C0h ;Stall Endpoint
ret
;-----------------------------------------------------------------
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;C
;C END OF CLASS COMMANDS
;C
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;-----------------------------------------------------------------
;-----------------------------------------------------------------
;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
;V
;V START OF VENDOR COMMANDS
;V
;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
;-----------------------------------------------------------------
VendorSetDeviceCommand:
call SetUpControlWriteStatusStage ; We know this will was a single packet only
ret
VendorGetDeviceCommand:
ret
VendorSetInterfaceCommand:
VendorGetInterfaceCommand:
VendorSetEndpointCommand:
VendorGetEndpointCommand:
VendorSetOtherCommand:
VendorGetOtherCommand:
;------------------------------------------
; - UnknownVendorCommand -- STALL ENDPOINT
;------------------------------------------
orl EPCON , #0C0h ;Stall Endpoint
ret
;-----------------------------------------------------------------
;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
;V
;V END OF VENDOR COMMANDS
;V
;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
;-----------------------------------------------------------------
;-----------------------------------------------------------------
;UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
;U
;U UTILILITY ROUTINES
;U
;UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
;-----------------------------------------------------------------
;COMMENT *------------------------------------------------------------
;Function name : ProcessInToken
;Brief Description : Services all INs on EP0.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
ProcessInToken:
anl FIFLG, #EP0_TX_CLR ; clear the interrupt bit
jmp CheckInStatusPhase
ProcessHubInToken:
CheckInStatusPhase:
mov A, gbSetupSeqTX ; read state variable
cjne A, #STATUS_PHASE,SendDataBack ; Should this be the end to
; a setup sequence
StatusPhaseDone:
lCall CompleteSetCommand
mov gbSetupSeqTX, #SETUP_PHASE ; Set state var. to expect setup.
mov gbSetupSeqRX, #SETUP_PHASE
jmp ReturnProcessIn
SendDataBack:
cjne A, #DATA_PHASE, ReturnProcessIn
call LoadControlTXFifo
ReturnProcessIn:
Ret
;COMMENT *------------------------------------------------------------
;Function name : CompleteSetCommand
;Brief Description : Called after the status phase of a set command has
; : completed. This is called everytime there is a
; : xmit status stage.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
CompleteSetCommand:
mov A, bRequest ; If this was not a Std. Set
; command then return.
cjne A, #SET_ADDRESS, CheckNextCommand
;------------------------------------------------
;- SET ADDRESS
;------------------------------------------------
DoSetAddress:
;
SetFunctionAddress:
mov FADDR, wValue+1 ; Set to new address
jmp ReturnCompleteSet
CheckNextCommand:
ReturnCompleteSet:
ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpControlWriteStatusStage
;Brief Description : Sets the status in the IN buffer.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
SetUpControlWriteStatusStage:
mov TXCNTL, #00 ; Setup Null Packet
; setb TXOE0 ; Enable data transmit
Ret
;COMMENT *------------------------------------------------------------
;Function name : LoadControlTXFifo
;Brief Description : Copy data from the location pointed to by
; : the three byte value gbFControlBufferLocation.
; : The number of bytes left to transmit are stored in
; : gbFControlBufferBytesLeft. If zero bytes are left then
; : a Null packet is loaded even if the null/short packet is
; : not needed.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
LoadControlTXFifo:
push R0 ; Need to save this register
push DPX
mov DPXL, gbFControlBufferLocation ; Get location of data to send.
mov DPH, gbFControlBufferLocation+1
mov DPL, gbFControlBufferLocation+2
mov A, gbFControlBufferBytesLeft ; First check to sei if any data is availble
orl A, gbFControlBufferBytesLeft+1 ; to send.
jnz CntlDataAvail
mov R0, #0 ; if there is data do normal flow
ljmp ControlArmTx ; if none, do null packet
CntlDataAvail:
mov R0, #0 ; Number of bytes in FIFO- Awlays <=16
mov A, DPXL
JZ DataInRAM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -