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

📄 usb.asm

📁 Cypress 的VOIP DEMO 研究VOIP终端的朋友可以研究研究
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: USB.asm
;;   Version: 1.1, Updated on 2006/06/19 at 11:41:37
;;  Generated by PSoC Designer ver 4.3  b1884 : 23 June, 2006
;;
;;  DESCRIPTION: USB Device User Module software implementation file
;;               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 "USB_macros.inc"
include "USB.inc"
IF 0x0 & 0x10000000
PSOC_ERROR Please run the USB Setup Wizard.  Device Editor, Right Click the USB User Module
; This message will only appear if the USB Setup Wizard has not be run and the descriptors
; and associated data structures have been created.
; After running the USB Setup Wizard, you must also select the Config/Generate Application
; menu item from PSoC Designer in order to generate USB User Module data structures and
; descriptors.
ENDIF
;-----------------------------------------------
;  Global Symbols
;-----------------------------------------------
EXPORT USB_Start
EXPORT _USB_Start
EXPORT USB_Stop
EXPORT _USB_Stop
EXPORT USB_bCheckActivity
EXPORT _USB_bCheckActivity
EXPORT USB_bGetConfiguration
EXPORT _USB_bGetConfiguration
EXPORT USB_bGetEPState
EXPORT _USB_bGetEPState
EXPORT USB_wGetEPCount
EXPORT _USB_wGetEPCount
EXPORT USB_LoadInEP
EXPORT _USB_LoadInEP
EXPORT USB_LoadInISOCEP
EXPORT _USB_LoadInISOCEP
EXPORT USB_EnableOutEP
EXPORT _USB_EnableOutEP
EXPORT USB_EnableOutISOCEP
EXPORT _USB_EnableOutISOCEP
EXPORT USB_DisableOutEP
EXPORT _USB_DisableOutEP
EXPORT USB_bReadOutEP
EXPORT _USB_bReadOutEP
EXPORT USB_Force
EXPORT _USB_Force
EXPORT USB_bGetEPAckState
EXPORT _USB_bGetEPAckState
;EXPORT USB_Suspend
;EXPORT _USB_Suspend
;EXPORT USB_Resume
;EXPORT _USB_Resume
EXPORT USB_bRWUEnabled
EXPORT _USB_bRWUEnabled

AREA InterruptRAM (RAM,REL,CON)
;-----------------------------------------------
;  Constant Definitions
;-----------------------------------------------

;-----------------------------------------------
;  Variable Allocation
;-----------------------------------------------
EXPORT USB_APITemp
 USB_APITemp:                           BLK   2 ; Two bytes of temporary
                                                ; storage shared by the API
                                                ; functions
EXPORT USB_APIEPNumber, _USB_APIEPNumber
_USB_APIEPNumber:
 USB_APIEPNumber:                      BLK   1 ; API storage for speed
EXPORT USB_APICount, _USB_APICount
_USB_APICount:
 USB_APICount:                         BLK   1 ; API storage for speed

EXPORT USB_bActivity
 USB_bActivity:                        BLK   1 ; Activity flag (Shared between the ISR and API)

NDX_WORKAROUND:	EQU	1
 IF NDX_WORKAROUND
ndxUsbTmp:	BLK	1	; NDX WORKAROUND
 ENDIF
                                                
;-----------------------------------------------
;  Constant Data Allocation
;-----------------------------------------------
AREA UserModules (ROM, REL)
EXPORT USB_USB_EP_BIT_LOOKUP
.LITERAL
USB_USB_EP_BIT_LOOKUP:  ;
    DB     01H                       ; EP0
    DB     02H                       ; EP1
    DB     04H                       ; EP2
    DB     08H                       ; EP3
    DB     010H                      ; EP4
.ENDLITERAL

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_Start
;
;  DESCRIPTION:    Starts the USB User Module
;                    Sets the device selection
;                    Set the configuration to unconfigured
;                    Enables the SIE for Address 0
;                    Enables the USB pullup (D- for low speed, D+ for full speed)
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A is the desired device
;                X is the operation voltage
;
;  RETURNS:              Nothing
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
 USB_Start:
_USB_Start:
    RAM_PROLOGUE RAM_USE_CLASS_4
    RAM_PROLOGUE RAM_USE_CLASS_3
        RAM_SETPAGE_CUR >USB_bCurrentDevice ; Set the CUR_PP to the right page
    RAM_SETPAGE_IDX >USB_bCurrentDevice; Set the IDX_PP to the right page
    push    X
    mov     [USB_bCurrentDevice], A    ; The app selects the desired device

    mov     [USB_TransferType], USB_TRANS_STATE_IDLE ; Transaction Idle State
    mov     [USB_Configuration], 0     ; Unconfigured
    mov     [USB_DeviceStatus], 0      ; Clears device status

    MOV     [USB_EPDataToggle], 0      ; Clear all EP data toggles

    mov     reg[TMP_DR0], 0            ; EP1 start address in PMA space
        mov     reg[TMP_DR1], 64       ; EP2 start address in PMA space
        mov     reg[TMP_DR2], 128      ; EP3 start address in PMA space
        mov     reg[TMP_DR3], 192      ; EP4 start address in PMA space

;    mov     X, USB_MAX_EP_NUMBER      ; Set up loop to clear all of the endpoint data items
; Flow or jump here to clear the data for the next endpoint
;.loop:
;    mov     [X + USB_EPDataToggle], 0 ; Or in the toggle
;    dec     X                         ; Are we done?
;    jnz     .loop                     ; Jump to do another endpoint
; Flow here to enable the SIE

    mov     reg[USB_ADDR], USB_ADDR_ENABLE ; Enable Address 0
        mov     reg[USB_USBIO_CR0], USB_AUTO_DPDM

; Set the Operating Voltage at which the chip will run
    pop     A
    M8C_SetBank1
        mov     reg[USB_USB_CR1], A
        M8C_SetBank0
;   TODO
    mov     reg[USB_EP0MODE], USB_MODE_STALL_IN_OUT ; ACK Setup/Stall IN/OUT
    M8C_EnableIntMask USB_INT_REG, (USB_INT_RESET_MASK | USB_INT_EP0_MASK)

;   Enable the pullup so we can start to rock and roll
    mov     reg[USB_USBIO_CR1], USB_PULLUP_ENABLE ; Pullup D+

    RAM_EPILOGUE RAM_USE_CLASS_3
        RAM_EPILOGUE RAM_USE_CLASS_4
    RET
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_Stop
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: None
;
;  RETURNS:   Nothing
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
 USB_Stop:
_USB_Stop:
    RAM_PROLOGUE RAM_USE_CLASS_4
        RAM_SETPAGE_CUR >USB_bCurrentDevice ; Set the CUR_PP to the right page

    mov     [USB_bCurrentDevice], 0    ; The app selects the desired device

    mov     [USB_TransferType], USB_TRANS_STATE_IDLE ; Transaction Idle State
    mov     [USB_Configuration], 0     ; Unconfigured
    mov     [USB_DeviceStatus], 0      ; Clears device status
    mov     reg[USB_ADDR], 0           ; Clear the addfress and Address 0

    and     reg[USB_USBIO_CR1], ~USB_PULLUP_ENABLE ; Release D-
    mov     reg[USB_INT_REG], 0x00 ; Enable the interrupt

        RAM_EPILOGUE RAM_USE_CLASS_4
    RET
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_bCheckActivity
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: Nothing
;
;  RETURNS:   A is a flag that indicates bus activity
;
;  SIDE EFFECTS: ;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
 USB_bCheckActivity:
_USB_bCheckActivity:
    RAM_PROLOGUE RAM_USE_CLASS_1
    M8C_SetBank1
    mov    A, reg[USB_USB_CR1]         ; USB Activity bit indicates activity
    and    A, USB_BUS_ACTIVITY         ; Activity?
    jz     .no_activity                ; Jump on no activity?
; Flow here on bus activity
    mov    A, 1                        ; Return true
    jmp    .done
; Jump here on no activity
.no_activity:
    mov    A, 0                        ; Return false
; Jump or flow here to clear the activity bit, then return
.done:
    and    reg[USB_USB_CR1], ~USB_BUS_ACTIVITY  ; Clear the activity flag
    M8C_SetBank0
        RAM_EPILOGUE RAM_USE_CLASS_1
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_bGetConfiguration
;
;  DESCRIPTION:   Returns the current configuration number
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    None
;
;  RETURNS:      A contains the current configuration number
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
 USB_bGetConfiguration:
_USB_bGetConfiguration:
        RAM_PROLOGUE RAM_USE_CLASS_4
        RAM_SETPAGE_CUR >USB_Configuration
    mov     A,[USB_Configuration]
        RAM_EPILOGUE RAM_USE_CLASS_4
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_bGetEPState
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A contains the endpoint number
;
;  RETURNS:      A contains the endpoint state
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16
;    functions.
;
 USB_bGetEPState:
_USB_bGetEPState:
    RAM_PROLOGUE RAM_USE_CLASS_3
        RAM_SETPAGE_IDX >USB_EndpointAPIStatus
    cmp     A, (USB_MAX_EP_NUMBER + 1) ; Range check
    jnc     .invalid_ep                ; Bail out
; Flow here to enable an endpoint
    mov     X, A                       ; Endpoint number is the index
    mov     A, [X+USB_EndpointAPIStatus]; Get the state
    jmp     .exit                      ; Go to the common exit
; Jump here for an invalid endpoint

⌨️ 快捷键说明

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