📄 hx_all.asm
字号:
;-----------------------------------------------------------------
;UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
;U
;U UTILILITY ROUTINES
;U
;UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
;-----------------------------------------------------------------
;COMMENT *------------------------------------------------------------
;Function name : ProcessInToken1
;Brief Description : Services all INs on EP0.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
ProcessInToken1:
;(HUB)
jb EPINDEX.7, ProcessHubInToken ; Is this a HUB or NON Hub Call?
anl FIFLG, #EP0_TX_CLR ; clear the interrupt bit
ljmp CheckInStatusPhase1
ProcessHubInToken:
anl HIFLG, #EP0_TX_CLR ; clear the interrupt bit
CheckInStatusPhase1:
mov A, gbSetupSeqTX1 ; read state variable
cjne A, #STATUS_PHASE,SendDataBack1 ; Should this be the end to
; a setup sequence
StatusPhaseDone1:
lCall CompleteSetCommand1
mov gbSetupSeqTX1, #SETUP_PHASE ; Set state var. to expect setup.
mov gbSetupSeqRX1, #SETUP_PHASE
sjmp ReturnProcessIn1
SendDataBack1:
cjne A, #DATA_PHASE, ReturnProcessIn1
lcall LoadControlTXFifo1
ReturnProcessIn1:
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
CompleteSetCommand1:
mov A, bRequest1 ; If this was not a Std. Set
; command then return.
cjne A, #SET_ADDRESS, CheckNextCommand1
;------------------------------------------------
;- SET ADDRESS
;------------------------------------------------
DoSetAddress1:
jnb EPINDEX.7, SetFunctionAddress1 ; Use EPINDEX to tell if this
SetHubAddress: ; was a hub command or function command.
mov HADDR, wValue1+1 ; Set to new address
sjmp ReturnCompleteSet1
SetFunctionAddress1:
mov FADDR, wValue1+1 ; Set to new address
sjmp ReturnCompleteSet1
CheckNextCommand1:
ReturnCompleteSet1:
ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpControlWriteStatusStage
;Brief Description : Sets the status in the IN buffer.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
SetUpControlWriteStatusStage1:
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
LoadControlTXFifo1:
push R0 ; Need to save this register
push DPX
mov DPXL, gbFControlBufferLocation1 ; Get location of data to send.
mov DPH, gbFControlBufferLocation1+1
mov DPL, gbFControlBufferLocation1+2
mov A, gbFControlBufferBytesLeft1 ; First check to sei if any data is availble
orl A, gbFControlBufferBytesLeft1+1 ; to send.
jnz CntlDataAvail1
mov R0, #0 ; if there is data do normal flow
ljmp ControlArmTx1 ; if none, do null packet
CntlDataAvail1:
mov R0, #0 ; Number of bytes in FIFO- Awlays <=16
mov A, DPXL
JZ DataInRAM1
;-----------------------------------------------
; Data is in ROM, use instrcutions to pull from ROM.
;-----------------------------------------------
DataInROM1:
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 gbFControlBufferBytesLeft1+1, ROMCheckMaxPacket1 ; If not zero, the continue.
ROMCheckUpper11:
mov A, gbFControlBufferBytesLeft1 ; If upper byte of wLength is also zero, buffer is empty.
jz ControlTxUpd1 ; Are we done with the buffer
dec A ; If it's not zero dec. the upper byte as well.
mov gbFControlBufferBytesLeft1, A ; And store it.
ROMCheckMaxPacket1:
cjne R0, #EP0_MAX_PACKET_SIZE, DataInROM1 ; Loop until FIFO is Full
ljmp ControlTxUpd1 ; Done with this FIFO.
;-----------------------------------------------
; Data is in RAM, use instrcutions to pull from RAM.
;-----------------------------------------------
DataInRAM1:
movx A, @DPTR ; Get Data to transmit
mov TXDAT, A
inc DPTR
inc R0 ; Increment the number of bytes in FIFO
djnz gbFControlBufferBytesLeft1+1, RAMCheckMaxPacket1 ; If not zero, the continue.
RAMCheckUpper11:
mov A, gbFControlBufferBytesLeft1 ; If upper byte of gbFControlBufferBytesLeft1 is also zero, buffer is empty.
jz ControlTxUpd1 ; Are we done with the buffer
dec A ; If it's not zero dec. the upper byte as well.
mov gbFControlBufferBytesLeft1, A ; And store it.
RAMCheckMaxPacket1:
cjne R0, #EP0_MAX_PACKET_SIZE, DataInRAM1 ; Loop until FIFO is Full
ControlTxUpd1:
mov gbFControlBufferLocation1+1, DPH ; Update read pointers.
mov gbFControlBufferLocation1+2, DPL
ControlArmTx1:
mov TXCNTL, R0 ; Write count into TXCNT register
setb TXOE ; Enable data transmit
ReturnLoadCntl1:
pop DPX
pop R0
Ret
;COMMENT *------------------------------------------------------------
;Function name : GetOUTData
;Brief Description : takes data from the FIFO, Puts it in memory and
; : then updates writes it to the fifo.
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
;GetOUTData:
; mov WR26, #LOW16(OUT_BUFFERS)
; mov R7, RXCNTL ; Read count of bytes rec'd
; mov @WR26, R7 ; Store the count in the OUT_BUFFERS space.
; add WR26, #01h ; Increment mem pointer
; orl R7, R7 ; Set flags
; je Return
;WriteToOUTBuffer:
; mov R8, RXDAT
; mov @WR26, R8
; inc WR26, #01h
; djnz R7, WriteToOUTBuffer
;Return:
; Ret
;COMMENT *------------------------------------------------------------
;Function name : INIT_USB
;Brief Description : Initialize USB SFRs
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
;SCOPE
INIT_USB: ; EP0 Comes up as it should except that
; all flow control is turned off except for
; OE bits. This will turn them on so we can
; accept all data.
; All other endpoints should not be configured
; until a Set Configuration command is given.
mov EPINDEX, #80
mov TXCON, #04h
mov RXCON, #04h
mov EPCON, #03Fh
ReturnInitUSB:
Ret
;COMMENT *------------------------------------------------------------
;Function name : INIT_VARIABLES
;Brief Description : Initializes global variables
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
; SCOPE
INIT_VARIABLES:
;Init SETUP VARIABLES
mov R0, #00h
mov Heart1_1, R0
mov Heart1_1+1, R0
mov gbSetupSeqRX1, R0 ; SetupSeq is set to
mov gbSetupSeqTX1, R0 ; STATUS_PHASE
mov gbFControlBufferLocation1, R0
mov gbFControlBufferLocation1+1, R0
mov gbFControlBufferLocation1+2, R0
mov gbFControlBufferBytesLeft1, R0
mov CurrentConfiguration1, R0
mov CurrentConfig1Interface1, R0
mov WR0, #0 ; Zero Out Counter
mov WR2, WR0
ReturnInit:
Ret
;========================================================================
;====================== Delay ======================================
;========================================================================
; This routine delays by the delay specified in DR0.
; If Fixed delay is called, the
FixedDelay:
mov WR2, #0
mov WR0, #20h
VaraibleDelay:
delay1:
dec DR0, #01
jne delay1
ret
;************************************************************************
;************* DEVICE DESCRIPTOR ****************************************
;************************************************************************
; NOTE!!!!! '251 is a Big Endian machine. Words and DWords are stored with the
; LSB in the numerically higher address.
;------------------------------------------------
;-------- HUB DESCRIPTOR ------------------------
;------------------------------------------------
;
; NOTE!!!!! '251 is a Big Endian machine. Words and DWords are stored with the
; LSB in the numerically higher address.
;
Header: db "HUB FIMRWARE 2",10,13,00
BEGIN_DEVICE_DESCRIPTOR:
gDevice_bLength: db 12h; DEVICE_DESCRIPTOR_LENGTH
gDevice_bDescriptorType: db DEVICE_DESCR
gDevice_bcdUSB: db LOW(00100h)
db HIGH(00100h)
gDevice_bDeviceClass: db 09h
gDevice_bDeviceSubClass: db 00h
gDevice_bDeviceProtocol: db 00h
gDevice_wMaxPacketSize0: db 08h
gDevice_widVendor: db LOW(008086h)
db HIGH(008086h)
gDevice_widProduct: db LOW(009304h)
db HIGH(009304h)
gDevice_bcdDevice: db LOW(00100h)
db HIGH(00100h)
gDevice_iManufacturer: db 02h ;These three fields are supposed
gDevice_iProduct: db 01h ;to contain the index of strings
gDevice_iSerialNumber: db 00h ;describing device.
gDevice_bNumConfigurations: db 1
END_DEVICE_DESCRIPTOR:
;/*--------------- Initialize global Config descriptor ----------------*/
BEGIN_CONFIG_DESCRIPTOR:
gConfig_bLength: db 09h
gConfig_bDescriptorType: db CONFIG_DESCR
gConfig_bTotalLength: db END_CONFIG_DESCRIPTOR - BEGIN_CONFIG_DESCRIPTOR
gConfig_bCorrection: db 0
gConfig_bNumInterfaces: db 1 ; NUM_OF_INTERFACES;
gConfig_bConfigurationValue: db 1
gConfig_iConfiguration: db 00h
gConfig_bmAttributes: db 040h
gConfig_MaxPower: db 032h
; /*------------- Initialize global
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -