📄 ax_firm.asm
字号:
; The amount asked for or the amount
; availible.
push ACC
push B
clr CY ; A=Actual-wLength=AskedFor
subb A, wLength+1
mov A, B
subb A, wLength
jc AskedFor_IsLarger
LengthsMatch:
wLengthIsSmaller: ; If Asked for is smaller, replace
; actual with asked for.
pop B
pop ACC
mov B, wLength
mov A, wLength+1
sjmp LoadIt
AskedFor_IsLarger:
pop B
pop ACC
LoadIt: ; From now on,
; wLength = bytes remaining.
mov gbFControlBufferBytesLeft, B
mov gbFControlBufferBytesLeft+1, A
LCall LoadControlTXFifo
sjmp ReturnSTDGetDeviceCommand
CheckGetConfiguration:
cjne A, #GET_CONFIGURATION, CheckGetStatus
;------------------------------------------------
;- GET CONFIGURATION
;------------------------------------------------
mov R11, CurrentConfiguration
mov TXDAT, A
mov TXCNTL, #01
sjmp ReturnSTDGetDeviceCommand
CheckGetStatus:
cjne A, #GET_STATUS, ReturnSTDGetDeviceCommand
;------------------------------------------------
;- GET DEVICE STATUS
;------------------------------------------------
mov A, #01h ; Not RWU and seld powered
mov TXDAT, A
mov TXDAT, #00h
mov TXCNTL, #02
sjmp ReturnSTDGetDeviceCommand
ReturnBADSTDGetDeviceCommand:
orl EPCON, #0C0h ; Stall EP0
ReturnSTDGetDeviceCommand:
ret
;COMMENT *------------------------------------------------------------
;Function name : StandardGetEndpointCommand:
;Brief Description : Process a Standard Set Endpoint Command Setup Token
; : This can only be a Set,Clear Feature - Endpoint Stall
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
StandardGetEndpointCommand:
mov A, bRequest
cjne A, #GET_STATUS, ReturnBadSTDGetEPCommand
;------------------------------------------------
;- GET ENDPOINT STATUS
;------------------------------------------------
mov A, wIndex + 1
anl A, #0Fh ; Mask off all but the endpoint value
mov EPINDEX,A ; Point the Index register at the
mov A, wIndex + 1 ; Start by clearing out R0
jb ACC.7, GetInStallStatus
GetOutStallStatus:
mov A, EPCON
jnb ACC.7, NotStalled
mov A, #01 ; Return Stalled
sjmp DoneWithCommand
GetInStallStatus:
mov A, EPCON
jnb ACC.6, NotStalled
mov A, #01
sjmp DoneWithCommand
NotStalled:
mov A, #00h
DoneWithCommand:
anl EPINDEX,#80h ; Point the index back to EP0
mov TXDAT, A
mov TXDAT, #00h
mov TXCNTL, #02
ret
ReturnBadSTDGetEPCommand:
orl EPCON, #0C0h ; Stall EP0
ReturnSTDGetEPCommand:
Ret
;COMMENT *------------------------------------------------------------
;Function name : SetUpSinglePacketControlReadStatusStage
;Brief Description : Sets the status in the IN buffer and initilizes all the
; : registers needed to do a single packet control read.
; : This needs to be done so the IN token is processed correctly.
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
SetUpSinglePacketControlReadStatusStage:
mov wLength, #00
mov wLength+1, #00
mov gbSetupSeqRX, #STATUS_PHASE ; Advance State Machine to next state
mov gbSetupSeqTX, #DATA_PHASE
setb TXOE ; Enable data transmit
Ret
;COMMENT *------------------------------------------------------------
;Function name : StandardSetEndpointCommand:
;Brief Description : Process a Standard Set Endpoint Command Setup Token
; : This can only be a Set,Clear Feature - Endpoint Stall
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
StandardSetEndpointCommand:
push EPINDEX
mov A, wIndex+1 ; Get the endpoint of the stall to clear
anl A, #0Fh ; Find out if this is an EP0 CLear Stall Command.
orl EPINDEX,A ; Setup the EPINDEX to point at correct index.
; Check to make sure this is an Endpoint Stall.
; If it is not then it's a wrong command plus you
; save a few bytes doing it in this order.
mov A, wValue+1
cjne A, #ENDPOINT_STALL, ReturnBadSTDSetEPCommand
mov A, bRequest
cjne A, #CLEAR_FEATURE, CheckSetEndpointFeature
ClearEndpointFeature:
;------------------------------------------------
;- CLEAR ENDPOINT STALL
;------------------------------------------------
ClearEndpointStall:
mov A, wIndex+1 ; Get the endpoint of the stall to clear
anl A, #0Fh ; Find out if this is an EP0 CLear Stall Command.
JNZ ClearNonEP0Stall
anl EPCON, #03Fh ; For EP0 Clear both TX & RX stall bits
sjmp ReturnSTDSetEPCommand
ClearNonEP0Stall:
mov A, wIndex+1 ; Get the endpoint of the stall to clear
JB ACC.7, ClearInStall ; For Non EP0, examing the direction bit as well.
ClearOutStall:
anl EPCON, #CLEAR_OUT_STALL_MASK
sjmp ReturnSTDSetEPCommand
ClearInStall:
anl EPCON, #CLEAR_IN_STALL_MASK
sjmp ReturnSTDSetEPCommand
CheckSetEndpointFeature:
cjne A, #SET_FEATURE, ReturnBadSTDSetEPCommand
SetEndpointFeature:
;------------------------------------------------
;- SET ENDPOINT STALL
;------------------------------------------------
SetEndpointStall:
mov A, wIndex+1 ; Get the endpoint to stall
JB ACC.7, SetInStall
SetOutStall:
orl EPCON, #SET_OUT_STALL_MASK
sjmp ReturnSTDSetEPCommand
SetInStall:
orl EPCON, #SET_IN_STALL_MASK
sjmp ReturnSTDSetEPCommand
ReturnBadSTDSetEPCommand:
orl EPCON, #0C0h ; Stall EP0
ReturnSTDSetEPCommand:
pop EPINDEX
ljmp SetUpControlWriteStatusStage
;COMMENT *------------------------------------------------------------
;Function name : StandardSetDeviceCommand:
;Brief Description : Process a Standard Set Device Command Setup Token
; : The only valid commands are Set Address,
; : Set Configuration. Other commands which have this
; : field but are un-defined are
; : ClearDeviceFeature, SetDescriptor, SetDeviceFeature.
; :
;Regs preserved : No reg. is saved
;--------------------------------------------------------------------*
StandardSetDeviceCommand:
mov A, bRequest
cjne A, #SET_CONFIGURATION, CheckSetDeviceAddress
SetDeviceConfiguration:
;------------------------------------------------
;- SET DEVICE CONFIGURATION
;------------------------------------------------
; Check to see what configuration we should take on.
mov A, wValue+1
CheckConfig0:
cjne A, #0, CheckConfig1
mov CurrentConfiguration, R11 ; Set up the variables
push EPINDEX
LCall ResetFifos ; Empty out all of the FIFOs and return to
; the un configuraed state.
pop EPINDEX
jb LC, ReturnSTDSetDevice ; Are we in low power state?
setb LC ; If not then goto low power state.
sjmp ReturnSTDSetDevice
CheckConfig1:
cjne A, #1, CheckConfig2
mov CurrentConfiguration, R11 ; Set up the variables
lCall SetUpConfiguration1
sjmp ReturnSTDSetDevice
CheckConfig2:
cjne A, #2, ReturnBadSetDeviceCommand
mov CurrentConfiguration, R11 ; Set up the variables
lCall SetUpConfiguration2
sjmp ReturnSTDSetDevice
CheckSetDeviceAddress:
cjne A, #SET_ADDRESS, CheckSetDeviceRWU
;------------------------------------------------
;- SET DEVICE ADDRESS
;------------------------------------------------
; Set Address should just return. The command will be executed
; following the status stage
sjmp ReturnSTDSetDevice
CheckSetDeviceRWU:
cjne A, #SET_FEATURE, CheckClearDeviceRWU
mov A, wValue+1
cjne A, #DEVICE_REMOTE_WAKEUP, ReturnBadSetDeviceCommand
; Call user function to enable RWU
sjmp ReturnSTDSetDevice
CheckClearDeviceRWU:
cjne A, #CLEAR_FEATURE, ReturnBadSetDeviceCommand
mov A, wValue+1
cjne A, #DEVICE_REMOTE_WAKEUP, ReturnBadSetDeviceCommand
;Call user code to disable RWU capibility
sjmp ReturnSTDSetDevice
ReturnSTDSetDevice:
ljmp SetUpControlWriteStatusStage
ReturnBadSetDeviceCommand:
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -