📄 lite_frm.asm
字号:
AJMP VendorGetInterfaceCommand
AJMP VendorSetEndpointCommand
AJMP VendorGetEndpointCommand
AJMP VendorSetOtherCommand
AJMP VendorGetOtherCommand
COMMENT *------------------------------------------------------------
Function name : GetStandardDeviceCommand:
Brief Description : Process a Get Standard Device Command Setup Token
: This can only be a Get (Device or Configuration) Descriptor,
: or Get Device Status, Get Configuration
Regs preserved : No reg. is saved
--------------------------------------------------------------------*
SCOPE
StandardGetDeviceCommand:
mov A, bRequest
cjne A, #GET_DESCRIPTOR, CheckGetConfiguration
mov A, bDescriptorType
cjne A, #DEVICE_DESCR, CheckConfigDescriptor
; ********************** GET DESCRIPTOR, DEVICE *******************
mov gbFControlBufferLocation, #LOW HIGH16(BEGIN_DEVICE_DESCRIPTOR)
mov gbFControlBufferLocation+1, #HIGH LOW16(BEGIN_DEVICE_DESCRIPTOR)
mov gbFControlBufferLocation+2, #LOW LOW16(BEGIN_DEVICE_DESCRIPTOR)
mov A, #LOW (END_DEVICE_DESCRIPTOR - BEGIN_DEVICE_DESCRIPTOR) ;#12h
mov B, #HIGH (END_DEVICE_DESCRIPTOR - BEGIN_DEVICE_DESCRIPTOR) ;00h
jmp LoadBuffer
CheckConfigDescriptor:
cjne A, #CONFIG_DESCR, CheckStringDescriptor
; ********************** GET DESCRIPTOR, CONFIGURATION ************
mov gbFControlBufferLocation, #LOW HIGH16(BEGIN_CONFIG_DESCRIPTOR)
mov gbFControlBufferLocation+1, #HIGH LOW16(BEGIN_CONFIG_DESCRIPTOR)
mov gbFControlBufferLocation+2, #LOW LOW16(BEGIN_CONFIG_DESCRIPTOR)
mov A, #LOW (END_CONFIG_DESCRIPTOR - BEGIN_CONFIG_DESCRIPTOR)
mov B, #HIGH (END_CONFIG_DESCRIPTOR - BEGIN_CONFIG_DESCRIPTOR)
jmp LoadBuffer
CheckStringDescriptor:
cjne A, #STRING_DESCR, ReturnBADSTDGetDeviceCommand
; ********************** GET DESCRIPTOR, CONFIGURATION ************
mov gbFControlBufferLocation, #LOW HIGH16(STRING_1)
mov gbFControlBufferLocation+1, #HIGH LOW16(STRING_1)
mov gbFControlBufferLocation+2, #LOW LOW16(STRING_1)
mov A, #LOW (STRING_2-STRING_1)
mov B, #HIGH(STRING_2-STRING_1)
jmp LoadBuffer
LoadBuffer: ; Compare to see which is shorter.
; 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
jmp LoadIt
AskedFor_IsLarger:
pop B
pop ACC
LoadIt: ; From now on, wLength = bytes remaining.
mov wLength, B
mov wLength+1, A
Call LoadControlTXFifo
jmp ReturnSTDGetDeviceCommand
CheckGetConfiguration:
cjne A, #GET_CONFIGURATION, CheckGetStatus
;------------------------------------------------
;- GET CONFIGURATION
;------------------------------------------------
;------- TBD -------
jmp ReturnSTDGetDeviceCommand
CheckGetStatus:
cjne A, #GET_STATUS, ReturnSTDGetDeviceCommand
;------------------------------------------------
;- GET DEVICE STATUS
;------------------------------------------------
;------- TBD -------
jmp ReturnSTDGetDeviceCommand
ReturnSTDGetDeviceCommand:
jmp SetUpControlReadStatusStage
ReturnBADSTDGetDeviceCommand:
orl EPCON0, #0C0h ;Stall EP0
jmp SetUpControlReadStatusStage
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
--------------------------------------------------------------------*
SCOPE
StandardGetEndpointCommand:
mov A, bRequest
cjne A, #GET_STATUS, CheckGetEndpointDescriptor
;------------------------------------------------
;- GET ENDPOINT STATUS
;------------------------------------------------
mov A, wIndex + 1
anl A, #0Fh ; Mask off all but the endpoint value
orl EPINDEX,A ; Point the Index register at the
mov A, wIndex + 1 ; Start by clearing out R0
jb ACC.7, GetInStallStatus
GetOutStallStatus:
mov A, EPCON0
jnb ACC.6, NotStalled
mov A, #01 ; Return Stalled
jmp DoneWithCommand
GetInStallStatus:
mov A, EPCON0
jnb ACC.7, NotStalled
mov A, #01
DoneWithCommand:
NotStalled:
anl EPINDEX,#80h ; Point the index back to EP0
mov TXDAT0, A
mov TXDAT0, #00h
mov TXCNT0, #02
jmp ReturnSTDGetEPCommand
;------------------------------------------------
;- GET HID/REPORT DESCRIPTOR CODE
;------------------------------------------------
CheckGetEndpointDescriptor:
cjne A, #GET_DESCRIPTOR, ReturnBadSTDGetEPCommand
mov A, wValue
cjne A, #HID_DESCR, CheckGetReportDescriptor
;------------------------------------------------
;- GET HID DESCRIPTOR CODE
;------------------------------------------------
; ********************** GET (HID)DESCRIPTOR, ENDPOINT *******************
mov gbFControlBufferLocation, #LOW HIGH16(BEGIN_KBD_HID_DESCRIPTOR)
mov gbFControlBufferLocation+1, #HIGH LOW16(BEGIN_KBD_HID_DESCRIPTOR)
mov gbFControlBufferLocation+2, #LOW LOW16(BEGIN_KBD_HID_DESCRIPTOR)
mov A, #LOW LOW16(END_KBD_HID_DESCRIPTOR - BEGIN_KBD_HID_DESCRIPTOR)
mov B, #HIGH LOW16(END_KBD_HID_DESCRIPTOR - BEGIN_KBD_HID_DESCRIPTOR)
jmp LoadBuffer
CheckGetReportDescriptor:
cjne A, #REPORT_DESCR, ReturnBadSTDGetEPCommand
;------------------------------------------------
;- GET REPORT DESCRIPTOR CODE
;------------------------------------------------
; ********************** GET (REPORT)DESCRIPTOR, ENDPOINT *******************
mov gbFControlBufferLocation, #LOW HIGH16( BEGIN_KBD_REPORT_DESCRIPTOR )
mov gbFControlBufferLocation+1, #HIGH LOW16( BEGIN_KBD_REPORT_DESCRIPTOR )
mov gbFControlBufferLocation+2, #LOW LOW16( BEGIN_KBD_REPORT_DESCRIPTOR )
mov A, #LOW LOW16( END_KBD_REPORT_DESCRIPTOR - BEGIN_KBD_REPORT_DESCRIPTOR )
mov B, #HIGH LOW16( END_KBD_REPORT_DESCRIPTOR - BEGIN_KBD_REPORT_DESCRIPTOR )
jmp LoadBuffer
ReturnBadSTDGetEPCommand:
ReturnSTDGetEPCommand:
jmp SetUpControlReadStatusStage
COMMENT *------------------------------------------------------------
Function name : SetUpControlReadStatusStage
Brief Description : Sets the status in the IN buffer.
Regs preserved : No reg. is saved
--------------------------------------------------------------------*
SCOPE
SetUpControlReadStatusStage:
mov gbSetupSeqRX, #STATUS_PHASE ; Advance State Machine to next state
mov gbSetupSeqTX, #DATA_PHASE
setb TXOE0 ; 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
--------------------------------------------------------------------*
SCOPE
StandardSetEndpointCommand:
; 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
JB ACC.7, ClearInStall
ClearOutStall:
anl EPCON0, #CLEAR_OUT_STALL_MASK
jmp ReturnSTDSetEPCommand
ClearInStall:
anl EPCON0, #CLEAR_IN_STALL_MASK
jmp 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 EPCON0, #SET_OUT_STALL_MASK
jmp ReturnSTDSetEPCommand
SetInStall:
orl EPCON0, #SET_IN_STALL_MASK
jmp ReturnSTDSetEPCommand
ReturnBadSTDSetEPCommand:
ReturnSTDSetEPCommand:
jmp 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
--------------------------------------------------------------------*
SCOPE
StandardSetDeviceCommand:
mov A, bRequest
cjne A, #SET_CONFIGURATION, CheckSetDeviceAddress
SetDeviceConfiguration:
;------------------------------------------------
;- SET DEVICE CONFIGURATION
;------------------------------------------------
;------- TBD -------
; Call SetConfiguration
jmp ReturnSTDSetDevice
CheckSetDeviceAddress:
cjne A, #SET_ADDRESS, ReturnBadSetDeviceCommand
;------------------------------------------------
;- SET DEVICE CONFIGURATION
;------------------------------------------------
; Set Address should just return. The command will be executed following
; the status stage
jmp ReturnSTDSetDevice
ReturnBadSetDeviceCommand:
ReturnSTDSetDevice:
jmp SetUpControlWriteStatusStage
COMMENT *------------------------------------------------------------
Function name : SetUpControlWriteStatusStage
Brief Description : Sets the status in the IN buffer.
Regs preserved : No reg. is saved
--------------------------------------------------------------------*
SCOPE
SetUpControlWriteStatusStage:
mov TXCNT0, #00 ; Setup Null Packet
setb TXOE0
SetUpControlWrite:
mov gbSetupSeqTX, #STATUS_PHASE ; Advance State Machine to next state
mov gbSetupSeqRX, #DATA_PHASE
mov gbFControlBufferBytesLeft, #00 ; No. of bytes to transfer
Ret
;---------------------------------------------
; Will be deleteing some of these.
; Dead code for now.
;---------------------------------------------
ClassGetDeviceCommand:
mov A, bRequest
cjne A, #GET_DESCRIPTOR, OtherClassGetDeviceCommand
GetClassDeviceDescriptor:
; ********************** GET DEVICE DESCRIPTOR, HID ************
; mov WR30, #LOW16(BEGIN_HID_DESCRIPTOR)
mov gbFControlBufferLocation, #LOW HIGH16(BEGIN_DEVICE_DESCRIPTOR)
mov gbFControlBufferLocation+1, #HIGH LOW16(BEGIN_DEVICE_DESCRIPTOR)
mov gbFControlBufferLocation+2, #LOW LOW16(BEGIN_DEVICE_DESCRIPTOR)
mov gbFControlBufferBytesLeft, #12h
LoadBufferTBD:
Call LoadControlTXFifo
jmp SetUpControlReadStatusStage
CheckEntityDescriptor:
; cjne A, #ENTITY_DESCR, OtherClassGetDeviceCommand
; ********************** GET DESCRIPTOR, ENTITY ************
; mov WR30, #LOW16(BEGIN_ENTITY_DESCRIPTOR)
; mov R9, gbEntityDescriptorLen
OtherClassGetDeviceCommand:
; call GetClassDeviceCommand
jmp SetUpControlReadStatusStage
ClassGetOtherCommand:
; call GetClassOtherCommand
jmp SetUpControlReadStatusStage
ClassSetDeviceCommand:
; call SetClassDeviceCommand
jmp SetUpControlWriteStatusStage
ClassSetOtherCommand:
; call SetClassOtherCommand
jmp SetUpControlWriteStatusStage
StandardSetInterfaceCommand:
StandardGetInterfaceCommand:
StandardSetOtherCommand:
StandardGetOtherCommand:
ClassSetInterfaceCommand:
ClassGetInterfaceCommand:
;(SPR)
COMMENT *------------------------------------------------------------
Function name : ClassSetEndpointCommand
Brief Description : Handles the three main class "set" requests:
- Set Report Request
- Set Idle Request
- Set Protocol Request
Regs preserved : No reg. is saved
--------------------------------------------------------------------*
SCOPE
ClassSetEndpointCommand:
mov A, bRequest
cjne A, #009h, CheckSetIdleRequest ;09 = Set Report Request
SetReportRequest:
lcall SetUpControlWrite ; Setup State Machine.
jmp ExitClassSetEndpointCommand
;-------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -