📄 usb.asm
字号:
;;*****************************************************************************
;;*****************************************************************************
;; FILENAME: USB.asm
;; @Version@
;; Generated by PSoC Designer ver 4.2 b1013 : 02 September, 2004
;;
;; DESCRIPTION: USB Device User Module software implementation file
;; 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_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_EnableOutEP
EXPORT _USB_EnableOutEP
EXPORT USB_DisableOutEP
EXPORT _USB_DisableOutEP
EXPORT USB_bReadOutEP
EXPORT _USB_bReadOutEP
EXPORT USB_Force
EXPORT _USB_Force
EXPORT USB_bGetEPAckState
EXPORT _USB_bGetEPAckState
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
;-----------------------------------------------
; Constant Data Allocation
;-----------------------------------------------
AREA UserModules (ROM, REL)
.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 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
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
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
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
.invalid_ep:
mov A, 0 ; Return 0 for an invalid ep
; Jump or flow here for a common exit
.exit:
RAM_EPILOGUE RAM_USE_CLASS_3
ret ; All done
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_bGetEPCount
;
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: A contains the Endpiont Number
;
; RETURNS: A and X contain a WORD that indicate the values stored in the
; Count registers of the Endpoint
;
; 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_wGetEPCount:
_USB_wGetEPCount:
RAM_PROLOGUE RAM_USE_CLASS_1
cmp A, (USB_MAX_EP_NUMBER + 1) ; Range check
jnc .invalid_ep ; Bail out
; Flow here to get the endpoint count
asl A ; Multiply the index by two to get to the value
mov X, A ; Endpoint number is the index
mov A, reg[X+USB_EP1CNT1 - 1] ; Here is the count
sub A, 2
push A
dec X
mov A, reg[X+USB_EP1CNT1 - 1] ; Here is the count
and A, 0x01
mov X, A
pop A
jmp .exit ; Go to the common exit
; Jump here for an invalid endpoint
.invalid_ep:
mov A, 0 ; Return 0 for an invalid ep
; Jump or flow here for a common exit
.exit:
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_LoadInEP
;
; DESCRIPTION: This function loads the specified endpoint buffer
; with the number of bytes previously set in the count
; register.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; [SP-7] MSB of Count to send
; [SP-6] LSB of Count to send
; [SP-5] MSB of data array address
; [SP-4] LSB of data array address
; [SP-3] Endpoint Number
;
; RETURNS:
; none
;
; 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.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
; IDX_PP
;
EP_NUM: equ -3 ; Endpoint Number
DATA_LSB: equ -4 ; LSB pointer of data
DATA_MSB: equ -5 ; MSB pointer of data
CNTLEN_LSB: equ -6
CNTLEN_MSB: equ -7 ; Length of data to send
TOGGLE: equ -8
USB_LoadInEP:
_USB_LoadInEP:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -