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

📄 usb_drv.asm

📁 利用psoc进行usb及capsense的程序编写
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: USB_drv.asm
;;  @Version@
;;  Generated by PSoC Designer ver 4.2  b1013 : 02 September, 2004
;;
;;  DESCRIPTION: USB Device User Module control endpoint driver
;;               for the CY8C24090 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 "USB_macros.inc"
include "USB.inc"

;-----------------------------------------------
;  Global Symbols		 
;-----------------------------------------------
export  USB_EP0_ISR
export _USB_EP0_ISR
export  USB_InitControlRead
export  USB_InitControlWrite
export  USB_NoDataStageControlTransfer

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

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

;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA InterruptRAM (RAM,REL,CON)
;----------------------------------------------------------------------------
; Current Device
;----------------------------------------------------------------------------
EXPORT USB_bCurrentDevice, _USB_bCurrentDevice
 USB_bCurrentDevice:
_USB_bCurrentDevice:                    BLK   1    ;  Current Device
;----------------------------------------------------------------------------
; Current Configuration
;----------------------------------------------------------------------------
EXPORT USB_Configuration, _USB_Configuration
 USB_Configuration:
_USB_Configuration:                     BLK   1    ;  Current Configuration
;----------------------------------------------------------------------------
; Current Device Status
;----------------------------------------------------------------------------
EXPORT USB_DeviceStatus, _USB_DeviceStatus
 USB_DeviceStatus:
_USB_DeviceStatus:                      BLK   1    ;  Current Device Status
;----------------------------------------------------------------------------
; Interface Setting
;----------------------------------------------------------------------------
; TODO: User Module Parameter determines the number of interfaces
EXPORT USB_InterfaceSetting, _USB_InterfaceSetting
 USB_InterfaceSetting:
_USB_InterfaceSetting:                  BLK   1    ; Interface Setting
;----------------------------------------------------------------------------
; Endpoint Status--USB Status
;----------------------------------------------------------------------------
EXPORT USB_EndpointStatus, _USB_EndpointStatus
 USB_EndpointStatus:
_USB_EndpointStatus:                    BLK   USB_NUM_ENDPOINTS    ; Endpoint Status
;----------------------------------------------------------------------------
; Last Packet Size
;----------------------------------------------------------------------------
EXPORT USB_LastSize 
 USB_LastSize:                          BLK   1    ; Last Packet Size
;----------------------------------------------------------------------------
; Control Transfer State Machine
; State values for Control Write
; State values for Control Read
;----------------------------------------------------------------------------
EXPORT USB_TransferType 
 USB_TransferType:                      BLK   1    ; Control Transfer State Machine
;----------------------------------------------------------------------------
; Control Transfer Intermediate Buffer--Shared among the requests
;----------------------------------------------------------------------------
EXPORT USB_TransferBuffer 
 USB_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 USB_CurrentTD, _USB_CurrentTD
_USB_CurrentTD:
 USB_CurrentTD:
EXPORT USB_DataSource, _USB_DataSource
_USB_DataSource:
 USB_DataSource:                        BLK   1
;----------------------------------------------------------------------------
; Control Transfer Data Size
;----------------------------------------------------------------------------
EXPORT USB_TransferSize, _USB_TransferSize
_USB_TransferSize:
 USB_TransferSize:                      BLK   2
;----------------------------------------------------------------------------
; Control Transfer Data Pointer
;   Source for Control Read
;   Destination for Control Write
;----------------------------------------------------------------------------
EXPORT USB_DataPtr, _USB_DataPtr
_USB_DataPtr: 
 USB_DataPtr:                           BLK   2
;----------------------------------------------------------------------------
; Control Transfer Index
;----------------------------------------------------------------------------
 USB_Index:                             BLK   2
;----------------------------------------------------------------------------
; Control Endpoint Data toggle
EXPORT USB_EPDataToggle, _USB_EPDataToggle
 _USB_EPDataToggle:
 USB_EPDataToggle:
 USB_EP0DataToggle:                     BLK   USB_NUM_ENDPOINTS
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
EXPORT USB_fDataPending
 USB_fDataPending:                      BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
EXPORT USB_PendingData
  USB_PendingData:                      BLK   1

;----------------------------------------------------------------------------
; Temporary Data registers
EXPORT USB_t2, USB_t1, USB_t0
 USB_t2:                                BLK   1    ; Temporary shared by the UM
 USB_t1:                                BLK   1    ; Temporary shared by the UM
 USB_t0:                                BLK   1    ; Temporary shared by the UM

EXPORT USB_IntState
 USB_IntState:                          BLK  1
EXPORT USB_StackPointer
 USB_StackPointer:                      BLK  1
EXPORT USB_TempMode 
 USB_TempMode:                          BLK 1
;----------------------------------------------------------------------------
; Endpoint Transfer--API Status
;----------------------------------------------------------------------------
EXPORT USB_EndpointAPIStatus, _USB_EndpointAPIStatus
 USB_EndpointAPIStatus:
_USB_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: USB_EP0_ISR
;
;  DESCRIPTION: This is the entry point into the Endpoint 0 ISR.  EP0 is 
;               responsible for control transfers and is therefore used
;               for device enumeration
;
 USB_EP0_ISR:
_USB_EP0_ISR:
;	tst  [USB_IntState], 0xFF 
;	jnz   .restoreStack                   ; If we are in a nested call
	push A
	push X
    REG_PRESERVE MVW_PP
    REG_PRESERVE MVR_PP
;	REG_PRESERVE INT_MSK0
;	REG_PRESERVE INT_MSK1
;	REG_PRESERVE INT_MSK2
;	REG_PRESERVE INT_MSK3
    
;    mov     reg[INT_MSK0], 0
;    mov     reg[INT_MSK1], 0
;    mov     reg[INT_MSK2], USB_INT_EP0_MASK
;    mov     reg[INT_MSK3], 0
    
;	mov  X, SP
;	mov  A, X
;	mov  [USB_StackPointer], A
;	inc  [USB_IntState]
;	M8C_EnableGInt 
;	jmp  .continueEP0

;.restoreStack:
;	mov  A, [USB_StackPointer]
;	swap A, SP
;	M8C_EnableGInt

;.continueEP0:

    RAM_SETPAGE_MVW 0
    RAM_SETPAGE_MVR 0 

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

    mov  [USB_TempMode], USB_MODE_NAK_IN_OUT  
    mov  reg[USB_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	 USB_EP0_Setup

    asl	 A                              ; Shift to the carry and jump if IN bit set
    jc	 USB_EP0_IN

    asl	 A                              ; Shift to the carry and jump if OUT bit set
    jc	 USB_EP0_OUT
    
    ljmp  USB_Not_Supported
; Common Exit Point
USB_EP0_ISR_EXIT:
;    M8C_DisableGInt
;    REG_RESTORE INT_MSK3    
;    REG_RESTORE INT_MSK2    
;    REG_RESTORE INT_MSK1    
;    REG_RESTORE INT_MSK0    
    REG_RESTORE MVR_PP
    REG_RESTORE MVW_PP    
    pop  X                              ; 
	mov  A, [USB_TempMode] 
	mov  reg[USB_EP0MODE], A
    pop  A                              ; Restore Context
;    mov  [USB_IntState], 0
    reti
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_EP0_Setup
;
;  DESCRIPTION: Dispatches handlers for the specific setup request received
;
 USB_EP0_Setup:
_USB_EP0_Setup:
; Check the byte count and validity.  All SETUP are 8 bytes and 0 toggle
    mov  A, reg[USB_EP0CNT]                  ; Get the count reg
    cmp  A, (USB_CNT_VALID | 0x0A)            
    jz   .dispatch

    jmp  USB_Not_Supported_Local2
;-----------------------------------------------------------------------------
; 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.		

⌨️ 快捷键说明

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