📄 usb.asm
字号:
;;*****************************************************************************
;;*****************************************************************************
;; FILENAME: USB.asm
;; Version: 1.5, Updated on 2006/06/19 at 11:43:56
;; Generated by PSoC Designer ver 4.4 b1884 : 14 Jan, 2007
;;
;; DESCRIPTION: USB Device User Module software implementation file
;; 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, 2005. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************
include "m8c.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_bGetEPCount
EXPORT _USB_bGetEPCount
EXPORT USB_XLoadEP
EXPORT _USB_XLoadEP
EXPORT USB_EnableOutEP
EXPORT _USB_EnableOutEP
EXPORT USB_DisableOutEP
EXPORT _USB_DisableOutEP
EXPORT USB_EnableEP
EXPORT _USB_EnableEP
EXPORT USB_DisableEP
EXPORT _USB_DisableEP
EXPORT USB_Force
EXPORT _USB_Force
EXPORT USB_Suspend
EXPORT _USB_Suspend
EXPORT USB_Resume
EXPORT _USB_Resume
EXPORT USB_bRWUEnabled
EXPORT _USB_bRWUEnabled
AREA bss (RAM,REL)
;-----------------------------------------------
; 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)
;-----------------------------------------------
; 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
.ENDLITERAL
AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
; 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 setting
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
USB_Start:
_USB_Start:
MOV REG[P10CR], 0x00 ; Disable the states
MOV REG[P11CR], 0x00 ;
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
; Flow here to enable the SIE
MOV REG[USB_ADDR], USB_ADDR_ENABLE ; Enable Address 0
OR REG[USB_USBXCR], USB_PULLUP_ENABLE ; Pullup D-
MOV REG[USB_EP0MODE], USB_MODE_STALL_IN_OUT ; ACK Setup/Stall IN/OUT
NOP
MOV A, REG[USB_EP0MODE] ; Read the mode register as a debug marker
M8C_EnableIntMask INT_MSK1, (INT_MSK1_USB_ACTIVITY | INT_MSK1_USB_BUS_RESET | INT_MSK1_USB_EP0)
RET
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_Stop
;
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
USB_Stop:
_USB_Stop:
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 ; Clear the device status
MOV [USB_bActivity], 0 ; Clear the activity flag
MOV REG[USB_ADDR], 0 ; Clear the addfress and Address 0
AND REG[USB_USBXCR], ~USB_PULLUP_ENABLE ; Release D-
M8C_DisableIntMask INT_MSK1, (INT_MSK1_USB_ACTIVITY | INT_MSK1_USB_BUS_RESET | INT_MSK1_USB_EP0 | INT_MSK1_USB_EP1 | INT_MSK1_USB_EP2) ; Enable the interrupt
RET
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_bCheckActivity
;
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
; The activity interrupt sets a RAM flag indicating activity and disables the
; interrupt. Disabling the interrupt keeps the bus activity from creating too
; many interrupts. bCheckActivity checks and clears the flag, the enables
; interrupts for the next interval.
;
;-----------------------------------------------------------------------------
.SECTION
USB_bCheckActivity:
_USB_bCheckActivity:
MOV A, [USB_bActivity] ; Activity?
CMP A, 1 ;
JZ .active ; Jump on Activity
; Flow here on no activity
RET
; Jump here if activity was detected
.active:
MOV [USB_bActivity], 0 ; Clear the activity flag for next time
M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_ACTIVITY ; Enable the activity interupt
RET
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_bGetConfiguration
;
; DESCRIPTION: Returns the current configuration number
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: A contains the current configuration number
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
USB_bGetConfiguration:
_USB_bGetConfiguration:
MOV A,[USB_Configuration]
RET
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_bGetEPState
;
; DESCRIPTION: Returns the current endpoint state
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: A: Endpoint Number
;
; RETURNS: A: NO_EVENT_ALLOWED
; EVENT_PENDING
; NO_EVENT_PENDING
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
USB_bGetEPState:
_USB_bGetEPState:
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:
RET ; All done
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_bRWUEnabled
;
; DESCRIPTION: Returns 1 if Remote Wake Up is enabled, otherwise 0
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: A: 1--Remote Wake Up Enabled
; 0--Remote Wake Up Disabled
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
USB_bRWUEnabled:
_USB_bRWUEnabled:
TST [USB_DeviceStatus], USB_DEVICE_STATUS_REMOTE_WAKEUP
JNZ .enabled ; Jump if enabled
; Flow here if RWU is disabled
MOV A, 0 ; Return disabled
JMP .exit ; Go to the common exit
; Jump when RWU is enabled
.enabled:
MOV A, 1 ; Return enabled
; Jump or flow here for a common exit
.exit:
RET ; All done
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_bGetEPCount
;
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -