📄 myusb.asm
字号:
;;*****************************************************************************
;;*****************************************************************************
;; FILENAME: myUSB.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 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 "myUSB_macros.inc"
include "myUSB.inc"
IF 0x2 & 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 myUSB_Start
EXPORT _myUSB_Start
EXPORT myUSB_Stop
EXPORT _myUSB_Stop
EXPORT myUSB_bCheckActivity
EXPORT _myUSB_bCheckActivity
EXPORT myUSB_bGetConfiguration
EXPORT _myUSB_bGetConfiguration
EXPORT myUSB_bGetEPState
EXPORT _myUSB_bGetEPState
EXPORT myUSB_bGetEPCount
EXPORT _myUSB_bGetEPCount
EXPORT myUSB_XLoadEP
EXPORT _myUSB_XLoadEP
EXPORT myUSB_EnableOutEP
EXPORT _myUSB_EnableOutEP
EXPORT myUSB_DisableOutEP
EXPORT _myUSB_DisableOutEP
EXPORT myUSB_EnableEP
EXPORT _myUSB_EnableEP
EXPORT myUSB_DisableEP
EXPORT _myUSB_DisableEP
EXPORT myUSB_Force
EXPORT _myUSB_Force
EXPORT myUSB_Suspend
EXPORT _myUSB_Suspend
EXPORT myUSB_Resume
EXPORT _myUSB_Resume
EXPORT myUSB_bRWUEnabled
EXPORT _myUSB_bRWUEnabled
AREA bss (RAM,REL)
;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
;----------------------------------------------------------------------------
EXPORT myUSB_APITemp
myUSB_APITemp: BLK 2 ; Two bytes of temporary
; storage shared by the API
; functions
EXPORT myUSB_APIEPNumber, _myUSB_APIEPNumber
_myUSB_APIEPNumber:
myUSB_APIEPNumber: BLK 1 ; API storage for speed
EXPORT myUSB_APICount, _myUSB_APICount
_myUSB_APICount:
myUSB_APICount: BLK 1 ; API storage for speed
EXPORT myUSB_bActivity
myUSB_bActivity: BLK 1 ; Activity flag (Shared between the ISR and API)
;-----------------------------------------------
; Constant Data Allocation
;-----------------------------------------------
AREA UserModules (ROM, REL)
EXPORT myUSB_USB_EP_BIT_LOOKUP
.LITERAL
myUSB_USB_EP_BIT_LOOKUP: ;
DB 01H ; EP0
DB 02H ; EP1
DB 04H ; EP2
.ENDLITERAL
AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
; FUNCTION NAME: myUSB_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
myUSB_Start:
_myUSB_Start:
MOV REG[P10CR], 0x00 ; Disable the states
MOV REG[P11CR], 0x00 ;
MOV [myUSB_bCurrentDevice], A ; The app selects the desired device
MOV [myUSB_TransferType], USB_TRANS_STATE_IDLE ; Transaction Idle State
MOV [myUSB_Configuration], 0 ; Unconfigured
MOV [myUSB_DeviceStatus], 0 ; Clears device status
MOV [myUSB_EPDataToggle], 0 ; Clear all EP data toggles
; Flow here to enable the SIE
MOV REG[myUSB_ADDR], USB_ADDR_ENABLE ; Enable Address 0
OR REG[myUSB_USBXCR], USB_PULLUP_ENABLE ; Pullup D-
MOV REG[myUSB_EP0MODE], USB_MODE_STALL_IN_OUT ; ACK Setup/Stall IN/OUT
NOP
MOV A, REG[myUSB_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: myUSB_Stop
;
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
myUSB_Stop:
_myUSB_Stop:
MOV [myUSB_bCurrentDevice], 0 ; The app selects the desired device
MOV [myUSB_TransferType], USB_TRANS_STATE_IDLE ; Transaction Idle State
MOV [myUSB_Configuration], 0 ; Unconfigured
MOV [myUSB_DeviceStatus], 0 ; Clear the device status
MOV [myUSB_bActivity], 0 ; Clear the activity flag
MOV REG[myUSB_ADDR], 0 ; Clear the addfress and Address 0
AND REG[myUSB_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: myUSB_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
myUSB_bCheckActivity:
_myUSB_bCheckActivity:
MOV A, [myUSB_bActivity] ; Activity?
CMP A, 1 ;
JZ .active ; Jump on Activity
; Flow here on no activity
RET
; Jump here if activity was detected
.active:
MOV [myUSB_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: myUSB_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
myUSB_bGetConfiguration:
_myUSB_bGetConfiguration:
MOV A,[myUSB_Configuration]
RET
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: myUSB_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
myUSB_bGetEPState:
_myUSB_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+myUSB_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: myUSB_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
myUSB_bRWUEnabled:
_myUSB_bRWUEnabled:
TST [myUSB_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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -