CY7C63813做的PS2鼠标键盘通信过程丢失数据

[复制链接]
2821|5
 楼主| bsaver 发表于 2012-7-9 09:57 | 显示全部楼层 |阅读模式
用 CY7C63813 做的自动识别 USB,PS2 鼠标键盘的程序,PS2 通信是在PS2M模块程序的基础上修改的,现在发现PS2通信过程有丢失数据的现象,比如滚动鼠标的滚轮正常的数据是:0x08,0x00,0x00,0x01;发送丢失数据时会有:0x08,0x00,0x01 或者 0x08,0x00,0x00 现象。一直没有找到原因,大家帮忙看一下。
 楼主| bsaver 发表于 2012-7-9 10:16 | 显示全部楼层

RE: CY7C63813做的PS2鼠标键盘通信过程丢失数据

  1. PS2M_Send:
  2. _PS2M_Send:
  3. .data:    equ -1                             ; Local stack variables
  4. .cnt:     equ -2
  5. .parity:  equ -3
  6. ;        M8C_DisableGInt
  7.     PUSH    X                               ; Build the local variable
  8.     ADD     SP, 3                           ;
  9.     MOV     X, SP                           ;
  10.     MOV     [X + .data], A                  ; Save off the data byte
  11.     MOV     [X + .parity], 1                ; Start the parity at 1
  12.     MOV     [X + .cnt], 8                   ; Send 8 data bits
  13.         MOV                [_fHostRqs], 0
  14. ; Test for inhibit   
  15.     TST    REG[PS2M_DR], PS2M_SCLK          ; Inhibit?
  16.     JZ     .rts                    ; Continue to wait if we are inhibited

  17.     DELAY    20, 60                           ; Min delay between check for inhibit

  18.     TST    REG[PS2M_DR], PS2M_SCLK          ; Inhibit?
  19.     JZ     .rts                    ; Continue to wait if we are inhibited

  20. ; Test for RTS
  21.     TST    REG[PS2M_DR], PS2M_SDATA         ; RTS?
  22.     JZ     .rts                             ; Jump if RTS
  23. ; change data pin to output mode
  24.         OR           REG[P01CR], 0x01
  25.         OR           REG[P02CR], 0x01                                        ;test debug
  26. ; Flow here to send start bit
  27.     CALL   PS2M_Send_0                      ; Start bits are zero
  28.     JC     .inhib                           ; Host has inhibited

  29.     DELAY  2, 12                            ; Wait 2 uSec

  30. ; Flow or jump here to sent the data bits
  31. .snb:
  32.     ASR    [X + .data]                       ; rotate the next bit to the carry
  33.     JC     .s1                               ; and send a 1 or 0 based
  34. .s0:
  35.     CALL   PS2M_Send_0                       ; Send 0
  36.     JMP    .cont
  37. .s1:
  38.     INC    [X + .parity]                     ; Count the number of 1 bits for the parity
  39.     CALL   PS2M_Send_1                       ; Send 1
  40. .cont:
  41.     JC     .inhib                            ; Did the host inhibit us during the last bit?     
  42.     DEC    [X + .cnt]                        ; If not, send the next bit
  43.     JZ     .s_parity                         ; When it hits zero, do the parity
  44.     JNC    .snb                              ; It will carry after the parity bit is sent

  45. ; Flow here to send the stop bit
  46.     CALL   PS2M_Send_1                       ; Stop bits are 1
  47.     JMP    .success
  48.    
  49. ; Flow here after all 8 data bits have been clocked out
  50. .s_parity:
  51.     MOV    A, [X + .parity]                  ; clock out the lsb of the parity
  52.     MOV    [X + .data],a                     ; Save the data
  53.     JMP    .snb

  54. ; Jump here on a successful stop bit
  55. .success:
  56.     MOV    A, 0                              ; Flow here after a successful stop bit
  57. ;    CMP                [PS2M_bCmdCnt], 0x00
  58. ;        JZ                .exit
  59. ;        CALL   PS2M_ReadSendBuffer
  60.         JMP    .exit
  61. ; Jump here if we failed because we were inhibited
  62. .inhib:                                     ; Jump here for any failed bit
  63.         OR     reg[PS2M_DR], PS2M_CLKH_DATAH
  64.         MOV                [_fHostRqs], 1
  65.         MOV    A, 0x88         
  66.     JMP    .exit
  67. ; Jump here if we found a RTS
  68. .rts:                                        ; Jump here for a RTS
  69.     MOV    A, 0x90                           ;
  70. ; Jump or flow here to exit   
  71. .exit:
  72.         ;change data pin to input mode
  73.         AND           REG[P01CR], 0xfe
  74.         AND           REG[P02CR], 0xfe                                        ;test debug
  75.     ADD    SP, -3                            ; Clean up the stack
  76.     POP    X   
  77. ;        M8C_EnableGInt
  78.         PUSH   A
  79.         DELAY    38, 12                         ; Wait 38 uSec
  80.         POP           A
  81.     RET   
  82. ;-----------------------------------------------------------------------------
  83. ;  FUNCTION NAME: PS2M_Send_1, PS2M_Send_0
  84. ;  DESCRIPTION:   Local function.  Assembly interface only.
  85. ;
  86. ;-----------------------------------------------------------------------------
  87. ;
  88. ;  ARGUMENTS:
  89. ;
  90. ;  RETURNS:
  91. ;
  92. ;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
  93. ;
  94. ;  THEORY of OPERATION or PROCEDURE:
  95. ;
  96. ;-----------------------------------------------------------------------------
  97. PS2M_Send_1:
  98.     OR     REG[PS2M_DR], PS2M_SDATA  ; Set the data bit high
  99.         DELAY    10, 12                         ; Wait 10 uSec
  100.     ; Clock Low                             ; Clock Low and the data
  101.     AND    REG[PS2M_DR], ~PS2M_SCLK          ; Clock Low
  102.     DELAY    38, 12                         ; Wait 38 uSec
  103.     ; Clock High                            ; Finally Clock High and the data
  104.     OR     REG[PS2M_DR], PS2M_SCLK          ; Clock High
  105.     DELAY    22, 60                         ; Wait 22 uSec
  106.     ; Check for inhibit
  107.     CLEARC                                  ; Carry clear indicates success
  108.         AND           REG[P02CR], 0xfe                                        ;test debug
  109.         TST    REG[PS2M_DR], PS2M_SCLK          ; Inhibit?
  110.     JNZ    .clock_done                      ; Jump if not
  111.     SETC                                    ; Carry set indicates fail/Inhibit
  112. .clock_done:
  113.     ; Done
  114.         OR           REG[P02CR], 0x01                                        ;test debug
  115.     RET



  116. PS2M_Send_0:
  117.         AND     REG[PS2M_DR], ~PS2M_SDATA                  ; clear the data bit high
  118.         DELAY    10, 12                         ; Wait 10 uSec
  119.     ; Clock Low                             ; Clock Low and the data
  120.     AND    REG[PS2M_DR], ~PS2M_SCLK          ; Clock Low
  121.     DELAY    38, 12                         ; Wait 38 uSec
  122.     ; Clock High                            ; Finally Clock High and the data
  123.     OR     REG[PS2M_DR], PS2M_SCLK          ; Clock High
  124.     DELAY    22, 60                         ; Wait 22 uSec
  125.     ; Check for inhibit
  126.     CLEARC                                  ; Carry clear indicates success
  127.     AND           REG[P02CR], 0xfe                                        ;test debug
  128.         TST    REG[PS2M_DR], PS2M_SCLK          ; Inhibit?
  129.     JNZ    .clock_done                      ; Jump if not
  130.     SETC                                    ; Carry set indicates fail/Inhibit
  131. .clock_done:
  132.     ; Done
  133.         OR           REG[P02CR], 0x01                                        ;test debug
  134.     RET
 楼主| bsaver 发表于 2012-7-9 10:16 | 显示全部楼层
源码,怎么会这样....
 楼主| bsaver 发表于 2012-7-9 10:18 | 显示全部楼层

RE: CY7C63813做的PS2鼠标键盘通信过程丢失数据

  1. .SECTION
  2. PS2M_SendNextByte:
  3. _PS2M_SendNextByte:
  4. ; Anything to send?
  5. mov a, [PS2M_bTxPktIndex] ; Get the index
  6. cmp a, [PS2M_bTxPktSize] ; Compared to the packet length
  7. jz .exit ; Anything left to send?
  8. M8C_DisableGInt ; Disable interrupts
  9. mov x, [PS2M_bTxPktIndex] ; Get the index
  10. mov a, [x+PS2M_aTxBuffer] ; Get the next byte
  11. call PS2M_Send ; Send it
  12. cmp a,0x00 ; Successful?
  13. jnz .exit ; Jump if not
  14. inc [PS2M_bTxPktIndex] ; Bump the index
  15. .exit:
  16. M8C_EnableGInt ; Enable interrupts
  17. ret
  18. .ENDSECTION
 楼主| bsaver 发表于 2012-7-9 10:19 | 显示全部楼层

RE: CY7C63813做的PS2鼠标键盘通信过程丢失数据

  1. while(PS2K_TransferInProgress())
  2. {
  3.                 PS2K_SendNextByte();
  4.         if(fHostRqs) return;
  5. }
 楼主| bsaver 发表于 2012-7-9 10:21 | 显示全部楼层
贴的代码真丑,还不如抓图呢...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

51

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部