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

📄 myusb_drv.asm

📁 实现2个ps/2接口转到1个USB接口功能
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: myUSB_drv.asm
;;   Version: 1.5, Updated on 2005/08/17 at 15:01:28
;;  Generated by PSoC Designer ver 4.2  b1013 : 02 September, 2004
;;
;;  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 "myUSB_macros.inc"
include "myUSB.inc"

;-----------------------------------------------
;  Global Symbols
;-----------------------------------------------
export  _myUSB_EP0_ISR
export  myUSB_InitControlRead
export  myUSB_InitControlWrite
export  myUSB_InitNoDataStageControlTransfer
export  myUSB_NoDataStageControlTransfer

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

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

;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
AREA bss (RAM,REL)
;----------------------------------------------------------------------------
; Current Device
;----------------------------------------------------------------------------
EXPORT myUSB_bCurrentDevice
myUSB_bCurrentDevice:                   BLK   1    ;  Current Device
;----------------------------------------------------------------------------
; Current Configuration
;----------------------------------------------------------------------------
EXPORT myUSB_Configuration, _myUSB_Configuration
_myUSB_Configuration:
 myUSB_Configuration:                   BLK   1    ;  Current Configuration
;----------------------------------------------------------------------------
; Current Device Status
;----------------------------------------------------------------------------
EXPORT myUSB_DeviceStatus
 myUSB_DeviceStatus:                    BLK   1    ;  Current Device Status
;----------------------------------------------------------------------------
; Interface Setting
;----------------------------------------------------------------------------
EXPORT myUSB_InterfaceSetting
 myUSB_InterfaceSetting:                BLK   2    ; Interface Setting
;----------------------------------------------------------------------------
; Endpoint Status--USB Status
;----------------------------------------------------------------------------
EXPORT myUSB_EndpointStatus
 myUSB_EndpointStatus:                  BLK   USB_NUM_ENDPOINTS    ; Endpoint Status
;----------------------------------------------------------------------------
; Last Packet Size
;----------------------------------------------------------------------------
EXPORT myUSB_LastSize
 myUSB_LastSize:                        BLK   1    ;  Last Packet Size
;----------------------------------------------------------------------------
; Control Transfer State Machine
; State values for Control Write
; State values for Control Read
;----------------------------------------------------------------------------
EXPORT myUSB_TransferType
 myUSB_TransferType:                    BLK   1    ; Control Transfer State Machine
;----------------------------------------------------------------------------
; Control Transfer Intermediate Buffer--Shared among the requests
;----------------------------------------------------------------------------
EXPORT myUSB_TransferBuffer
 myUSB_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 myUSB_CurrentTD, _myUSB_CurrentTD
 myUSB_CurrentTD:
_myUSB_CurrentTD:
EXPORT myUSB_DataSource, _myUSB_DataSource
 myUSB_DataSource:
_myUSB_DataSource:                     BLK   1
;----------------------------------------------------------------------------
; Control Transfer Data Size
;----------------------------------------------------------------------------
EXPORT myUSB_TransferSize, _myUSB_TransferSize
 myUSB_TransferSize:
 _myUSB_TransferSize:                  BLK   2
;----------------------------------------------------------------------------
; Control Transfer Data Pointer
;   Source for Control Read
;   Destination for Control Write
;----------------------------------------------------------------------------
EXPORT myUSB_DataPtr, _myUSB_DataPtr
 myUSB_DataPtr:
 _myUSB_DataPtr:                       BLK   2
;----------------------------------------------------------------------------
; Transfer Completion Notification
;----------------------------------------------------------------------------
EXPORT myUSB_StatusBlockPtr, _myUSB_StatusBlockPtr
 myUSB_StatusBlockPtr:
 _myUSB_StatusBlockPtr:                BLK   2
;----------------------------------------------------------------------------
; Control Transfer _TransferByteCount (Actually transfered)
;----------------------------------------------------------------------------
 myUSB_TransferByteCount:               BLK   2
;----------------------------------------------------------------------------
; Control Endpoint Data toggle
EXPORT myUSB_EPDataToggle
 myUSB_EPDataToggle:
 myUSB_EP0DataToggle:                   BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
EXPORT myUSB_fDataPending
 myUSB_fDataPending:                    BLK   1
;----------------------------------------------------------------------------
; Control Endpoint Data Pending Flag
;EXPORT myUSB_PendingData
; myUSB_PendingData:                    BLK   1
;----------------------------------------------------------------------------
; Temporary Data registers
EXPORT myUSB_t2, myUSB_t1, myUSB_t0
 myUSB_t2:                              BLK   1    ; Temporary shared by the UM
 myUSB_t1:                              BLK   1    ; Temporary shared by the UM
 myUSB_t0:                              BLK   1    ; Temporary shared by the UM
;----------------------------------------------------------------------------
; Endpoint Transfer--API Status
;----------------------------------------------------------------------------
EXPORT myUSB_EndpointAPIStatus, _myUSB_EndpointAPIStatus
 myUSB_EndpointAPIStatus:
_myUSB_EndpointAPIStatus:               BLK   USB_NUM_ENDPOINTS    ; Endpoint Status

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:
;
;-----------------------------------------------------------------------------
 myUSB_EP0_ISR:
_myUSB_EP0_ISR:
    PUSH    A                          ; Save the context
    PUSH    X                          ; 
    ; Dispatch to setup/in/out handlers
EXPORT  myUSB_mode_read
myUSB_mode_read:
   MOV    A, REG[myUSB_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      myUSB_EP0_Setup

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

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

    MOV    REG[myUSB_EP0CNT], A        ; Update the count   
    MOV    A, X                        ; Get the new mode
    MOV    REG[myUSB_EP0MODE], A       ; Update the node   

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

    JMP    myUSB_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[myUSB_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     [myUSB_t2], A                    ; store shifted value
    POP     A                                ; get original value
    OR      A, [myUSB_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 myUSB_bmRequestType_Dispatch
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_EP0_IN
;
;  DESCRIPTION:   Dispatch a USB IN
;
;-----------------------------------------------------------------------------
 myUSB_EP0_IN:
_myUSB_EP0_IN:
   
    MOV     A, [myUSB_TransferType]
myUSB_ControlInDispatch:               
    JACC    myUSB_ControlInDispatchTable
myUSB_ControlInDispatchTable:
    JMP     myUSB_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
    JMP     myUSB_ControlReadDataStage     ; USB_TRANS_STATE_CONTROL_READ
    JMP     myUSB_ControlWriteStatusStage  ; USB_TRANS_STATE_CONTROL_WRITE
    JMP     myUSB_NoDataControlStatusStage ; USB_TRANS_STATE_NO_DATA_CONTROL
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_EP0_OUT
;
;  DESCRIPTION:   Dispatch a USB OUT
;
;-----------------------------------------------------------------------------
 myUSB_EP0_OUT:
_myUSB_EP0_OUT:
    MOV     A, [myUSB_TransferType]
    JACC    myUSB_ControlOutDispatchTable
myUSB_ControlOutDispatchTable:
    JMP     myUSB_Not_Supported_Local_Drv  ; USB_TRANS_STATE_IDLE
    JMP     myUSB_ControlReadStatusStage   ; USB_TRANS_STATE_CONTROL_READ
    JMP     myUSB_ControlWriteDataStage    ; USB_TRANS_STATE_CONTROL_WRITE
    JMP     myUSB_NoDataControlError       ; USB_TRANS_STATE_NO_DATA_CONTROL
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_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 myUSB_CurrentTD data structure.
;
;-----------------------------------------------------------------------------
 myUSB_InitControlRead:
    MOV     [myUSB_LastSize], A        ; Save the packet size?
    CALL    myUSB_InitializeStatusBlock
    MOV     [myUSB_TransferType], USB_TRANS_STATE_CONTROL_READ
    
    ; Check the transfer size against the request size
    MOV    A, REG[myUSB_EP0DATA+wLengthHi] ; MSB of wLength
    CMP    A, [myUSB_TransferSize]
    JNZ    .L1

    MOV    A, REG[myUSB_EP0DATA+wLengthLo] ; LSB of wLength
    CMP    A, [myUSB_TransferSize+1]
    JZ     .L9
.L1:
    JNC    .L9
;    
    MOV    [myUSB_TransferSize+1], A   ; 

⌨️ 快捷键说明

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