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

📄 usbps2.lst

📁 Cypress 的(鼠标+键盘)复合设备汇编源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
0049            ;------------------------------------------------------------------------
0049            ; To support the USB specification.
0049            remote_wakeup_status:   equ  usbmain_ram_base 
0049                                                                                                                                    ; remote wakeup request
0049                                                                                                                                    ; zero is disabled
0049                                                                                                                                    ; two is enabled
0049            configuration_status:   equ  (usbmain_ram_base+1)
0049                                                                                                                                    ; configuration status
0049                                                                                                                                    ; zero is unconfigured
0049                                                                                                                                    ; one is configured
0049            ep1_stall_status:               equ  (usbmain_ram_base+2)                           ; zero is not stalled
0049            ep2_stall_status:               equ  (usbmain_ram_base+3)                                                                                                                       ; one is stalled
0049            
0049            protocol_status:                equ  (usbmain_ram_base+4)                       ; zero is boot protocol
0049                                                                    ; one is report protocol
0049            ; support SetIdle and GetIdle
0049            kbd_idle_period:                equ  (usbmain_ram_base+5)                       ; keyboard idle period
0049            kbd_idle_period_ctr:    equ  (usbmain_ram_base+6)                       ; keyboard idle period
0049            mouse_idle_period:      equ  (usbmain_ram_base+7)                ; mouse idle period
0049            mouse_idle_period_ctr:  equ  (usbmain_ram_base+8)                ; mouse idle period
0049            consumer_idle_period:   equ  (usbmain_ram_base+9)                       ; consumer keys idle period
0049            consumer_idle_period_ctr:equ  (usbmain_ram_base+10)                     ; consumer keys idle period
0049            power_idle_period:              equ  (usbmain_ram_base+11)                      ; power idle period
0049            power_idle_period_ctr:  equ  (usbmain_ram_base+12)                      ; power idle period
0049            
0049            1ms_counter:            equ  (usbmain_ram_base+13)                      ; 4ms counter
0049            data_start:             equ  (usbmain_ram_base+14)                      ; points to start of descriptor
0049            data_count:             equ  (usbmain_ram_base+15)                      ; current length of descriptor
0049            byte_count:             equ  (usbmain_ram_base+16)                      ; current size of transmission
0049            temp:                   equ  (usbmain_ram_base+17)
0049            
0049            ;--------------------------------------------------------------------------
0049            suspend_counter:        equ  (usbmain_ram_base+18)                      ; contains number of idle bus msecs
0049            
0049            
0049            ;------------------------------------------------------------------------
0049            ; application support
0049            ;------------------------------------------------------------------------
0049            
0049            
0049            page:                                   equ  (usbmain_ram_base+19)                      ; page location of descriptor(RAM,
0049                                                                                                                                    ; ROM page 1, ROM page 2
0049            EP0_mode_shadow:        equ  (usbmain_ram_base+20)                      ; variable to store ep0 mode
0049                                                                                                                                    ; used by set_ep0_mode
0049            
0049            ps2_tmp:                                equ  (usbmain_ram_base+21)                      ; temporary variable for port 3 write by PS/2
0049            background_flags:               equ  (usbmain_ram_base+22)                      ; signal flags for background 
0049            usb_leds:                   equ  (usbmain_ram_base+23)                  ; overcurrent debounce counter
0049            last_key_report:        equ  (usbmain_ram_base+24)
0049            EP0_fifo_shadow:        equ  (usbmain_ram_base+25)
0049            EP_A0_counter_shadow:   equ  (usbmain_ram_base+26)
0049            EP0_Next_Mode:          equ  (usbmain_ram_base+27)
0049            EP0_FLAG:               equ  (usbmain_ram_base+28)
0049            USBMAIN_RAM_SIZE:               equ  29
0049             
0049            SUSPEND_FLAG:                           equ 1
0049            SCAN_FLAG:                                      equ 2
0049            ;========================================================================
0049            ;                       program listing
0049            ;======================================================================== 
0049            
0049            
0049            ;========================================================================
0049            ; The 128 uSec interrupt is not used by the keyboard code.  The keyboard
0049            ; only does not require the DAC or GPIO port in this version of
0049            ; firmware.  It may be necessary to enable GPIO interrupts when the
0049            ; keyboard enters a power down suspend mode.
0049            DoNothing_ISR:
0049 73    [08]         reti                    ; return from interrupt
004A            
004A            ;========================================================================
004A            ; Suspend
004A            ;
004A            ; This routine is invoked from the main loop when bus activity has ceased for
004A            ; 3 msec or more. This routine prepares the keyboard for suspension, suspends
004A            ; the part, and restores the keyboard upon a subsequent resume.
004A            ;========================================================================
004A            ; Suspend
004A            ;
004A            ; This routine is invoked from the main loop when bus activity has ceased for
004A            ; 3 msec or more. This routine prepares the keyboard for suspension, suspends
004A            ; the part, and restores the keyboard upon a subsequent resume.
004A            
004A            Suspend:
004A            
004A 2D    [05]         push A
004B                                                            ; (since all pins are guaranteed to not float)
004B            
004B 5B 84 [10]         call mouse_suspend              ; put PS/2 mouse in stream mode
004D 70    [08]         di                                      ; disable interrupts
004E 19 FF [04]         mov A, RESISTIVE_NEG          ; all ports resistive neg so that
0050 2A 08 [05]         iowr GPIO_Config              ; we stay within suspend current budget (500uA)
0052 19 00 [04]         mov A, 0                      ; pull down the column lines
0054 2A 00 [05]         iowr Port0_Data
0056 2A 01 [05]         iowr Port1_Data
0058 1A 88 [06]         mov A, [ksc_p3out]
005A 0D 07 [04]         or A, P3_LED_MASK             ; turn LEDs off
005C 10 3F [04]         and A, ~P3_KEY_MASK             ; don't touch bit 6 & 7 (PS/2 mouse interface)
005E 2A 03 [05]         iowr Port3_Data                 
0060 19 FF [04]         mov A, FFh
0062 2A 06 [05]         iowr Port2_Interrupt            ; enable port 2 GPIO interrupt for keyboard
0064 19 20 [04]         mov A, GPIO_ONLY_MASK         ; enable GPIO interrupt only
0066 2A 20 [05]         iowr Global_Interrupt
0068 1A 22 [06]         mov A, [remote_wakeup_status] ; is remote wakeup feature enabled?
006A 16 02 [04]         cmp A, ENABLE_REMOTE_WAKEUP
006C B0 6F [05]         jnz  Suspend_controller
006E 72    [08]         ei
006F            Suspend_controller:
006F            
006F 29 FF [05]         iord Status_Control           ; set the suspend bit causing suspend
0071 0D 08 [04]         or A, 08h
0073 2A FF [05]         iowr Status_Control           ; we are suspended here
0075            
0075            ; resume !!!!!!                                 
0075 20    [04]         nop                           ; execute a nop after resuming
0076                
0076 70    [08]         di
0077 2A 26 [05]     iowr Watchdog
0079 29 1F [05]         iord USB_Status_Control         ; check if there is no bus activity
007B 10 08 [04]         and A, 08h
007D 16 00 [04]         cmp A, 00h
007F B0 B1 [05]         jnz GPIO_disable_interrupts   ; if there is bus activity, 
0081                                                            ; disable interrupts and exit
0081            
0081            
0081 19 04 [04]         mov A, TIMER_ONLY_MASK          ; enable 1ms interrupt
0083 2A 20 [05]         iowr Global_Interrupt
0085 72    [08]         ei
0086 1A 2F [06]         mov A, [1ms_counter]            ; clear wakeup counter
0088 01 05 [04]         add A,5
008A            
008A            wakeup_delay:                           ; wait 5ms before we send the wakeup signal
008A 2A 26 [05]     iowr Watchdog
008C 17 2F [06]         cmp A, [1ms_counter]
008E B0 8A [05]         jnz wakeup_delay
0090            
0090 70    [08]         di                                      ; disable interrupts
0091            
0091 29 1F [05]         iord USB_Status_Control         ; check again if there is no bus activity
0093 10 08 [04]         and A, 08h                              ; after 5ms
0095 16 00 [04]         cmp A, 00h
0097 B0 B1 [05]         jnz GPIO_disable_interrupts   ; if there is bus activity, 
0099                                                            ; disable interrupts and exit
0099            
0099            
0099 19 02 [04]         mov A, FORCE_J                ; force J state to correct cross-over voltage
009B 2A 1F [05]         iowr USB_Status_Control       ; problem during resume signalling
009D            
009D 19 01 [04]         mov A, FORCE_K                  ; start sending resume signal
009F 2A 1F [05]         iowr USB_Status_Control
00A1            
00A1 72    [08]         ei                                      ; enable 1ms interrupt again
00A2 1A 2F [06]         mov A, [1ms_counter]            ; clear wakeup counter
00A4 01 0A [04]     add A,0ah
00A6            
00A6            wakeup_duration:                                ; send resume signal for 10ms
00A6 2A 26 [05]     iowr Watchdog
00A8 17 2F [06]         cmp A, [1ms_counter]
00AA B0 A6 [05]         jnz wakeup_duration
00AC            
00AC 70    [08]         di                                      ; disable interrupts
00AD            
00AD 19 00 [04]         mov A, NOT_FORCING              ; let SIE control D+/D-
00AF 2A 1F [05]         iowr USB_Status_Control         
00B1            
00B1            
00B1            GPIO_disable_interrupts:                ;
00B1                                                            ;interrupts are off when we get here
00B1 29 1F [05]         iord USB_Status_Control
00B3 10 F7 [04]         and A, F7h                              ; clear Bus Activity bit
00B5 2A 1F [05]         iowr USB_Status_Control
00B7            
00B7 19 00 [04]         mov A, 0
00B9 2A 06 [05]         iowr Port2_Interrupt            ; disable GPIO interrupt for keyboard
00BB            
00BB 19 25 [04]         mov A, GPIO_TIMER_RESET_MASK  ; enable GPIO and 1ms interrupts
00BD 2A 20 [05]         iowr Global_Interrupt
00BF            
00BF            
00BF 72    [08]         ei
00C0 5B 84 [10]         call mouse_resume                       ; put PS/2 mouse into polling mode
00C2 70    [08]         di  
00C3            Skip_suspend:
00C3 19 F5 [04]         mov A, NORMAL                 ; restore original GPIO configuration
00C5 2A 08 [05]         iowr GPIO_Config                        
00C7 19 00 [04]       mov A,0
00C9 31 34 [05]       mov [suspend_counter],A
00CB 5A 4D [10]         call ksc_restore_ports            ; restore column ports to pre-suspend values
00CD 72    [08]     ei
00CE 2B    [04]     pop A
00CF 3F    [08]     ret
00D0            
00D0            
00D0            
00D0            check_activity:
00D0            
00D0 29 1F [05]         iord    USB_Status_Control                  ; check if there is  bus activity
00D2 10 08 [04]         and     A, 08h
00D4 3F    [08]     ret
00D5            
00D5            ;========================================================================
00D5            ; The 1 msec interrupt is used to clear the watchdog timer, to maintain
00D5            ; all timers with a 1msec granularity
00D5            ;========================================================================
00D5            
00D5            One_mSec_ISR:
00D5 23 2F [07]     inc         [1ms_counter]                               ;increment 1msec timer
00D7 1A 2F [06]     mov         A,[1ms_counter]
00D9 10 03 [04]     and         A,3                         
00DB                
00DB B0 E3 [05]     jnz         check_bus_activity_status           ;every 4 msec, do the following:
00DD            
00DD 1A 38 [06]     mov         A,[background_flags]                ; set the flag to scan the keyboard
00DF 0D 02 [04]     or          A,SCAN_FLAG
00E1 31 38 [05]     mov         [background_flags],A
00E3            
00E3            check_bus_activity_status:
00E3 29 1F [05]         iord    USB_Status_Control                              ; check if there is no bus activity
00E5 10 08 [04]         and             A, 08h
00E7 16 00 [04]         cmp             A,0h
00E9 A0 F7 [05]         jz              Inc_counter                                             ; if there was bus activity
00EB 29 1F [05]         iord    USB_Status_Control                              ;   clear the bus activity bit
00ED 10 F7 [04]         and             A, 0F7h
00EF 2A 1F [05]         iowr    USB_Status_Control
00F1 19 00 [04]         mov             A, 0h                                                   ;   clear the suspend counter
00F3 31 34 [05]         mov             [suspend_counter], A                    ;   
00F5 81 06 [05]         jmp             Exit_1ms
00F7            
00F7            Inc_counter:                                                            ;there was no bus activity,
00F7 23 34 [07]     inc         [suspend_counter]                               ;so increment the bus activity counter
00F9 1A 34 [06]         mov             A,[suspend_counter]
00FB 16 03 [04]         cmp             A, 03h                                                  ;if 3msecs of bus inactivity passed
00FD

⌨️ 快捷键说明

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