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

📄 usbhidio.lst

📁 在Linux中
💻 LST
📖 第 1 页 / 共 5 页
字号:
00F4 20    [04]      nop
00F5 80 F0 [05]      jmp suspendReset
00F7            
00F7            BusReset:
00F7            ;Clear all reset bits.
00F7            ;Set bit 0 (the run bit).
00F7 19 01 [04]      mov A, RunBit
00F9 2A FF [05]      iowr Status_Control
00FB            ;Set up for enumeration (Endpoint 0 and 1-millisecond interrupts enabled)
00FB 19 0C [04]      mov A, ENUMERATE_MASK
00FD 31 20 [05]      mov [interrupt_mask],A
00FF 1F    [04]         XPAGE
0100 2A 20 [05]      iowr Global_Interrupt
0102            
0102            wait:
0102            ;Wait until configured.
0102 29 11 [05]      iord USB_EP1_TX_Config
0104 16 00 [04]      cmp A, 0
0106            ;Clear the watchdog timer
0106 2A 21 [05]      iowr Watchdog
0108            ;If not configured, continue to wait.
0108 A1 02 [05]      jz wait     
010A            ;When configured, initialize loop_temp.
010A            ;Loop_temp adds a delay in the start of transmission of data.
010A            ;The chip will respond to the first IN packet no sooner than 
010A            ;230 milliseconds after enumeration is complete.
010A            ;The delay was included in Cypress' joystick code to prevents problems 
010A            ;that occurred when power cycled off and on or the joystick was plugged
010A            ;in before the host powered up.
010A            ;I've left it in because it does no harm and 
010A            ;other hardware might have similar behavior.
010A            ;During the delay, the chip will send a NAK in response to any IN packet.
010A 19 FF [04]      mov A, 0ffh
010C 31 37 [05]      mov [loop_temp], A
010E            
010E            ;Enable endpoint 1
010E 29 11 [05]      iord USB_EP1_TX_Config
0110 0D 92 [04]      or A, 92h
0112 2A 11 [05]      iowr USB_EP1_TX_Config
0114            
0114            ;======================================================================
0114            ; The main program loop.
0114            ;======================================================================
0114            
0114            main:
0114            ;Find out if the loop_temp delay has timed out.
0114            ;Loop_temp =0 if not timed out, FFh if timed out.
0114 1A 37 [06]      mov A, [loop_temp]
0116 16 0A [04]      cmp A, 0Ah
0118            ;If no, don't enable transmitting.
0118 D1 1E [05]      jnc no_set
011A            ;If yes, enable transmitting.
011A 19 01 [04]      mov A, 01h
011C 31 32 [05]      mov [start_send], A
011E            no_set:
011E            ;Clear the watchdog timer.
011E            ;This has to be done at least once every 8 milliseconds!
011E 2A 21 [05]      iowr Watchdog
0120 29 00 [05]      iord Port0_Data
0122            nochange:
0122 81 14 [05]      jmp main
0124            
0124            ;----------------------------------------------------------------------
0124            ;The endpoint 0 ISR supports the control endpoint.
0124            ;This code enumerates and configures the hardware.
0124            ;It also responds to Set Report requests that receive data from the host.
0124            ;----------------------------------------------------------------------
0124            
0124            USB_EP0_ISR:
0124 2D    [05]      push A
0125 29 14 [05]      iord USB_EP0_RX_Status
0127            ;Has a Setup packet been received?
0127 10 01 [04]      and A, 01h
0129            ;If no, find out if it's an OUT packet.
0129 A1 3D [05]      jz check_for_out_packet
012B            ;If yes, handle it.
012B            ;Disable endpoint 0 interrupts.
012B 1A 20 [06]      mov A,[interrupt_mask]
012D 10 F7 [04]      and A, 0F7h
012F 31 20 [05]      mov [interrupt_mask], A
0131 2A 20 [05]      iowr Global_Interrupt
0133            ;Find out what the Setup packet contains and handle the request.
0133 91 83 [10]       call StageOne
0135            ;Re-enable Endpoint 0 interrupts.
0135 1A 20 [06]      mov A, [interrupt_mask]
0137 0D 08 [04]      or A, 08h
0139 31 20 [05]      mov [interrupt_mask], A
013B 81 7B [05]      jmp done_with_packet
013D            
013D            check_for_out_packet:
013D 29 14 [05]      iord USB_EP0_RX_Status
013F            ;Is it an OUT packet?
013F 10 02 [04]      and A, 02h
0141            ;If no, ignore it.
0141 A1 7B [05]      jz done_with_packet
0143            ;If yes, process the received data.
0143            ;Disable Endpoint 0 interrupts.
0143 1A 20 [06]      mov A,[interrupt_mask]
0145 10 F7 [04]      and A, 0F7h
0147 31 20 [05]      mov [interrupt_mask], A
0149 2A 20 [05]      iowr Global_Interrupt
014B            
014B            ;For debugging: set Port 0, bit 1 to show that we're here.
014B 29 00 [05]     iord Port0_Data
014D 0D 02 [04]     or a, 2
014F 2A 00 [05]     iowr Port0_Data
0151            
0151            ;Read the first byte in the buffer
0151 1A 70 [06]      mov a, [Endpoint_0]
0153            ;For debugging: if the first byte =12h, bring Port 0, bit 0 high
0153 16 12 [04]       cmp a, 12h
0155 B1 5D [05]       jnz not_a_match
0157 29 00 [05]       iord Port0_Data
0159 0D 04 [04]       or a, 4
015B 2A 00 [05]       iowr Port0_Data
015D            
015D            not_a_match:
015D            
015D            ;For debugging, add 1 to each byte read
015D            ;and copy the bytes to RAM.
015D            ;These bytes will be sent back to the host.
015D            
015D 2E    [05]       push X
015E                  ;data_count holds the number of bytes left to read.
015E                  ;X holds the index of the address to read
015E                  ;and the index of the address to store the received data.
015E                  ;Initialize the X register.
015E 1C 00 [04]       mov X, 0
0160                  
0160                  Get_Received_Data:
0160                  ;Find out if there are any bytes to read.
0160 19 00 [04]       mov A, 0
0162 17 28 [06]       cmp A, [data_count]
0164                  ;Jump if nothing to read.
0164 A1 78 [05]       jz DoneWithReceivedData
0166            
0166                  ;Get a byte.
0166 1B 70 [07]       mov A, [X + Endpoint_0]
0168                  ;For debugging, increment the received value.
0168                  ;(Endpoint 1 will send it back to the host.)
0168                  ;If the value is 255, reset to 0.
0168                  ;Otherwise increment it.
0168 16 FF [04]       cmp A, 255
016A A1 6F [05]       jz ResetToZero
016C 21    [04]       inc A
016D 81 71 [05]       jmp NewValueSet
016F                  ResetToZero:
016F 19 00 [04]       mov A, 0
0171                  NewValueSet:
0171                  ;Save the value.
0171 32 38 [06]       mov [X + Data_Byte0], A
0173                  ;Decrement the number of bytes to read.
0173 27 28 [07]       dec [data_count]
0175                  ;Increment the address to read.
0175 22    [04]       inc X
0176                  ;Do another
0176 81 60 [05]       jmp Get_Received_Data
0178            
0178                  DoneWithReceivedData:
0178 2C    [04]       pop X
0179            
0179            ;For debugging, set Port 0 to match the value written
0179            ;IN transfers can read this value back.
0179            ;     iowr Port0_Data
0179            
0179            ;Handshake by sending a 0-byte data packet.
0179 93 79 [10] call Send0ByteDataPacket
017B            
017B            done_with_packet:
017B            ;Re-enable Endpoint 0 interrupts.
017B 1A 20 [06]      mov A,[interrupt_mask]
017D 0D 08 [04]      or A, 08h
017F 31 20 [05]      mov [interrupt_mask], A
0181 1E 20 [13]      ipret Global_Interrupt
0183            
0183            ;========================================================================
0183            ;Control transfers
0183            ;========================================================================
0183            
0183            ;------------------------------------------------------------------------
0183            ;Control transfer, stage one.
0183            ;Find out whether the request is a standard device or HID request,
0183            ;the direction of data transfer, 
0183            ;and whether the request is to a device, interface, or endpoint.
0183            ;(from Table 9.2 in the USB spec)
0183            ;------------------------------------------------------------------------
0183            
0183            StageOne:
0183            ;Clear the setup flag
0183 19 00 [04]      mov A, 00h
0185 2A 14 [05]      iowr USB_EP0_RX_Status
0187            ;Set the StatusOuts bit to cause auto-handshake after receiving a data packet.
0187 19 08 [04]      mov A, 8
0189 2A 13 [05]      iowr USB_Status_Control
018B            ;bmRequestType contains the request.
018B 1A 70 [06]       mov A, [bmRequestType]
018D            
018D            ;Standard device requests. From the USB spec.
018D            ; host to device requests
018D 16 00 [04]         cmp A, 00h
018F A1 B2 [05]         jz RequestType00                 ; bmRequestType = 00000000 device
0191            ;       cmp A, 01h                       *** not required ***  
0191            ;       jz RequestType01                 ; bmRequestType = 00000001 interface
0191 16 02 [04]         cmp A, 02h              
0193 A1 C6 [05]         jz RequestType02                 ; bmRequestType = 00000010 endpoint
0195 16 80 [04]         cmp A, 80h             
0197            ; device to host requests
0197 A1 D2 [05]         jz RequestType80                 ; bmRequestType = 10000000 device
0199 16 81 [04]         cmp A, 81h
019B A1 E2 [05]         jz RequestType81                 ; bmRequestType = 10000001 interface
019D 16 82 [04]         cmp A, 82h
019F A1 EE [05]         jz RequestType82                 ; bmRequestType = 10000010 endpoint
01A1            
01A1            ;HID-class device requests. From the HID spec
01A1            ; host to device requests
01A1 16 21 [04]         cmp A, 21h
01A3 A1 FA [05]         jz RequestType21                 ; bmRequestType = 00100001 interface
01A5 16 22 [04]         cmp A, 22h                       ; *** not in HID spec ***
01A7 A2 0C [05]         jz RequestType22                 ; bmRequestType = 00100010 endpoint
01A9            ; device to host requests
01A9 16 A1 [04]         cmp A, A1h
01AB A2 14 [05]         jz RequestTypeA1                 ; bmRequestType = 10100001 interface
01AD            
01AD            ; Stall unsupported requests
01AD            SendStall:
01AD 19 A0 [04]       mov A, A0h
01AF 2A 10 [05]      iowr USB_EP0_TX_Config
01B1 3F    [08]       ret
01B2            
01B2            ;----------------------------------------------------------------------
01B2            ;Control transfer, stage two
01B2            ;Find out which request it is.
01B2            ;----------------------------------------------------------------------
01B2            
01B2            ;Host to device with device as recipient
01B2            RequestType00:
01B2            
01B2            ;The Remote Wakeup feature is disabled on reset.
01B2 1A 71 [06]      mov A, [bRequest]     ; load bRequest
01B4            ; Clear Feature                      bRequest = 1
01B4 16 01 [04]      cmp A, clear_feature
01B6 A2 24 [05]      jz ClearRemoteWakeup 
01B8            ; Set Feature                     bRequest = 3
01B8 16 03 [04]      cmp A, set_feature
01BA A2 31 [05]      jz SetRemoteWakeup
01BC            
01BC            ; Set the device address to a non-zero value.
01BC            ; Set Address                     bRequest = 5
01BC 16 05 [04]      cmp A, set_address
01BE A2 3E [05]      jz SetAddress
01C0            
01C0            ; Set Descriptor is optional.
01C0            ; Set Descriptor                bRequest = 7    *** not supported ***
01C0            
01C0            ;If wValue is zero, the device is not configured.
01C0            ;The only other legal value for this firmware is 1.
01C0            ;Set Configuration           bRequest = 9
01C0 16 09 [04]     cmp A, set_configuration
01C2 A2 45 [05]     jz SetConfiguration
01C4            
01C4            ;Stall unsupported requests.
01C4 81 AD [05]     jmp SendStall
01C6            
01C6            
01C6            ;Host to device with interface as recipient    *** not required ***
01C6            ; RequestType01:
01C6            ;        mov A, [bRequest]       ; load bRequest
01C6            
01C6            ; There are no interface features defined in the spec.
01C6            ; Clear Feature                 bRequest = 1    *** not supported ***
01C6            ; Set Feature                   bRequest = 3    *** not supported ***
01C6            
01C6            ; Set Interface is optional.
01C6            ; Set Interface                 bRequest = 11   *** not supported ***
01C6            

⌨️ 快捷键说明

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