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

📄 ps2d.asm

📁 Cypress cy7c63318 鼠标开发板的源代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: PS2D.asm
;;   Version: 1.2, Updated on 2005/07/06 at 13:49:25
;;  Generated by PSoC Designer ver 4.2  b1013 : 02 September, 2004
;;
;;  DESCRIPTION: PS2D 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 "PS2D.inc"
include "globalparams.inc"

;-----------------------------------------------
;  Global Symbols
;-----------------------------------------------
export  PS2D_Start
export _PS2D_Start
export  PS2D_Stop
export _PS2D_Stop

export  PS2D_IsEnabled
export _PS2D_IsEnabled
export  PS2D_SendNextByte
export _PS2D_SendNextByte
export  PS2D_GetHostByte
export _PS2D_GetHostByte
export  PS2D_SendResponseResend
export _PS2D_SendResponseResend
export  PS2D_SendResponseError
export _PS2D_SendResponseError
export  PS2D_SendResponseACK
export _PS2D_SendResponseACK
export  PS2D_SendResponseByte
export _PS2D_SendResponseByte
export  PS2D_AbortTransfer
export _PS2D_AbortTransfer
export  PS2D_TransferInProgress
export _PS2D_TransferInProgress
export PS2D_BAT
export _PS2D_BAT
;-----------------------------------------------
;  Persistent RAM Allocation
;-----------------------------------------------
AREA bss (RAM,REL)

export  PS2D_bIsEnabled
export _PS2D_bIsEnabled
 PS2D_bIsEnabled:
_PS2D_bIsEnabled:                       BLK  1

export  PS2D_bMode
export _PS2D_bMode
 PS2D_bMode:
_PS2D_bMode:                            BLK  1

export  PS2D_bLastMode
export _PS2D_bLastMode
 PS2D_bLastMode:
_PS2D_bLastMode:                        BLK  1

export  PS2D_bTxPktIndex
export _PS2D_bTxPktIndex
 PS2D_bTxPktIndex:
_PS2D_bTxPktIndex:                      BLK  1

export  PS2D_bTxPktSize
export _PS2D_bTxPktSize
 PS2D_bTxPktSize:
_PS2D_bTxPktSize:                       BLK  1

export  PS2D_aTxBuffer
export _PS2D_aTxBuffer
 PS2D_aTxBuffer:
_PS2D_aTxBuffer:                        BLK PS2D_TX_BUFFER_SIZE 

export  PS2D_ErrorCnt
PS2D_ErrorCnt:                          BLK 1

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

IF   PS2D_IO_CONFIG_TYPE
PS2D_DR:                               EQU    P1DATA
PS2D_SCLK:                             EQU    0x01 ; PS2 Clock Line
PS2D_SDATA:                            EQU    0x02 ; PS2 Data Line
PS2D_MASK:                             EQU    0x03
PS2D_CLKH_DATAH:                       EQU    0x03
PS2D_CLKH_DATAL:                       EQU    0x01
PS2D_CLKL_DATAH:                       EQU    0x02
PS2D_CLKL_DATAL:                       EQU    0x00

OUTPUT_ENABLE:                         EQU    0x01
PS2_PULLUP_ENABLE:                     EQU    0x02
OPEN_DRAIN:                            EQU    0x04

ELSE
PS2D_SCLK:       equ 0x@_SCLK_MASK                ; PS2 Clock Line
PS2D_SDATA:      equ 0x@_SDATA_MASK               ; PS2 Data Line
PS2D_MASK:       equ ((0x@_SCLK_MASK) | (0x@_SDATA_MASK))
PS2D_CLKH_DATAH: equ ((0x@_SCLK_MASK) | (0x@_SDATA_MASK))    
PS2D_CLKH_DATAL: equ ((0x@_SCLK_MASK))    
PS2D_CLKL_DATAH: equ ((0x@_SDATA_MASK))    
PS2D_CLKL_DATAL: equ 0    
PS2D_DR:         equ    PRT1DR
PS2D_DM0:        equ    PRT1DM0
PS2D_DM1:        equ    PRT1DM1
PS2D_DM2:        equ    PRT1DM2
ENDIF
;-----------------------------------------------
; Macro definitions
;-----------------------------------------------
;-----------------------------------------------
; Precise Delay
;-----------------------------------------------
    MACRO DELAY
    push    A

IF (@0)
ELSE
PSOC_ERROR  PS2D User Module - Delay value must be greater than zero
ENDIF

IF CPU_CLOCK_SPEED - OSC_CR0_CPU_24MHz
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_12MHz
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_6MHz
PSOC_ERROR  PS2D User Module - Only supports 6, 12, or 24 Mhz
ELSE

; 6 Mhz
    MOV     A, ((@0*2)/3) ; convert uSec to number of delay loops required
    SUB     A, ((((((@1+21)*167)/1000)+1)*2)/3) ; subtract cpu cycles plus current overhead
    
ENDIF
ELSE

; 12 Mhz
    MOV     A, ((@0*4)/7) ; convert uSec to number of delay loops required
    SUB     A, (((((@1+21)*83)/1000)*4)/7) ; subtract cpu cycles plus current overhead

ENDIF
ELSE

; 24 Mhz
    MOV     A, ((@0*8)/11) ; convert uSec to number of delay loops required
    SUB     A, (((((@1+21)*42)/1000)*8)/11) ; subtract cpu cycles plus current overhead

ENDIF

    JC      .mdelay_exit ; exit if carry set, time has already expired

    call	PS2D_Delay

.mdelay_exit:

    pop    A
    ENDM
;-----------------------------------------------
; Clear Carry
;-----------------------------------------------
    MACRO CLEARC
    and    f,~(FLAG_CARRY)
    ENDM
;-----------------------------------------------
; Set Carry
;-----------------------------------------------
    MACRO SETC
    or    f,FLAG_CARRY
    ENDM

AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PS2D_Start
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
.SECTION
 PS2D_Start:
_PS2D_Start:

    ; Set PS2_SCLK and PS2_SDATA to Resistive Pull Up
    CALL PS2D_Release

IF   PS2D_IO_CONFIG_TYPE
    MOV  REG[P10CR], (PS2_PULLUP_ENABLE | OUTPUT_ENABLE)   ; Enable the pullups
    MOV  REG[P11CR], (OPEN_DRAIN | OUTPUT_ENABLE)          ; Enable the pullups

ELSE
    M8C_SetBank1
    OR   REG[PS2D_DM1],(PS2D_SCLK | PS2D_SDATA)   ; Set the clock and data 
    OR   REG[PS2D_DM0],(PS2D_SCLK | PS2D_SDATA)   ; Set the clock and data 

    M8C_SetBank0
    AND  REG[PS2D_DM2],~(PS2D_SCLK | PS2D_SDATA)  ; clear the clock and data 
ENDIF

    CALL PS2D_BAT

    RET
.ENDSECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PS2D_Stop
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
.SECTION
 PS2D_Stop:
_PS2D_Stop:
   ret
.ENDSECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PS2D_BAT
;
;  DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
.SECTION
 PS2D_BAT:
_PS2D_BAT:

    CALL PS2D_StartDevice              ; Device specific start

; Delay for ~500 mSec 
    MOV	  X, 250                       ; 250 * 20 * 100 uSec = 500 mSec
.wait_loop_o:
    MOV   A, 20                        ; Inner loop
.wait_loop_i:

    DELAY 100, 0                       ; Delay 100 uSec each loop
    M8C_ClearWDT                       ; Feed the watchdog

    DEC   A                            ; Are we done with inner loop?
    JNZ   .wait_loop_i

    DEC  X                             ; Are we done with outer loop??
    JNZ   .wait_loop_o

    mov    a, PS2_CMD_PASS_BAT              ; Completion
    call   PS2D_SendResponseByte            ; Send it

; Mouse only
IF (PS2D_DEVICE_TYPE & PS2D_DEVICE_TYPE_MOUSE)
    cmp    a, PS2D_CLKH_DATAL               ; Was the host in RTS
    jz     .exit                            ; Exit if RTS
    mov    a, [PS2D_bDeviceID]              ; Device ID
    call   PS2D_SendResponseByte            ; Send it
ENDIF

.exit:
    ret
.ENDSECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: PS2D_IsEnabled
;
;  DESCRIPTION:    API Function returns the current enable status of the UM
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:	   None
;
;  RETURNS:		   A: 0 Disabled
;                             1 Enabled
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
 PS2D_IsEnabled:
_PS2D_IsEnabled:
   mov    a, [PS2D_bIsEnabled]         ; Simply return the enabled status
   ret
.ENDSECTION

⌨️ 快捷键说明

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