📄 ax_firm.asm
字号:
;--------------------------------------------------------------------*
SetUpConfiguration1:
push EPINDEX
setb LC ; High MIPs & Power mode
lcall ResetFifos ; Place all FIFOs in known state
mov EPINDEX, #01 ; EP1
mov EPCON, #00FH ; Non Control, Non ISO, Dual Packet
orl FIE, #0Ch ; ENable the interupts
mov EPINDEX, #02 ; EP2
mov EPCON, #00FH ; Non Control, Non ISO, Dual Packet
orl FIE, #030h ; ENable the interupts
;mov EPINDEX, #03 ; EP3
;mov EPCON, #00FH ; Non Control, Non ISO, Dual Packet
;orl FIE, #0C0h ; ENable the interupts
mov EPINDEX, #03 ; EP3
mov EPCON, #00FH ; Non Control, Non ISO, Dual Packet
mov RXCON, #0Ch ; ISO, ATM
mov TXCON, #0Ch ; ISO, ATM
pop EPINDEX
ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpConfiguration2
;Brief Description : Setup the endpoints to the parameters specified in the
; : configuration 2 descriptor.
; :
; : See below for the actual values.
; :
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
SetUpConfiguration2:
push EPINDEX
clr LC ; High MIPs & Power mode
lcall ResetFifos ; Place all FIFOs in known state
mov EPINDEX, #01 ; EP1
mov EPCON, #00FH ; Non Control, Dual Packet
mov RXCON, 0Ch ; ISO, ATM
mov EPINDEX, #02 ; EP2
mov EPCON, #00FH ; Non Control, Non ISO, Dual Packet
mov RXCON, 0Ch ; ISO, ATM
mov EPINDEX, #03 ; EP3
mov EPCON, #00FH ; Non Control, Non ISO, Dual Packet
mov RXCON, 0Ch ; ISO, ATM
mov TXCON, 0Ch ; ISO, ATM
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
;--------------------------------------------------------------------*
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:
lcall SetUpControlWriteStatusStage ; We know this will was a single packet only
ret
VendorGetDeviceCommand:
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
;--------------------------------------------------------------------*
ProcessInToken:
anl FIFLG, #EP0_TX_CLR ; clear the interrupt bit
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
sjmp ReturnProcessIn
SendDataBack:
cjne A, #DATA_PHASE, ReturnProcessIn
lcall 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
;--------------------------------------------------------------------*
CompleteSetCommand:
mov A, bmRequestType
anl A, #060h ; What type command is this?
JZ DoneWithStandardCommand ; If it's a standard command, then go to it's code.
cjne A, #40h, DoneDoneWithClassCommand
CheckVendorDone:
sjmp ReturnCompleteSet
DoneWithStandardCommand:
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
sjmp ReturnCompleteSet
CheckNextCommand:
DoneDoneWithClassCommand: ; Put here as this code doesn't currently support Class commands
ReturnCompleteSet:
ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpControlWriteStatusStage
;Brief Description : Sets the status in the IN buffer.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
SetUpControlWriteStatusStage:
mov TXCNTL, #00 ; Setup Null Packet
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
;--------------------------------------------------------------------*
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
;-----------------------------------------------
; Data is in ROM, use instrcutions to pull from ROM.
;-----------------------------------------------
DataInROM:
mov A, #00h
movc A, @A+DPTR ; Get Data to transmit
mov TXDAT, A
inc DPTR
inc R0 ; Increment the number of bytes in FIFO
djnz gbFControlBufferBytesLeft+1, ROMCheckMaxPacket ; If not zero, the continue.
ROMCheckUpper1:
mov A, gbFControlBufferBytesLeft ; If upper byte of wLength is also zero, buffer is empty.
jz ControlTxUpd ; Are we done with the buffer
dec A ; If it's not zero dec. the upper byte as well.
mov gbFControlBufferBytesLeft, A ; And store it.
ROMCheckMaxPacket:
cjne R0, #EP0_MAX_PACKET_SIZE, DataInROM ; Loop until FIFO is Full
sjmp ControlTxUpd ; Done with this FIFO.
;-----------------------------------------------
; Data is in RAM, use instrcutions to pull from RAM.
;-----------------------------------------------
DataInRAM:
movx A, @DPTR ; Get Data to transmit
mov TXDAT, A
inc DPTR
inc R0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -