⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_drv.lis

📁 Cypress cy7c63318 鼠标开发板的源代码
💻 LIS
📖 第 1 页 / 共 5 页
字号:
 0012            USB_TransferSize:
 0012            _USB_TransferSize:                    BLK   2
 0014           ;----------------------------------------------------------------------------
 0014           ; Control Transfer Data Pointer
 0014           ;   Source for Control Read
 0014           ;   Destination for Control Write
 0014           ;----------------------------------------------------------------------------
                EXPORT USB_DataPtr, _USB_DataPtr
 0014            USB_DataPtr:
 0014            _USB_DataPtr:                         BLK   2
 0016           ;----------------------------------------------------------------------------
 0016           ; Transfer Completion Notification
 0016           ;----------------------------------------------------------------------------
                EXPORT USB_StatusBlockPtr, _USB_StatusBlockPtr
 0016            USB_StatusBlockPtr:
 0016            _USB_StatusBlockPtr:                  BLK   2
 0018           ;----------------------------------------------------------------------------
 0018           ; Control Transfer _TransferByteCount (Actually transfered)
 0018           ;----------------------------------------------------------------------------
 0018            USB_TransferByteCount:                 BLK   2
 001A           ;----------------------------------------------------------------------------
 001A           ; Control Endpoint Data toggle
                EXPORT USB_EPDataToggle
 001A            USB_EPDataToggle:
 001A            USB_EP0DataToggle:                     BLK   1
 001B           ;----------------------------------------------------------------------------
 001B           ; Control Endpoint Data Pending Flag
                EXPORT USB_fDataPending
 001B            USB_fDataPending:                      BLK   1
 001C           ;----------------------------------------------------------------------------
 001C           ; Control Endpoint Data Pending Flag
 001C           ;EXPORT USB_PendingData
 001C           ; USB_PendingData:                      BLK   1
 001C           ;----------------------------------------------------------------------------
 001C           ; Temporary Data registers
                EXPORT USB_t2, USB_t1, USB_t0
 001C            USB_t2:                                BLK   1    ; Temporary shared by the UM
 001D            USB_t1:                                BLK   1    ; Temporary shared by the UM
 001E            USB_t0:                                BLK   1    ; Temporary shared by the UM
 001F           ;----------------------------------------------------------------------------
 001F           ; Endpoint Transfer--API Status
 001F           ;----------------------------------------------------------------------------
                EXPORT USB_EndpointAPIStatus, _USB_EndpointAPIStatus
 001F            USB_EndpointAPIStatus:
 001F           _USB_EndpointAPIStatus:                 BLK   USB_NUM_ENDPOINTS    ; Endpoint Status
 0022           
                AREA UserModules (ROM, REL)
                ;-----------------------------------------------------------------------------
                ;  FUNCTION NAME: USB_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            USB_EP0_ISR:
 0000           _USB_EP0_ISR:
 0000 08            PUSH    A                          ; Save the context
 0001 10            PUSH    X                          ; 
 0002               ; Dispatch to setup/in/out handlers
                EXPORT  USB_mode_read
 0002           USB_mode_read:
 0002 5D44         MOV    A, REG[USB_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      USB_EP0_Setup
 0007           
 0007 64            asl    a                           ; Shift to the carry and jump if IN bit set
 0008 C02E          jc      USB_EP0_IN
 000A           
 000A 64            asl    a                           ; Shift to the carry and jump if OUT bit set
 000B C037          jc     USB_EP0_OUT
 000D 8258          JMP    USB_Not_Supported_Local_Drv
 000F           ; ISR Exit Point to update the mode register
 000F           ;   mode and count have been pushed onto the stack
                EXPORT USB_EP0_UPD_MODE_EXIT
 000F           USB_EP0_UPD_MODE_EXIT:
 000F           
 000F 6041          MOV    REG[USB_EP0CNT], A          ; Update the count   
 0011 5B            MOV    A, X                        ; Get the new mode
 0012 6044          MOV    REG[USB_EP0MODE], A         ; Update the node   
 0014           
 0014           USB_EP0_ISR_EXIT:
 0014               
 0014 20            POP X                              ; 
 0015 18            POP A                              ; Restore Context
 0016 7E            RETI
 0017           ;-----------------------------------------------------------------------------
 0017           ;  FUNCTION NAME: USB_EP0_Setup
 0017           ;
 0017           ;  DESCRIPTION:   Dispatch a USB SETUP 
 0017           ;
 0017           ;-----------------------------------------------------------------------------
 0017            USB_EP0_Setup:
 0017           _USB_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    USB_UpdateStatusBlock
 001C 18            POP     A                          ; Restore the mode register
 001D 5D41          MOV    A, REG[USB_EP0CNT]                ; Get the count reg
 001F 394A          CMP    A, (USB_CNT_VALID | 0x0A)            
 0021 A003          JZ      .dispatch
 0023           
 0023 8242          JMP    USB_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[USB_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 531C          MOV     [USB_t2], A                      ; store shifted value
 002F 18            POP     A                                ; get original value
 0030 2A1C          OR      A, [USB_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 USB_bmRequestType_Dispatch
 0037           ;-----------------------------------------------------------------------------
 0037           ;  FUNCTION NAME: USB_EP0_IN
 0037           ;
 0037           ;  DESCRIPTION:   Dispatch a USB IN
 0037           ;
 0037           ;-----------------------------------------------------------------------------
 0037            USB_EP0_IN:
 0037           _USB_EP0_IN:
 0037              
 0037 5108          MOV     A, [USB_TransferType]
 0039           USB_ControlInDispatch:               
 0039 E001          JACC    USB_ControlInDispatchTable
 003B           USB_ControlInDispatchTable:
 003B 822A          JMP     USB_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
 003D 8037          JMP     USB_ControlReadDataStage     ; USB_TRANS_STATE_CONTROL_READ
 003F 80AD          JMP     USB_ControlWriteStatusStage  ; USB_TRANS_STATE_CONTROL_WRITE
 0041 80B8          JMP     USB_NoDataControlStatusStage ; USB_TRANS_STATE_NO_DATA_CONTROL
 0043           ;-----------------------------------------------------------------------------
 0043           ;  FUNCTION NAME: USB_EP0_OUT
 0043           ;
 0043           ;  DESCRIPTION:   Dispatch a USB OUT
 0043           ;
 0043           ;-----------------------------------------------------------------------------
 0043            USB_EP0_OUT:
 0043           _USB_EP0_OUT:
 0043 5108          MOV     A, [USB_TransferType]
 0045 E001          JACC    USB_ControlOutDispatchTable
 0047           USB_ControlOutDispatchTable:
 0047 821E          JMP     USB_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
 0049 802D          JMP     USB_ControlReadStatusStage   ; USB_TRANS_STATE_CONTROL_READ
 004B 805E          JMP     USB_ControlWriteDataStage    ; USB_TRANS_STATE_CONTROL_WRITE
 004D 80C6          JMP     USB_NoDataControlError       ; USB_TRANS_STATE_NO_DATA_CONTROL
 004F           ;-----------------------------------------------------------------------------
 004F           ;  FUNCTION NAME: USB_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 USB_CurrentTD data structure.
 004F           ;
 004F           ;-----------------------------------------------------------------------------
 004F            USB_InitControlRead:
 004F 5307          MOV     [USB_LastSize], A          ; Save the packet size?
 0051 91B9          CALL    USB_InitializeStatusBlock
 0053 550802        MOV     [USB_TransferType], USB_TRANS_STATE_CONTROL_READ
 0056               
 0056               ; Check the transfer size against the request size
 0056 5D57          MOV    A, REG[USB_EP0DATA+wLengthHi] ; MSB of wLength
 0058 3A12          CMP    A, [USB_TransferSize]
 005A B007          JNZ    .L1
 005C           
 005C 5D56          MOV    A, REG[USB_EP0DATA+wLengthLo] ; LSB of wLength
 005E 3A13          CMP    A, [USB_TransferSize+1]
 0060 A009          JZ     .L9
 0062           .L1:
 0062 D007          JNC    .L9
 0064           ;    
 0064 5313          MOV    [USB_TransferSize+1], A     ; 
 0066 5D57          MOV    A, REG[USB_EP0DATA+wLengthHi] ; 
 0068 5312          MOV    [USB_TransferSize], A       ; 
 006A           .L9:
 006A 551800        MOV    [USB_TransferByteCount], 0  ; 
 006D 551900        MOV    [USB_TransferByteCount+1], 0; 
 007

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -