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

📄 usbfs_1_drv.asm

📁 cypresscy74294ic键盘和鼠标原码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: USBFS_1_drv.asm
;;  Version: 1.1, Updated on 2006/06/19 at 11:41:37
;;  Generated by PSoC Designer ver 4.4  b1884 : 14 Jan, 2007
;;
;;  DESCRIPTION: USB Device User Module control endpoint driver
;;               for the CY8C24090 and CY7C64215 family of devices
;;
;;  NOTE: User Module APIs conform to the fastcall16 convention for marshalling
;;        arguments and observe the associated "Registers are volatile" policy.
;;        This means it is the caller's responsibility to preserve any values
;;        in the X and A registers that are still needed after the API functions
;;        returns. For Large Memory Model devices it is also the caller's
;;        responsibility to perserve any value in the CUR_PP, IDX_PP, MVR_PP and
;;        MVW_PP registers. Even though some of these registers may not be modified
;;        now, there is no guarantee that will remain the case in future releases.
;;-----------------------------------------------------------------------------
;;  Copyright (c) Cypress Semiconductor 2005. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************

include "m8c.inc"
include "memory.inc"
include "USBFS_1_macros.inc"
include "USBFS_1.inc"

;-----------------------------------------------
;  Global Symbols
;-----------------------------------------------
export _USBFS_1_EP0_ISR
export  USBFS_1_InitControlRead
export _USBFS_1_InitControlRead
export  USBFS_1_InitControlWrite
export _USBFS_1_InitControlWrite
export  USBFS_1_InitNoDataStageControlTransfer
export _USBFS_1_InitNoDataStageControlTransfer
export  USBFS_1_NoDataStageControlTransfer

;-----------------------------------------------
;  Macro Definitions
;-----------------------------------------------

;-----------------------------------------------
;  Constant Definitions
;-----------------------------------------------

;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA InterruptRAM (RAM,REL,CON)
;----------------------------------------------------------------------------
; Current Device
;----------------------------------------------------------------------------
EXPORT USBFS_1_bCurrentDevice, _USBFS_1_bCurrentDevice
 USBFS_1_bCurrentDevice:
_USBFS_1_bCurrentDevice:                BLK   1    ;  Current Device
;----------------------------------------------------------------------------
; Current Configuration
;----------------------------------------------------------------------------
EXPORT USBFS_1_Configuration, _USBFS_1_Configuration
 USBFS_1_Configuration:
_USBFS_1_Configuration:                 BLK   1    ;  Current Configuration
;----------------------------------------------------------------------------
; Current Device Status
;----------------------------------------------------------------------------
EXPORT USBFS_1_DeviceStatus, _USBFS_1_DeviceStatus
 USBFS_1_DeviceStatus:
_USBFS_1_DeviceStatus:                  BLK   1    ;  Current Device Status
;----------------------------------------------------------------------------
; Interface Setting
;----------------------------------------------------------------------------
; TODO: User Module Parameter determines the number of interfaces
EXPORT USBFS_1_InterfaceSetting, _USBFS_1_InterfaceSetting
 USBFS_1_InterfaceSetting:
_USBFS_1_InterfaceSetting:              BLK   1h    ; Interface Setting
;----------------------------------------------------------------------------
; Endpoint Status--USB Status
;----------------------------------------------------------------------------
EXPORT USBFS_1_EndpointStatus, _USBFS_1_EndpointStatus
 USBFS_1_EndpointStatus:
_USBFS_1_EndpointStatus:                BLK   USB_NUM_ENDPOINTS    ; Endpoint Status
;----------------------------------------------------------------------------
; Last Packet Size
;----------------------------------------------------------------------------
EXPORT USBFS_1_LastSize
 USBFS_1_LastSize:                      BLK   1    ; Last Packet Size
;----------------------------------------------------------------------------
; Control Transfer State Machine
; State values for Control Write
; State values for Control Read
;----------------------------------------------------------------------------
EXPORT USBFS_1_TransferType
 USBFS_1_TransferType:                  BLK   1    ; Control Transfer State Machine
;----------------------------------------------------------------------------
; Control Transfer Intermediate Buffer--Shared among the requests
;----------------------------------------------------------------------------
EXPORT USBFS_1_TransferBuffer
 USBFS_1_TransferBuffer:                BLK   8
;----------------------------------------------------------------------------
; Transfer Descriptor Data for Control Transfer
;  --The following data have the same format as the first 5 bytes of the TD_ENTRY
;----------------------------------------------------------------------------
; Control Transfer Data Source
;   USB_DS_ROM
;   USB_DS_RAM
;   USB_DS_RAM_AS_NEEDED
;----------------------------------------------------------------------------
EXPORT USBFS_1_CurrentTD, _USBFS_1_CurrentTD
_USBFS_1_CurrentTD:
 USBFS_1_CurrentTD:
EXPORT USBFS_1_DataSource, _USBFS_1_DataSource
_USBFS_1_DataSource:
 USBFS_1_DataSource:                    BLK   1
;----------------------------------------------------------------------------
; Control Transfer Data Size
;----------------------------------------------------------------------------
EXPORT USBFS_1_TransferSize, _USBFS_1_TransferSize
_USBFS_1_TransferSize:
 USBFS_1_TransferSize:                  BLK   2
;----------------------------------------------------------------------------
; Control Transfer Data Pointer
;   Source for Control Read
;   Destination for Control Write
;----------------------------------------------------------------------------
EXPORT USBFS_1_DataPtr, _USBFS_1_DataPtr
_USBFS_1_DataPtr:
 USBFS_1_DataPtr:                       BLK   2
;----------------------------------------------------------------------------
; Transfer Completion Notification
;----------------------------------------------------------------------------
EXPORT USBFS_1_StatusBlockPtr, _USBFS_1_StatusBlockPtr
_USBFS_1_StatusBlockPtr:
 USBFS_1_StatusBlockPtr:                BLK   2

;----------------------------------------------------------------------------
; Control Transfer _TransferByteCount (Actually transfered
;----------------------------------------------------------------------------
 USBFS_1_TransferByteCount:             BLK   2

;----------------------------------------------------------------------------
; Control Endpoint Data toggle
EXPORT USBFS_1_EPDataToggle, _USBFS_1_EPDataToggle
 _USBFS_1_EPDataToggle:
 USBFS_1_EPDataToggle:
 USBFS_1_EP0DataToggle:                 BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
EXPORT USBFS_1_fDataPending
 USBFS_1_fDataPending:                  BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
;EXPORT USBFS_1_PendingData
; USBFS_1_PendingData:                  BLK   1
;----------------------------------------------------------------------------
; Temporary Data registers
EXPORT USBFS_1_t2, USBFS_1_t1, USBFS_1_t0
 USBFS_1_t2:                            BLK   1    ; Temporary shared by the UM
 USBFS_1_t1:                            BLK   1    ; Temporary shared by the UM
 USBFS_1_t0:                            BLK   1    ; Temporary shared by the UM

;EXPORT USBFS_1_IntState
; USBFS_1_IntState:                     BLK  1
;EXPORT USBFS_1_StackPointer
; USBFS_1_StackPointer:                 BLK  1
;EXPORT USBFS_1_TempMode
; USBFS_1_TempMode:                     BLK 1
;----------------------------------------------------------------------------
; Endpoint Transfer--API Status
;----------------------------------------------------------------------------
EXPORT USBFS_1_EndpointAPIStatus, _USBFS_1_EndpointAPIStatus
 USBFS_1_EndpointAPIStatus:
_USBFS_1_EndpointAPIStatus:             BLK   USB_NUM_ENDPOINTS    ; Endpoint Status

IF 1
ELSE
ERROR_RUN_USB_WIZARD
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; In order for the USB User Module to compile properly the USB Wizard must be run.
; To do this navigate back to the Device Editor Window, right click on the icon for the
; USB User Module and select the 'USB Setup Wizard...'.  Configure the device as needed
; and then click OK.  Re-generate source before compiling again.
; For HID devices it is important that all instances of HID Class Descriptors point to a valid
; HID report.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF

AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_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:
;
;-----------------------------------------------------------------------------
 USBFS_1_EP0_ISR:
_USBFS_1_EP0_ISR:
        push A
        push X
    REG_PRESERVE MVW_PP
    REG_PRESERVE MVR_PP

    RAM_SETPAGE_MVW 0
    RAM_SETPAGE_MVR 0

    ; Dispatch to setup/in/out handlers
    MOV  A, reg[USBFS_1_EP0MODE]        ; Get the mode reg

 ;   MOV  [USBFS_1_TempMode], USB_MODE_NAK_IN_OUT
 ;   MOV  reg[USBFS_1_EP0MODE], USB_MODE_NAK_IN_OUT
    ; MSB is the SETUP bit, followed by IN, then OUT
    ASL  A                              ; Shift to the carry and jump if SETUP bit set
    JC   USBFS_1_EP0_Setup

    ASL  A                              ; Shift to the carry and jump if IN bit set
    JC   USBFS_1_EP0_IN

    ASL  A                              ; Shift to the carry and jump if OUT bit set
    JC   USBFS_1_EP0_OUT

    JMP    USBFS_1_Not_Supported_Local_Drv

; ISR Exit Point to update the mode register
;   mode and count have been pushed onto the stack
EXPORT USBFS_1_EP0_UPD_MODE_EXIT
USBFS_1_EP0_UPD_MODE_EXIT:

    MOV    REG[USBFS_1_EP0CNT], A      ; Update the count
    MOV    A, X                        ; Get the new mode
    MOV    REG[USBFS_1_EP0MODE], A     ; Update the node

; Common Exit Point
USBFS_1_EP0_ISR_EXIT:
    REG_RESTORE MVR_PP
    REG_RESTORE MVW_PP
    POP  X                              ;
;       MOV  A, [USBFS_1_TempMode]
;       MOV  reg[USBFS_1_EP0MODE], A
    POP  A                              ; Restore Context
    RETI


;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_EP0_Setup
;
;  DESCRIPTION:   Dispatch a USB SETUP
;
;-----------------------------------------------------------------------------
 USBFS_1_EP0_Setup:
_USBFS_1_EP0_Setup:
; Check the byte count and validity.  All SETUP are 8 bytes and 0 toggle
    PUSH    A                          ; Save the mode register
    MOV     A, USB_XFER_PREMATURE      ; Return a Premature Completion?
    CALL    USBFS_1_UpdateStatusBlock
    POP     A                          ; Restore the mode register
    MOV    A, REG[USBFS_1_EP0CNT]            ; Get the count reg
    CMP    A, (USB_CNT_VALID | 0x0A)
    JZ      .dispatch

    JMP    USBFS_1_Not_Supported_Local_Drv


;-----------------------------------------------------------------------------
; Jump here to dispatch the request
; The SETUP request is encoded in [bmRequestType]. Among the 8 bits in [bmRequestType], only bits
; 7,6,5,1,0 determine what the request is. Bits [2:4] are default to zero. The below code
; re-organizes [bmRequestType] to the following format:
; ( Zero, Zero, Bit7, Bit6, Bit5, Bit1, Bit0, Zero ), and depending on the value of this
; "re-organization", the firmware will jump to an appropriate table to handle the request.
;-----------------------------------------------------------------------------
.dispatch:
    MOV     A, REG[USBFS_1_EP0DATA+bmRequestType]   ; Get bmRequestType
    AND     A, E3h                           ; clear bits 4-3-2, these unused for our purposes
    PUSH    A                                ; store value on the stack
    ASR     A                                ; move bits 7-6-5 into 4-3-2's place
    ASR     A                                ; "asr" instruction shift all bits one place to the right.
    ASR     A                                ; Bit7 remains the same.
    MOV     [USBFS_1_t2], A                  ; store shifted value
    POP     A                                ; get original value
    OR      A, [USBFS_1_t2]                  ; or the two to get the 5-bit field
    AND     A, 1Fh                           ; clear bits 7-6-5 (asr wraps bit7)
                                             ; Bit0 is loaded with a Zero. This results in multiplying
                                             ; the accumulator by 2, and the reason to mutiply it by 2
                                             ; is that each "jmp" instruction in the tables is two bytes long.

    LJMP USBFS_1_bmRequestType_Dispatch


;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_EP0_IN
;
;  DESCRIPTION: Handles an IN request.  Depending on the state of the
;               enumeration sequence it decides what to do next
;
;-----------------------------------------------------------------------------
 USBFS_1_EP0_IN:
_USBFS_1_EP0_IN:

    MOV  A, [USBFS_1_TransferType]
;    CALL USBFS_1_ControlInDispatch
;    JMP  USBFS_1_EP0_ISR_EXIT               ; And exit
USBFS_1_ControlInDispatch:
    JACC    USBFS_1_ControlInDispatchTable
USBFS_1_ControlInDispatchTable:
    JMP     USBFS_1_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
    JMP     USBFS_1_ControlReadDataStage     ; USB_TRANS_STATE_CONTROL_READ
    JMP     USBFS_1_ControlWriteStatusStage  ; USB_TRANS_STATE_CONTROL_WRITE
    JMP     USBFS_1_NoDataControlStatusStage ; USB_TRANS_STATE_NO_DATA_CONTROL


;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_EP0_OUT
;
;  DESCRIPTION: HANDles an OUT request.  Depending on the state of the
;               enumeration sequence it decides what to do next
;
;-----------------------------------------------------------------------------
 USBFS_1_EP0_OUT:
_USBFS_1_EP0_OUT:
    MOV     A, [USBFS_1_TransferType]
    JACC    USBFS_1_ControlOutDispatchTable
USBFS_1_ControlOutDispatchTable:
    JMP     USBFS_1_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
    JMP     USBFS_1_ControlReadStatusStage   ; USB_TRANS_STATE_CONTROL_READ
    JMP     USBFS_1_ControlWriteDataStage    ; USB_TRANS_STATE_CONTROL_WRITE

⌨️ 快捷键说明

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