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

📄 usb_1_drv.asm

📁 详细的无线键盘,鼠标,无线桥 开发文档.包含电路原理图,电路板光汇文件.FIREWALL, 驱动程序等.有此文档,就可以完全直接生产出来无线键盘,鼠标,无线桥.整个一套完整的解决方案.
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: USB_1_drv.asm
;;   Version: 1.5, Updated on 2006/06/19 at 11:43:56
;;  Generated by PSoC Designer ver 4.3  b1884 : 23 June, 2006
;;
;;  DESCRIPTION: USB Device User Module control endpoint driver
;;               for the enCoRe II family of devices
;;
;;  NOTE: User Module APIs conform to the fastcall 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
;;        function returns. Even though these registers may be preserved now,
;;        there is no guarantee they will be preserved in future releases.
;;-----------------------------------------------------------------------------
;;  Copyright (c) Cypress Semiconductor 2004. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************

include "m8c.inc"
include "USB_1_macros.inc"
include "USB_1.inc"

;-----------------------------------------------
;  Global Symbols
;-----------------------------------------------
export  _USB_1_EP0_ISR
export  USB_1_InitControlRead
export  USB_1_InitControlWrite
export  USB_1_InitNoDataStageControlTransfer
export  USB_1_NoDataStageControlTransfer

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

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

;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA bss (RAM,REL)
;----------------------------------------------------------------------------
; Current Device
;----------------------------------------------------------------------------
EXPORT USB_1_bCurrentDevice
USB_1_bCurrentDevice:                   BLK   1    ;  Current Device
;----------------------------------------------------------------------------
; Current Configuration
;----------------------------------------------------------------------------
EXPORT USB_1_Configuration, _USB_1_Configuration
_USB_1_Configuration:
 USB_1_Configuration:                   BLK   1    ;  Current Configuration
;----------------------------------------------------------------------------
; Current Device Status
;----------------------------------------------------------------------------
EXPORT USB_1_DeviceStatus
 USB_1_DeviceStatus:                    BLK   1    ;  Current Device Status
;----------------------------------------------------------------------------
; Interface Setting
;----------------------------------------------------------------------------
EXPORT USB_1_InterfaceSetting
 USB_1_InterfaceSetting:                BLK   2h    ; Interface Setting
;----------------------------------------------------------------------------
; Endpoint Status--USB Status
;----------------------------------------------------------------------------
EXPORT USB_1_EndpointStatus
 USB_1_EndpointStatus:                  BLK   USB_NUM_ENDPOINTS    ; Endpoint Status
;----------------------------------------------------------------------------
; Last Packet Size
;----------------------------------------------------------------------------
EXPORT USB_1_LastSize
 USB_1_LastSize:                        BLK   1    ;  Last Packet Size
;----------------------------------------------------------------------------
; Control Transfer State Machine
; State values for Control Write
; State values for Control Read
;----------------------------------------------------------------------------
EXPORT USB_1_TransferType
 USB_1_TransferType:                    BLK   1    ; Control Transfer State Machine
;----------------------------------------------------------------------------
; Control Transfer Intermediate Buffer--Shared among the requests
;----------------------------------------------------------------------------
EXPORT USB_1_TransferBuffer
 USB_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 USB_1_CurrentTD, _USB_1_CurrentTD
 USB_1_CurrentTD:
_USB_1_CurrentTD:
EXPORT USB_1_DataSource, _USB_1_DataSource
 USB_1_DataSource:
_USB_1_DataSource:                     BLK   1
;----------------------------------------------------------------------------
; Control Transfer Data Size
;----------------------------------------------------------------------------
EXPORT USB_1_TransferSize, _USB_1_TransferSize
 USB_1_TransferSize:
 _USB_1_TransferSize:                  BLK   2
;----------------------------------------------------------------------------
; Control Transfer Data Pointer
;   Source for Control Read
;   Destination for Control Write
;----------------------------------------------------------------------------
EXPORT USB_1_DataPtr, _USB_1_DataPtr
 USB_1_DataPtr:
 _USB_1_DataPtr:                       BLK   2
;----------------------------------------------------------------------------
; Transfer Completion Notification
;----------------------------------------------------------------------------
EXPORT USB_1_StatusBlockPtr, _USB_1_StatusBlockPtr
 USB_1_StatusBlockPtr:
 _USB_1_StatusBlockPtr:                BLK   2
;----------------------------------------------------------------------------
; Control Transfer _TransferByteCount (Actually transfered)
;----------------------------------------------------------------------------
 USB_1_TransferByteCount:               BLK   2
;----------------------------------------------------------------------------
; Control Endpoint Data toggle
EXPORT USB_1_EPDataToggle
 USB_1_EPDataToggle:
 USB_1_EP0DataToggle:                   BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
EXPORT USB_1_fDataPending
 USB_1_fDataPending:                    BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
;EXPORT USB_1_PendingData
; USB_1_PendingData:                    BLK   1
;----------------------------------------------------------------------------
; Temporary Data registers
EXPORT USB_1_t2, USB_1_t1, USB_1_t0
 USB_1_t2:                              BLK   1    ; Temporary shared by the UM
 USB_1_t1:                              BLK   1    ; Temporary shared by the UM
 USB_1_t0:                              BLK   1    ; Temporary shared by the UM
;----------------------------------------------------------------------------
; Endpoint Transfer--API Status
;----------------------------------------------------------------------------
EXPORT USB_1_EndpointAPIStatus, _USB_1_EndpointAPIStatus
 USB_1_EndpointAPIStatus:
_USB_1_EndpointAPIStatus:               BLK   USB_NUM_ENDPOINTS    ; Endpoint Status

AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_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:
;
;-----------------------------------------------------------------------------
 USB_1_EP0_ISR:
_USB_1_EP0_ISR:
    PUSH    A                          ; Save the context
    PUSH    X                          ;
    ; Dispatch to setup/in/out handlers
EXPORT  USB_1_mode_read
USB_1_mode_read:
   MOV    A, REG[USB_1_EP0MODE]         ; Get the mode reg

; MSB is the SETUP bit, followed by IN, then OUT
    asl    a                           ; Shift to the carry and jump if SETUP bit set
    jc      USB_1_EP0_Setup

    asl    a                           ; Shift to the carry and jump if IN bit set
    jc      USB_1_EP0_IN

    asl    a                           ; Shift to the carry and jump if OUT bit set
    jc     USB_1_EP0_OUT
    JMP    USB_1_Not_Supported_Local_Drv
; ISR Exit Point to update the mode register
;   mode and count have been pushed onto the stack
EXPORT USB_1_EP0_UPD_MODE_EXIT
USB_1_EP0_UPD_MODE_EXIT:

    MOV    REG[USB_1_EP0CNT], A        ; Update the count
    MOV    A, X                        ; Get the new mode
    MOV    REG[USB_1_EP0MODE], A       ; Update the node

USB_1_EP0_ISR_EXIT:

    POP X                              ;
    POP A                              ; Restore Context
    RETI
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_EP0_Setup
;
;  DESCRIPTION:   Dispatch a USB SETUP
;
;-----------------------------------------------------------------------------
 USB_1_EP0_Setup:
_USB_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    USB_1_UpdateStatusBlock
    POP     A                          ; Restore the mode register
    MOV    A, REG[USB_1_EP0CNT]              ; Get the count reg
    CMP    A, (USB_CNT_VALID | 0x0A)
    JZ      .dispatch

    JMP    USB_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[USB_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     [USB_1_t2], A                    ; store shifted value
    POP     A                                ; get original value
    OR      A, [USB_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 USB_1_bmRequestType_Dispatch
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_EP0_IN
;
;  DESCRIPTION:   Dispatch a USB IN
;
;-----------------------------------------------------------------------------
 USB_1_EP0_IN:
_USB_1_EP0_IN:

    MOV     A, [USB_1_TransferType]
USB_1_ControlInDispatch:
    JACC    USB_1_ControlInDispatchTable
USB_1_ControlInDispatchTable:
    JMP     USB_1_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
    JMP     USB_1_ControlReadDataStage     ; USB_TRANS_STATE_CONTROL_READ
    JMP     USB_1_ControlWriteStatusStage  ; USB_TRANS_STATE_CONTROL_WRITE
    JMP     USB_1_NoDataControlStatusStage ; USB_TRANS_STATE_NO_DATA_CONTROL
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_EP0_OUT
;
;  DESCRIPTION:   Dispatch a USB OUT
;
;-----------------------------------------------------------------------------
 USB_1_EP0_OUT:
_USB_1_EP0_OUT:
    MOV     A, [USB_1_TransferType]
    JACC    USB_1_ControlOutDispatchTable
USB_1_ControlOutDispatchTable:
    JMP     USB_1_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
    JMP     USB_1_ControlReadStatusStage   ; USB_TRANS_STATE_CONTROL_READ
    JMP     USB_1_ControlWriteDataStage    ; USB_TRANS_STATE_CONTROL_WRITE
    JMP     USB_1_NoDataControlError       ; USB_TRANS_STATE_NO_DATA_CONTROL
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_InitControlRead
;
;  DESCRIPTION:   This routine initializes a control read.  It must be JUMPed to,
;                 not called.  It assumes a tranfer descriptor has been loaded
;                 into the driver USB_1_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
 USB_1_InitControlRead:
    MOV     [USB_1_LastSize], A        ; Save the packet size?
    CALL    USB_1_InitializeStatusBlock
    MOV     [USB_1_TransferType], USB_TRANS_STATE_CONTROL_READ

    ; Check the transfer size against the request size
    MOV    A, REG[USB_1_EP0DATA+wLengthHi] ; MSB of wLength
    CMP    A, [USB_1_TransferSize]
    JNZ    .L1

    MOV    A, REG[USB_1_EP0DATA+wLengthLo] ; LSB of wLength
    CMP    A, [USB_1_TransferSize+1]
    JZ     .L9
.L1:
    JNC    .L9
;
    MOV    [USB_1_TransferSize+1], A   ;
    MOV    A, REG[USB_1_EP0DATA+wLengthHi] ;
    MOV    [USB_1_TransferSize], A     ;
.L9:
    MOV    [USB_1_TransferByteCount], 0;
    MOV    [USB_1_TransferByteCount+1], 0 ;

⌨️ 快捷键说明

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