📄 myusb_drv.lis
字号:
0013 ;----------------------------------------------------------------------------
0013 ; Control Transfer Data Size
0013 ;----------------------------------------------------------------------------
EXPORT myUSB_TransferSize, _myUSB_TransferSize
0013 myUSB_TransferSize:
0013 _myUSB_TransferSize: BLK 2
0015 ;----------------------------------------------------------------------------
0015 ; Control Transfer Data Pointer
0015 ; Source for Control Read
0015 ; Destination for Control Write
0015 ;----------------------------------------------------------------------------
EXPORT myUSB_DataPtr, _myUSB_DataPtr
0015 myUSB_DataPtr:
0015 _myUSB_DataPtr: BLK 2
0017 ;----------------------------------------------------------------------------
0017 ; Transfer Completion Notification
0017 ;----------------------------------------------------------------------------
EXPORT myUSB_StatusBlockPtr, _myUSB_StatusBlockPtr
0017 myUSB_StatusBlockPtr:
0017 _myUSB_StatusBlockPtr: BLK 2
0019 ;----------------------------------------------------------------------------
0019 ; Control Transfer _TransferByteCount (Actually transfered)
0019 ;----------------------------------------------------------------------------
0019 myUSB_TransferByteCount: BLK 2
001B ;----------------------------------------------------------------------------
001B ; Control Endpoint Data toggle
EXPORT myUSB_EPDataToggle
001B myUSB_EPDataToggle:
001B myUSB_EP0DataToggle: BLK 1
001C ;----------------------------------------------------------------------------
001C ; Control Endpoint Data Pending Flag
EXPORT myUSB_fDataPending
001C myUSB_fDataPending: BLK 1
001D ;----------------------------------------------------------------------------
001D ; Control Endpoint Data Pending Flag
001D ;EXPORT myUSB_PendingData
001D ; myUSB_PendingData: BLK 1
001D ;----------------------------------------------------------------------------
001D ; Temporary Data registers
EXPORT myUSB_t2, myUSB_t1, myUSB_t0
001D myUSB_t2: BLK 1 ; Temporary shared by the UM
001E myUSB_t1: BLK 1 ; Temporary shared by the UM
001F myUSB_t0: BLK 1 ; Temporary shared by the UM
0020 ;----------------------------------------------------------------------------
0020 ; Endpoint Transfer--API Status
0020 ;----------------------------------------------------------------------------
EXPORT myUSB_EndpointAPIStatus, _myUSB_EndpointAPIStatus
0020 myUSB_EndpointAPIStatus:
0020 _myUSB_EndpointAPIStatus: BLK USB_NUM_ENDPOINTS ; Endpoint Status
0023
AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
; FUNCTION NAME: myUSB_EP0_ISR
;
; DESCRIPTION: The EPO ISR serves the control endpoint interrupts and
; dispaches all SETUP, IN, and OUT transfers to the proper
; dispatch routines for all supported USB requests.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: n/a
;
; RETURNS: n/a
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
0000 myUSB_EP0_ISR:
0000 _myUSB_EP0_ISR:
0000 08 PUSH A ; Save the context
0001 10 PUSH X ;
0002 ; Dispatch to setup/in/out handlers
EXPORT myUSB_mode_read
0002 myUSB_mode_read:
0002 5D44 MOV A, REG[myUSB_EP0MODE] ; Get the mode reg
0004
0004 ; MSB is the SETUP bit, followed by IN, then OUT
0004 64 asl a ; Shift to the carry and jump if SETUP bit set
0005 C011 jc myUSB_EP0_Setup
0007
0007 64 asl a ; Shift to the carry and jump if IN bit set
0008 C02E jc myUSB_EP0_IN
000A
000A 64 asl a ; Shift to the carry and jump if OUT bit set
000B C037 jc myUSB_EP0_OUT
000D 8258 JMP myUSB_Not_Supported_Local_Drv
000F ; ISR Exit Point to update the mode register
000F ; mode and count have been pushed onto the stack
EXPORT myUSB_EP0_UPD_MODE_EXIT
000F myUSB_EP0_UPD_MODE_EXIT:
000F
000F 6041 MOV REG[myUSB_EP0CNT], A ; Update the count
0011 5B MOV A, X ; Get the new mode
0012 6044 MOV REG[myUSB_EP0MODE], A ; Update the node
0014
0014 myUSB_EP0_ISR_EXIT:
0014
0014 20 POP X ;
0015 18 POP A ; Restore Context
0016 7E RETI
0017 ;-----------------------------------------------------------------------------
0017 ; FUNCTION NAME: myUSB_EP0_Setup
0017 ;
0017 ; DESCRIPTION: Dispatch a USB SETUP
0017 ;
0017 ;-----------------------------------------------------------------------------
0017 myUSB_EP0_Setup:
0017 _myUSB_EP0_Setup:
0017 ; Check the byte count and validity. All SETUP are 8 bytes and 0 toggle
0017 08 PUSH A ; Save the mode register
0018 5002 MOV A, USB_XFER_PREMATURE ; Return a Premature Completion?
001A 91DA CALL myUSB_UpdateStatusBlock
001C 18 POP A ; Restore the mode register
001D 5D41 MOV A, REG[myUSB_EP0CNT] ; Get the count reg
001F 394A CMP A, (USB_CNT_VALID | 0x0A)
0021 A003 JZ .dispatch
0023
0023 8242 JMP myUSB_Not_Supported_Local_Drv
0025 ;-----------------------------------------------------------------------------
0025 ; Jump here to dispatch the request
0025 ; The SETUP request is encoded in [bmRequestType]. Among the 8 bits in [bmRequestType], only bits
0025 ; 7,6,5,1,0 determine what the request is. Bits [2:4] are default to zero. The below code
0025 ; re-organizes [bmRequestType] to the following format:
0025 ; ( Zero, Zero, Bit7, Bit6, Bit5, Bit1, Bit0, Zero ), and depending on the value of this
0025 ; "re-organization", the firmware will jump to an appropriate table to handle the request.
0025 ;-----------------------------------------------------------------------------
0025 .dispatch:
0025 5D50 MOV A, REG[myUSB_EP0DATA+bmRequestType] ; Get bmRequestType
0027 21E3 AND A, E3h ; clear bits 4-3-2, these unused for our purposes
0029 08 PUSH A ; store value on the stack
002A 67 ASR A ; move bits 7-6-5 into 4-3-2's place
002B 67 ASR A ; "asr" instruction shift all bits one place to the right.
002C 67 ASR A ; Bit7 remains the same.
002D 531D MOV [myUSB_t2], A ; store shifted value
002F 18 POP A ; get original value
0030 2A1D OR A, [myUSB_t2] ; or the two to get the 5-bit field
0032 211F AND A, 1Fh ; clear bits 7-6-5 (asr wraps bit7)
0034 ; Bit0 is loaded with a Zero. This results in multiplying
0034 ; the accumulator by 2, and the reason to mutiply it by 2
0034 ; is that each "jmp" instruction in the tables is two bytes long.
0034
0034 7D025D LJMP myUSB_bmRequestType_Dispatch
0037 ;-----------------------------------------------------------------------------
0037 ; FUNCTION NAME: myUSB_EP0_IN
0037 ;
0037 ; DESCRIPTION: Dispatch a USB IN
0037 ;
0037 ;-----------------------------------------------------------------------------
0037 myUSB_EP0_IN:
0037 _myUSB_EP0_IN:
0037
0037 5109 MOV A, [myUSB_TransferType]
0039 myUSB_ControlInDispatch:
0039 E001 JACC myUSB_ControlInDispatchTable
003B myUSB_ControlInDispatchTable:
003B 822A JMP myUSB_Not_Supported_Local_Drv ; USB_TRANS_STATE_IDLE
003D 8037 JMP myUSB_ControlReadDataStage ; USB_TRANS_STATE_CONTROL_READ
003F 80AD JMP myUSB_ControlWriteStatusStage ; USB_TRANS_STATE_CONTROL_WRITE
0041 80B8 JMP myUSB_NoDataControlStatusStage ; USB_TRANS_STATE_NO_DATA_CONTROL
0043 ;-----------------------------------------------------------------------------
0043 ; FUNCTION NAME: myUSB_EP0_OUT
0043 ;
0043 ; DESCRIPTION: Dispatch a USB OUT
0043 ;
0043 ;-----------------------------------------------------------------------------
0043 myUSB_EP0_OUT:
0043 _myUSB_EP0_OUT:
0043 5109 MOV A, [myUSB_TransferType]
0045 E001 JACC myUSB_ControlOutDispatchTable
0047 myUSB_ControlOutDispatchTable:
0047 821E JMP myUSB_Not_Supported_Local_Drv ; USB_TRANS_STATE_IDLE
0049 802D JMP myUSB_ControlReadStatusStage ; USB_TRANS_STATE_CONTROL_READ
004B 805E JMP myUSB_ControlWriteDataStage ; USB_TRANS_STATE_CONTROL_WRITE
004D 80C6 JMP myUSB_NoDataControlError ; USB_TRANS_STATE_NO_DATA_CONTROL
004F ;-----------------------------------------------------------------------------
004F ; FUNCTION NAME: myUSB_InitControlRead
004F ;
004F ; DESCRIPTION: This routine initializes a control read. It must be JUMPed to,
004F ; not called. It assumes a tranfer descriptor has been loaded
004F ; into the driver myUSB_CurrentTD data structure.
004F ;
004F ;-----------------------------------------------------------------------------
004F myUSB_InitControlRead:
004F 5308 MOV [myUSB_LastSize], A ; Save the packet size?
0051 91B9 CALL myUSB_InitializeStatusBlock
0053 550902 MOV [myUSB_TransferType], USB_TRANS_STATE_CONTROL_READ
0056
0056 ; Check the transfer size against the request size
0056 5D57 MOV A, REG[myUSB_EP0DATA+wLengthHi] ; MSB of wLength
0058 3A13 CMP A, [myUSB_TransferSize]
005A B007 JNZ .L1
005C
005C 5D56 MOV A, REG[myUSB_EP0DATA+wLengthLo] ; LSB of wLength
005E 3A14 CMP A, [myUSB_TransferSize+1]
0060 A009 JZ .L9
0062 .L1:
0062 D007 JNC .L9
0064 ;
0064 5314 MOV [myUSB_TransferSize+1], A ;
0066 5D57 MOV A, REG[my
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -