Subversion Repositories Kolibri OS

Rev

Rev 5042 | Rev 5363 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5042 Rev 5087
Line 10... Line 10...
10
;;         GNU GENERAL PUBLIC LICENSE                           ;;
10
;;         GNU GENERAL PUBLIC LICENSE                           ;;
11
;;          Version 2, June 1991                                ;;
11
;;          Version 2, June 1991                                ;;
12
;;                                                              ;;
12
;;                                                              ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 14... Line 14...
14
 
14
 
Line 15... Line 15...
15
format MS COFF
15
format PE DLL native 0.05
Line 16... Line 16...
16
 
16
 
17
DEBUG = 1
17
DEBUG = 1
Line 18... Line 18...
18
 
18
 
19
__DEBUG__ = 1
19
__DEBUG__ = 1
Line 20... Line 20...
20
__DEBUG_LEVEL__ = 1
20
__DEBUG_LEVEL__ = 1
21
 
21
 
22
node equ ftdi_context
22
node equ ftdi_context
23
node.next equ ftdi_context.next_context
23
node.next equ ftdi_context.next_context
Line 24... Line -...
24
 
-
 
25
include '../../proc32.inc'
-
 
26
include '../../imports.inc'
-
 
27
include '../../fdo.inc'
24
 
28
include '../../struct.inc'
25
include '../../proc32.inc'
29
 
26
include '../../peimport.inc'
30
public START
27
include '../../fdo.inc'
31
public version
28
include '../../struct.inc'
Line 176... Line 173...
176
wValue                  dw      ?
173
wValue                  dw      ?
177
wIndex                  dw      ?
174
wIndex                  dw      ?
178
wLength                 dw      ?
175
wLength                 dw      ?
179
ends
176
ends
Line 180... Line 177...
180
 
177
 
181
section '.flat' code readable align 16
178
section '.flat' code readable executable
182
; The start procedure.
179
; The start procedure.
Line 183... Line 180...
183
proc START stdcall, .reason:DWORD
180
proc START c, .reason:DWORD, .cmdline:DWORD
184
 
181
 
185
        xor     eax, eax        ; initialize return value
182
        xor     eax, eax        ; initialize return value
186
        cmp     [.reason], 1    ; compare the argument
183
        cmp     [.reason], 1    ; compare the argument
Line 187... Line 184...
187
        jnz     .nothing                
184
        jnz     .nothing                
188
        stdcall RegUSBDriver, my_driver, service_proc, usb_functions
185
        invoke  RegUSBDriver, my_driver, service_proc, usb_functions
189
 
186
 
Line 190... Line 187...
190
.nothing:
187
.nothing:
Line 191... Line 188...
191
        ret
188
        ret
192
endp
189
endp
193
 
190
 
194
 
191
 
195
proc AddDevice stdcall uses ebx esi edi, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD
192
proc AddDevice stdcall uses ebx esi edi, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD
196
        
193
        
197
        stdcall USBGetParam, [.config_pipe], 0
194
        invoke  USBGetParam, [.config_pipe], 0
198
        mov     edx, eax
195
        mov     edx, eax
199
        DEBUGF 1,'K : Detected device vendor: %x\n', [eax+usb_descr.idVendor]
196
        DEBUGF 2,'K : Detected device vendor: 0x%x\n', [eax+usb_descr.idVendor]
200
        cmp     word[eax+usb_descr.idVendor], 0x0403
197
        cmp     word[eax+usb_descr.idVendor], 0x0403
201
        jnz     .notftdi
198
        jnz     .notftdi
202
        mov     eax, sizeof.ftdi_context
199
        mov     eax, sizeof.ftdi_context
203
        call    Kmalloc
200
        invoke  Kmalloc
204
        test    eax, eax
201
        test    eax, eax
205
        jnz     @f
202
        jnz     @f
Line 206... Line 203...
206
        mov     esi, nomemory_msg
203
        mov     esi, nomemory_msg
207
        call    SysMsgBoardStr
204
        invoke  SysMsgBoardStr
208
        jmp     .nothing
205
        jmp     .nothing
Line 220... Line 217...
220
 
217
 
221
        mov     [eax + ftdi_context.chipType], TYPE_R
218
        mov     [eax + ftdi_context.chipType], TYPE_R
Line 222... Line 219...
222
        jmp     .slow
219
        jmp     .slow
223
        
220
        
224
        mov     cx, [edx+usb_descr.bcdDevice]
221
        mov     cx, [edx+usb_descr.bcdDevice]
225
        DEBUGF 1, 'K : Chip type %x\n', ecx
222
        DEBUGF 2, 'K : Chip type 0x%x\n', ecx
226
        cmp     cx, 0x400
223
        cmp     cx, 0x400
227
        jnz     @f
224
        jnz     @f
228
        mov     [eax + ftdi_context.chipType], TYPE_BM
225
        mov     [eax + ftdi_context.chipType], TYPE_BM
Line 260... Line 257...
260
        
257
        
261
  .fast:
258
  .fast:
262
        add     [eax + ftdi_context.maxPacketSize], 512-64
259
        add     [eax + ftdi_context.maxPacketSize], 512-64
263
  .slow:    
260
  .slow:    
-
 
261
        mov     ebx, eax
264
        mov     ebx, eax
262
        invoke  USBOpenPipe, [.config_pipe], 0x81, \
265
        stdcall USBOpenPipe, [.config_pipe],  0x81,  [ebx + ftdi_context.maxPacketSize],  BULK_PIPE, 0
263
                            [ebx + ftdi_context.maxPacketSize],  BULK_PIPE, 0
266
        test    eax, eax
264
        test    eax, eax
267
        jz      .nothing
265
        jz      .nothing
-
 
266
        mov     [ebx + ftdi_context.outEP], eax
268
        mov     [ebx + ftdi_context.outEP], eax
267
        invoke  USBOpenPipe, [.config_pipe], 0x02, \
269
        stdcall USBOpenPipe, [.config_pipe],  0x02,  [ebx + ftdi_context.maxPacketSize],  BULK_PIPE, 0
268
                            [ebx + ftdi_context.maxPacketSize],  BULK_PIPE, 0
270
        test    eax, eax
269
        test    eax, eax
271
        jz      .nothing
270
        jz      .nothing
272
        mov     [ebx + ftdi_context.inEP], eax
271
        mov     [ebx + ftdi_context.inEP], eax
273
        mov     eax, ebx
272
        mov     eax, ebx
Line 286... Line 285...
286
input      equ  IOCTL.input
285
input      equ  IOCTL.input
287
inp_size   equ  IOCTL.inp_size
286
inp_size   equ  IOCTL.inp_size
288
output     equ  IOCTL.output
287
output     equ  IOCTL.output
289
out_size   equ  IOCTL.out_size
288
out_size   equ  IOCTL.out_size
Line 290... Line -...
290
 
-
 
291
align 4
289
 
292
proc service_proc stdcall uses ebx esi edi, ioctl:DWORD
290
proc service_proc stdcall uses ebx esi edi, ioctl:DWORD
293
locals
291
locals
294
ConfPacket  rb  10
292
ConfPacket  rb  10
295
EventData   rd  3
293
EventData   rd  3
Line 345... Line 343...
345
        cmp     eax, 9-7
343
        cmp     eax, 9-7
346
        je      .bulkevent
344
        je      .bulkevent
347
        xor     ecx, ecx
345
        xor     ecx, ecx
348
  .bulkevent:                
346
  .bulkevent:                
349
        xor     esi, esi
347
        xor     esi, esi
350
        call    CreateEvent        
348
        invoke  CreateEvent        
351
        mov     [EventData], eax
349
        mov     [EventData], eax
352
        mov     [EventData+4], edx
350
        mov     [EventData+4], edx
353
        pop     edi eax
351
        pop     edi eax
Line 354... Line 352...
354
        
352
        
Line 407... Line 405...
407
  .eventdestroy:
405
  .eventdestroy:
408
        ;---Dirty hack begin
406
        ;---Dirty hack begin
409
        test    eax, eax
407
        test    eax, eax
410
        jz      @f
408
        jz      @f
411
        mov     eax, dword[ConfPacket]
409
        mov     eax, dword[ConfPacket]
412
        call    Kfree
410
        invoke  Kfree
413
  @@:
411
  @@:
414
        ;---Dirty hack end
412
        ;---Dirty hack end
415
        mov     eax, [EventData]
413
        mov     eax, [EventData]
416
        mov     ebx, [EventData+4]
414
        mov     ebx, [EventData+4]
417
        call    DestroyEvent
415
        invoke  DestroyEvent
418
        jmp     .endswitch
416
        jmp     .endswitch
Line 419... Line 417...
419
        
417
        
420
  .ftdi_out_control_transfer_withinp:               
418
  .ftdi_out_control_transfer_withinp:               
421
        mov     dx, word[edi+8]
419
        mov     dx, word[edi+8]
Line 426... Line 424...
426
        mov     word[ConfPacket+4], cx
424
        mov     word[ConfPacket+4], cx
427
        xor     cx, cx
425
        xor     cx, cx
428
        mov     word[ConfPacket+6], cx
426
        mov     word[ConfPacket+6], cx
429
  .own_index:
427
  .own_index:
430
        mov     ebx, [edi+4]
428
        mov     ebx, [edi+4]
431
        DEBUGF 1,'K : ConfPacket %x %x\n', [ConfPacket], [ConfPacket+4]          
429
        DEBUGF 2,'K : ConfPacket 0x%x 0x%x\n', [ConfPacket], [ConfPacket+4]          
432
        lea     esi, [ConfPacket]
430
        lea     esi, [ConfPacket]
433
        lea     edi, [EventData]        
431
        lea     edi, [EventData]        
434
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, 0, 0, control_callback, edi, 0
432
        invoke  USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, 0,\
-
 
433
                                            0, control_callback, edi, 0
435
        test    eax, eax        
434
        test    eax, eax        
436
        jz      .error
435
        jz      .error
437
        mov     eax, [EventData]
436
        mov     eax, [EventData]
438
        mov     ebx, [EventData+4]
437
        mov     ebx, [EventData+4]
439
        call    WaitEvent
438
        invoke  WaitEvent
440
        mov     eax, [EventData+8]
439
        mov     eax, [EventData+8]
441
        test    eax, eax
440
        test    eax, eax
442
        jz      .endswitch
441
        jz      .endswitch
443
        jmp     .error
442
        jmp     .error
Line 444... Line 443...
444
        
443
        
445
  .ftdi_setrtshigh:
444
  .ftdi_setrtshigh:
-
 
445
        DEBUGF 2,'K : FTDI Setting RTS pin HIGH PID: %d Dev handler 0x0x%x\n', [edi],\
446
        ;DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n'                     
446
                                                                        [edi+4]
-
 
447
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
-
 
448
                                 + (SIO_SET_MODEM_CTRL_REQUEST shl 8) \
447
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16)
449
                                 + (SIO_SET_RTS_HIGH shl 16)
Line 448... Line 450...
448
        jmp     .ftdi_out_control_transfer_noinp         
450
        jmp     .ftdi_out_control_transfer_noinp         
449
 
451
 
-
 
452
  .ftdi_setrtslow:
450
  .ftdi_setrtslow:
453
        DEBUGF 2,'K : FTDI Setting RTS pin LOW PID: %d Dev handler 0x0x%x\n', [edi],\
-
 
454
                                                                        [edi+4]
-
 
455
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
451
        ;DEBUGF 1,'K : FTDI Setting RTS pin LOW\n'             
456
                                 + (SIO_SET_MODEM_CTRL_REQUEST shl 8) \
Line 452... Line 457...
452
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16)
457
                                 + (SIO_SET_RTS_LOW shl 16)
453
        jmp     .ftdi_out_control_transfer_noinp           
458
        jmp     .ftdi_out_control_transfer_noinp           
-
 
459
        
454
        
460
  .ftdi_setdtrhigh:
-
 
461
        DEBUGF 2,'K : FTDI Setting DTR pin HIGH PID: %d Dev handler 0x0x%x\n', [edi],\
-
 
462
                                                                        [edi+4]
455
  .ftdi_setdtrhigh:
463
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
Line 456... Line 464...
456
        ;DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n'                     
464
                                 + (SIO_SET_MODEM_CTRL_REQUEST shl 8) \
457
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16)
465
                                 + (SIO_SET_DTR_HIGH shl 16)
-
 
466
        jmp     .ftdi_out_control_transfer_noinp           
458
        jmp     .ftdi_out_control_transfer_noinp           
467
 
-
 
468
  .ftdi_setdtrlow:
-
 
469
        DEBUGF 2,'K : FTDI Setting DTR pin LOW PID: %d Dev handler 0x0x%x\n', [edi],\
459
 
470
                                                                        [edi+4]
Line 460... Line 471...
460
  .ftdi_setdtrlow:
471
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
461
        ;DEBUGF 1,'K : FTDI Setting DTR pin LOW\n'             
472
                                 + (SIO_SET_MODEM_CTRL_REQUEST shl 8) \
-
 
473
                                 + (SIO_SET_DTR_LOW shl 16)
462
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16)
474
        jmp     .ftdi_out_control_transfer_noinp           
-
 
475
        
-
 
476
  .ftdi_usb_reset:
463
        jmp     .ftdi_out_control_transfer_noinp           
477
        DEBUGF 2,'K : FTDI Reseting PID: %d Dev handler 0x0x%x\n', [edi],\
Line 464... Line 478...
464
        
478
                                                                        [edi+4]
-
 
479
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
-
 
480
                                 + (SIO_RESET_REQUEST shl 8) \+
465
  .ftdi_usb_reset:
481
                                   (SIO_RESET_SIO shl 16)
-
 
482
        jmp     .ftdi_out_control_transfer_noinp  
-
 
483
        
466
        ;DEBUGF 1,'K : FTDI Reseting\n'
484
  .ftdi_purge_rx_buf:
Line 467... Line 485...
467
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16)
485
        DEBUGF 2, 'K : FTDI Purge TX buffer PID: %d Dev handler 0x0x%x\n', [edi],\
-
 
486
                                                                        [edi+4]
-
 
487
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
468
        jmp     .ftdi_out_control_transfer_noinp  
488
                                 + (SIO_RESET_REQUEST shl 8) \
-
 
489
                                 + (SIO_RESET_PURGE_RX shl 16)
-
 
490
        jmp     .ftdi_out_control_transfer_noinp  
469
        
491
        
Line 470... Line 492...
470
  .ftdi_purge_rx_buf:
492
  .ftdi_purge_tx_buf:
-
 
493
        DEBUGF 2, 'K : FTDI Purge RX buffer PID: %d Dev handler 0x0x%x\n', [edi],\
-
 
494
                                                                        [edi+4]
471
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16)
495
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
-
 
496
                                 + (SIO_RESET_REQUEST shl 8) \
472
        jmp     .ftdi_out_control_transfer_noinp  
497
                                 + (SIO_RESET_PURGE_TX shl 16)
Line 473... Line 498...
473
        
498
        jmp     .ftdi_out_control_transfer_noinp  
-
 
499
        
-
 
500
  .ftdi_set_bitmode:
474
  .ftdi_purge_tx_buf:
501
        DEBUGF 2, 'K : FTDI Set bitmode 0x%x, bitmask 0x%x %d PID: %d Dev handler 0x0x%x\n', \
-
 
502
                                               [edi+8]:2,[edi+10]:2,[edi],[edi+4]
475
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16)
503
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
Line 476... Line 504...
476
        jmp     .ftdi_out_control_transfer_noinp  
504
                                + (SIO_SET_BITMODE_REQUEST shl 8)                                       
-
 
505
        jmp     .ftdi_out_control_transfer_withinp        
-
 
506
     
477
        
507
  .ftdi_set_line_property:
-
 
508
        DEBUGF 2, 'K : FTDI Set line property 0x%x PID: %d Dev handler 0x0x%x\n', \
478
  .ftdi_set_bitmode:
509
                                                          [edi+8]:4,[edi],[edi+4]
Line 479... Line 510...
479
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)                                       
510
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
-
 
511
                                + (SIO_SET_DATA_REQUEST shl 8)
-
 
512
        jmp     .ftdi_out_control_transfer_withinp
480
        jmp     .ftdi_out_control_transfer_withinp        
513
        
-
 
514
  .ftdi_set_latency_timer:
481
     
515
        DEBUGF 2, 'K : FTDI Set latency %d PID: %d Dev handler 0x0x%x\n', \
Line 482... Line 516...
482
  .ftdi_set_line_property:
516
                                                          [edi+8],[edi],[edi+4]
-
 
517
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
-
 
518
                                + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)        
483
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
519
        jmp     .ftdi_out_control_transfer_withinp
-
 
520
        
484
        jmp     .ftdi_out_control_transfer_withinp
521
  .ftdi_set_event_char:
Line 485... Line 522...
485
        
522
        DEBUGF 2, 'K : FTDI Set event char %c PID: %d Dev handler 0x0x%x\n', \
-
 
523
                                                          [edi+8],[edi],[edi+4]
-
 
524
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
-
 
525
                                + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
486
  .ftdi_set_latency_timer:
526
        jmp     .ftdi_out_control_transfer_withinp
487
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)        
527
 
488
        jmp     .ftdi_out_control_transfer_withinp
528
  .ftdi_set_error_char:
489
        
529
        DEBUGF 2, 'K : FTDI Set error char %c PID: %d Dev handler 0x0x%x\n', \
490
  .ftdi_set_event_char:
530
                                                          [edi+8],[edi],[edi+4]
491
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
531
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
492
        jmp     .ftdi_out_control_transfer_withinp
532
                                + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
493
 
533
        jmp     .ftdi_out_control_transfer_withinp 
Line 494... Line 534...
494
  .ftdi_set_error_char:
534
        
-
 
535
  .ftdi_setflowctrl:
-
 
536
        DEBUGF 2, 'K : FTDI Set flow control PID: %d Dev handler 0x0x%x\n', [edi],\
495
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
537
                                                                        [edi+4]
-
 
538
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
496
        jmp     .ftdi_out_control_transfer_withinp 
539
                                 + (SIO_SET_FLOW_CTRL_REQUEST shl 8) + (0 shl 16)
497
        
540
        mov     ebx, [edi+4]
498
  .ftdi_setflowctrl:
541
        mov     cx, word[edi+8]   
499
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_FLOW_CTRL_REQUEST shl 8) + (0 shl 16)
542
        or      ecx, [ebx + ftdi_context.index]
500
        mov     ebx, [edi+4]
543
        mov     word[ConfPacket+4], cx
501
        mov     cx, word[edi+8]   
544
        xor     cx, cx
502
        or      ecx, [ebx + ftdi_context.index]
545
        mov     word[ConfPacket+6], cx
503
        mov     word[ConfPacket+4], cx
546
        jmp     .own_index
504
        xor     cx, cx
547
 
505
        mov     word[ConfPacket+6], cx
548
  .ftdi_read_pins:
-
 
549
        DEBUGF 2, 'K : FTDI Read pins PID: %d Dev handler 0x0x%x\n', [edi],\
506
        jmp     .own_index
550
                                                                     [edi+4]
507
 
551
        mov     ebx, [edi+4] 
508
  .ftdi_read_pins:                            
552
        mov     dword[ConfPacket], (FTDI_DEVICE_IN_REQTYPE) /
509
        mov     ebx, [edi+4] 
553
                                 + (SIO_READ_PINS_REQUEST shl 8) + (0 shl 16)
510
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_READ_PINS_REQUEST shl 8) + (0 shl 16)
554
        mov     ecx, [ebx + ftdi_context.index]
511
        mov     ecx, [ebx + ftdi_context.index]
555
        mov     word[ConfPacket+4], cx
512
        mov     word[ConfPacket+4], cx
556
        mov     word[ConfPacket+6], 1
513
        mov     word[ConfPacket+6], 1
557
        lea     esi, [ConfPacket]
Line 529... Line 573...
529
        test    eax, eax
573
        test    eax, eax
530
        jz      .endswitch
574
        jz      .endswitch
531
        jmp     .error
575
        jmp     .error
Line 532... Line 576...
532
        
576
        
-
 
577
  .ftdi_set_wchunksize:
-
 
578
        DEBUGF 2, 'K : FTDI Set write chunksize %d bytes PID: %d Dev handler 0x0x%x\n', \
533
  .ftdi_set_wchunksize:
579
                                                    [edi+8], [edi], [edi+4]
534
        mov     ebx, [edi+4]
580
        mov     ebx, [edi+4]
535
        mov     ecx, [edi+8] 
581
        mov     ecx, [edi+8] 
536
        cmp     [ebx + ftdi_context.maxPacketSize], ecx
582
        cmp     [ebx + ftdi_context.maxPacketSize], ecx
537
        jg      .error
583
        jg      .error
538
        mov     [ebx + ftdi_context.writeBufChunkSize], ecx
584
        mov     [ebx + ftdi_context.writeBufChunkSize], ecx
Line 539... Line 585...
539
        jmp     .endswitch
585
        jmp     .endswitch
-
 
586
   
-
 
587
  .ftdi_get_wchunksize:
540
   
588
        DEBUGF 2, 'K : FTDI Get write chunksize PID: %d Dev handler 0x0x%x\n', [edi],\
541
  .ftdi_get_wchunksize:
589
                                                                        [edi+4]
542
        mov     esi, [edi+output]
590
        mov     esi, [edi+output]
543
        mov     edi, [edi+input]
591
        mov     edi, [edi+input]
544
        mov     ebx, [edi+4]
592
        mov     ebx, [edi+4]
545
        mov     ecx, [ebx + ftdi_context.writeBufChunkSize]
593
        mov     ecx, [ebx + ftdi_context.writeBufChunkSize]
Line 546... Line 594...
546
        mov     [esi], ecx
594
        mov     [esi], ecx
-
 
595
        jmp     .endswitch
-
 
596
 
547
        jmp     .endswitch
597
  .ftdi_set_rchunksize:
548
 
598
        DEBUGF 2, 'K : FTDI Set read chunksize %d bytes PID: %d Dev handler 0x0x%x\n', \
549
  .ftdi_set_rchunksize:
599
                                                    [edi+8], [edi], [edi+4]
550
        mov     ebx, [edi+4]
600
        mov     ebx, [edi+4]
551
        mov     ecx, [edi+8]
601
        mov     ecx, [edi+8]
552
        cmp     [ebx + ftdi_context.maxPacketSize], ecx
602
        cmp     [ebx + ftdi_context.maxPacketSize], ecx
Line 553... Line 603...
553
        jg      .error
603
        jg      .error
-
 
604
        mov     [ebx + ftdi_context.readBufChunkSize], ecx
-
 
605
        jmp     .endswitch
554
        mov     [ebx + ftdi_context.readBufChunkSize], ecx
606
 
555
        jmp     .endswitch
607
  .ftdi_get_rchunksize:
556
 
608
        DEBUGF 2, 'K : FTDI Get read chunksize PID: %d Dev handler 0x0x%x\n', [edi],\
557
  .ftdi_get_rchunksize:
609
                                                                        [edi+4]
558
        mov     esi, [edi+output]
610
        mov     esi, [edi+output]
559
        mov     edi, [edi+input]
611
        mov     edi, [edi+input]
Line 560... Line 612...
560
        mov     ebx, [edi+4]
612
        mov     ebx, [edi+4]
-
 
613
        mov     ecx, [ebx + ftdi_context.readBufChunkSize]
-
 
614
        mov     [esi], ecx
561
        mov     ecx, [ebx + ftdi_context.readBufChunkSize]
615
        jmp     .endswitch        
562
        mov     [esi], ecx
616
 
563
        jmp     .endswitch        
617
  .ftdi_write_data:
564
 
618
        DEBUGF 2, 'K : FTDI Write %d bytes PID: %d Dev handler 0x%x\n', [edi+8],\
565
  .ftdi_write_data:
619
                                                            [edi], [edi+4]
566
        mov     esi, edi
620
        mov     esi, edi
567
        add     esi, 12        
621
        add     esi, 12        
568
        mov     ebx, [edi+4]
622
        mov     ebx, [edi+4]
569
        ;---Dirty hack begin
623
        ;---Dirty hack begin
570
        mov     eax, [edi+8]
624
        mov     eax, [edi+8]
571
        call    Kmalloc
625
        invoke  Kmalloc
572
        test    eax, eax
626
        test    eax, eax
573
        jnz     @f
627
        jnz     @f
574
        mov     esi, nomemory_msg
628
        mov     esi, nomemory_msg
575
        call    SysMsgBoardStr
629
        invoke  SysMsgBoardStr
Line 592... Line 646...
592
        mov     edx, [ebx + ftdi_context.writeBufChunkSize]
646
        mov     edx, [ebx + ftdi_context.writeBufChunkSize]
593
  .lessthanchunk_write:
647
  .lessthanchunk_write:
594
        add     esi, ecx
648
        add     esi, ecx
595
        lea     eax, [EventData]
649
        lea     eax, [EventData]
596
        push    ecx ebx esi edi
650
        push    ecx ebx esi edi
597
        stdcall USBNormalTransferAsync, [ebx + ftdi_context.inEP], esi, edx, bulk_callback, eax, 1        
651
        invoke USBNormalTransferAsync, [ebx + ftdi_context.inEP], esi, edx, \
-
 
652
                                            bulk_callback, eax, 1
598
        mov     eax, [EventData]
653
        mov     eax, [EventData]
599
        mov     ebx, [EventData+4]
654
        mov     ebx, [EventData+4]
600
        call    WaitEvent
655
        invoke  WaitEvent
601
        pop     edi esi ebx ecx
656
        pop     edi esi ebx ecx
602
        cmp     [EventData+8], -1
657
        cmp     [EventData+8], -1
603
        jz      .error
658
        jz      .error
604
        add     ecx, [EventData+8]
659
        add     ecx, [EventData+8]
605
        cmp     ecx, [edi+8]
660
        cmp     ecx, [edi+8]
606
        jge     .eventdestroy
661
        jge     .eventdestroy
607
        jmp     .write_loop
662
        jmp     .write_loop
Line 608... Line 663...
608
        
663
        
-
 
664
  .ftdi_read_data:
-
 
665
        DEBUGF 2, 'K : FTDI Read %d bytes PID: %d Dev handler 0x%x\n', [edi+8],\
609
  .ftdi_read_data:
666
                                                            [edi], [edi+4]
610
        mov     edi, [ioctl]
667
        mov     edi, [ioctl]
611
        mov     esi, [edi+input]
668
        mov     esi, [edi+input]
612
        mov     edi, [edi+output]
669
        mov     edi, [edi+output]
613
        mov     ebx, [esi+4]     
670
        mov     ebx, [esi+4]     
614
        ;---Dirty hack begin
671
        ;---Dirty hack begin
615
        mov     eax, [esi+8]
672
        mov     eax, [esi+8]
616
        call    Kmalloc
673
        invoke  Kmalloc
617
        test    eax, eax
674
        test    eax, eax
618
        jnz     @f
675
        jnz     @f
619
        mov     esi, nomemory_msg
676
        mov     esi, nomemory_msg
620
        call    SysMsgBoardStr
677
        invoke  SysMsgBoardStr
621
        jmp     .eventdestroy
678
        jmp     .eventdestroy
622
  @@:
679
  @@:
623
        mov     edi, eax
680
        mov     edi, eax
624
        push    edi eax
681
        ; push    edi eax
625
        mov     ecx, [esi+8]
682
        ; mov     ecx, [esi+8]
626
        xor     eax, eax
683
        ; xor     eax, eax
627
        rep     stosb
684
        ; rep     stosb
628
        pop     eax edi
685
        ; pop     eax edi
629
        mov     dword[ConfPacket], eax ; Store in ConfPAcket ptr to allocated memory
686
        mov     dword[ConfPacket], eax ; Store in ConfPacket ptr to allocated memory
630
        ;---Dirty hack end        
687
        ;---Dirty hack end        
631
        xor     ecx, ecx
688
        xor     ecx, ecx
632
  .read_loop:
689
  .read_loop:
633
        mov     edx, [esi+8]
690
        mov     edx, [esi+8]
Line 639... Line 696...
639
        mov     edx, [ebx + ftdi_context.readBufChunkSize]     
696
        mov     edx, [ebx + ftdi_context.readBufChunkSize]     
640
  .lessthanchunk_read:
697
  .lessthanchunk_read:
641
        lea     eax, [EventData]
698
        lea     eax, [EventData]
642
        add     edi, ecx
699
        add     edi, ecx
643
        push    esi edi ecx ebx
700
        push    esi edi ecx ebx
644
        stdcall USBNormalTransferAsync, [ebx + ftdi_context.outEP], edi, edx, bulk_callback, eax, 1        
701
        invoke  USBNormalTransferAsync, [ebx + ftdi_context.outEP], edi, edx, \
-
 
702
                                            bulk_callback, eax, 1        
645
        mov     eax, [EventData]
703
        mov     eax, [EventData]
646
        mov     ebx, [EventData+4]        
704
        mov     ebx, [EventData+4]        
647
        call    WaitEvent
705
        invoke  WaitEvent
648
        pop     ebx ecx edi esi
706
        pop     ebx ecx edi esi
649
        cmp     [EventData+8], -1        
707
        cmp     [EventData+8], -1        
650
        jz      .error
708
        jz      .error
651
        add     ecx, [EventData+8]
709
        add     ecx, [EventData+8]
652
        jmp     .read_loop 
710
        jmp     .read_loop 
Line 660... Line 718...
660
        rep     movsb
718
        rep     movsb
661
        jmp     .eventdestroy
719
        jmp     .eventdestroy
662
        ;---Dirty hack end
720
        ;---Dirty hack end
Line 663... Line 721...
663
        
721
        
-
 
722
  .ftdi_poll_modem_status:
-
 
723
        DEBUGF 2, 'K : FTDI Poll modem status PID: %d Dev handler 0x0x%x\n', [edi],\
664
  .ftdi_poll_modem_status:                                 
724
                                                                        [edi+4] 
-
 
725
        mov     ebx, [edi+4] 
665
        mov     ebx, [edi+4] 
726
        mov     dword[ConfPacket], (FTDI_DEVICE_IN_REQTYPE) \
666
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_POLL_MODEM_STATUS_REQUEST shl 8) + (0 shl 16)
727
                                 + (SIO_POLL_MODEM_STATUS_REQUEST shl 8) + (0 shl 16)
667
        mov     ecx, [ebx + ftdi_context.index]
728
        mov     ecx, [ebx + ftdi_context.index]
668
        mov     word[ConfPacket+4], cx
729
        mov     word[ConfPacket+4], cx
669
        mov     word[ConfPacket+6], 1
730
        mov     word[ConfPacket+6], 1
670
        lea     esi, [ConfPacket]
731
        lea     esi, [ConfPacket]
671
        lea     edi, [EventData]
732
        lea     edi, [EventData]
672
        mov     ecx, [ioctl]
733
        mov     ecx, [ioctl]
673
        mov     ecx, [ecx+output]
734
        mov     ecx, [ecx+output]
-
 
735
        invoke  USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, \
674
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 2, control_callback, edi, 0
736
                                            2, control_callback, edi, 0
675
        mov     eax, [EventData]
737
        mov     eax, [EventData]
676
        mov     ebx, [EventData+4]
738
        mov     ebx, [EventData+4]
677
        call    WaitEvent
739
        invoke  WaitEvent
678
        mov     ax, word[ecx]
740
        mov     ax, word[ecx]
679
        xchg    ah, al
741
        xchg    ah, al
680
        and     ah, 0xFF
742
        and     ah, 0xFF
681
        mov     word[ecx], ax
743
        mov     word[ecx], ax
Line 682... Line 744...
682
        jmp     .endswitch
744
        jmp     .endswitch
-
 
745
        
-
 
746
  .ftdi_get_latency_timer:
683
        
747
        DEBUGF 2, 'K : FTDI Get latency timer PID: %d Dev handler 0x0x%x\n', [edi],\
-
 
748
                                                                        [edi+4] 
684
  .ftdi_get_latency_timer:                                 
749
        mov     ebx, [edi+4] 
685
        mov     ebx, [edi+4] 
750
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE \
686
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_GET_LATENCY_TIMER_REQUEST shl 8) + (0 shl 16)
751
                                + (SIO_GET_LATENCY_TIMER_REQUEST shl 8) + (0 shl 16)
687
        mov     ecx, [ebx + ftdi_context.index]
752
        mov     ecx, [ebx + ftdi_context.index]
688
        mov     word[ConfPacket+4], cx
753
        mov     word[ConfPacket+4], cx
689
        mov     word[ConfPacket+6], 1
754
        mov     word[ConfPacket+6], 1
690
        lea     esi, [ConfPacket]
755
        lea     esi, [ConfPacket]
691
        lea     edi, [EventData]
756
        lea     edi, [EventData]
692
        mov     ecx, [ioctl]
757
        mov     ecx, [ioctl]
-
 
758
        mov     ecx, [ecx+output]
693
        mov     ecx, [ecx+output]
759
        invoke  USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, \
694
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 2, control_callback, edi, 0
760
                                            2, control_callback, edi, 0
695
        mov     eax, [EventData]
761
        mov     eax, [EventData]
696
        mov     ebx, [EventData+4]
762
        mov     ebx, [EventData+4]
Line 697... Line 763...
697
        call    WaitEvent
763
        invoke  WaitEvent
-
 
764
        jmp     .endswitch
698
        jmp     .endswitch
765
                
699
                
766
  .ftdi_get_list:
700
  .ftdi_get_list:                               
767
        DEBUGF 2, 'K : FTDI devices\' list request\n'  
701
        mov     edi, [edi+output]
768
        mov     edi, [edi+output]
702
        xor     ecx, ecx
769
        xor     ecx, ecx
Line 725... Line 792...
725
  .emptylist:
792
  .emptylist:
726
        mov     [edi], ecx
793
        mov     [edi], ecx
727
        jmp     .endswitch
794
        jmp     .endswitch
Line 728... Line 795...
728
        	   
795
 
-
 
796
  .ftdi_lock:
729
  .ftdi_lock:
797
        DEBUGF 2, 'K : FTDI Lock PID: %d Dev handler 0x0x%x\n', [edi], [edi+4]  
730
        mov     esi, [edi+input]
798
        mov     esi, [edi+input]
731
        mov     ebx, [esi+4]
799
        mov     ebx, [esi+4]
732
        mov     eax, [ebx + ftdi_context.lockPID]
800
        mov     eax, [ebx + ftdi_context.lockPID]
733
        test    eax, eax
801
        test    eax, eax
Line 738... Line 806...
738
        mov     edi, [edi+output]
806
        mov     edi, [edi+output]
739
        mov     [edi], eax
807
        mov     [edi], eax
740
        jmp     .endswitch
808
        jmp     .endswitch
Line 741... Line 809...
741
        
809
        
-
 
810
  .ftdi_unlock:
742
  .ftdi_unlock:
811
        DEBUGF 2, 'K : FTDI Unlock PID: %d Dev handler 0x0x%x\n', [edi], [edi+4]
743
        mov     esi, [edi+input]
812
        mov     esi, [edi+input]
744
        mov     edi, [edi+output]
813
        mov     edi, [edi+output]
745
        mov     ebx, [esi+4]
814
        mov     ebx, [esi+4]
746
        mov     eax, [ebx + ftdi_context.lockPID]
815
        mov     eax, [ebx + ftdi_context.lockPID]
Line 754... Line 823...
754
        jmp     .endswitch 
823
        jmp     .endswitch 
Line 755... Line 824...
755
 
824
 
756
H_CLK = 120000000
825
H_CLK = 120000000
757
C_CLK = 48000000        
826
C_CLK = 48000000        
-
 
827
  .ftdi_set_baudrate:
-
 
828
        DEBUGF 2, 'K : FTDI Set baudrate to %d PID: %d Dev handle: 0x%x\n',\
758
  .ftdi_set_baudrate:
829
                   [edi+8], [edi], [edi+4]
759
        mov     ebx, [edi+4]
830
        mov     ebx, [edi+4]
760
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
831
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
761
        jl      .c_clk        
832
        jl      .c_clk        
762
        imul    eax, [edi+8], 10
833
        imul    eax, [edi+8], 10
Line 881... Line 952...
881
        shr     ecx, 8
952
        shr     ecx, 8
882
        and     ecx, 0xFF00
953
        and     ecx, 0xFF00
883
        or      ecx, [ebx + ftdi_context.index]
954
        or      ecx, [ebx + ftdi_context.index]
Line 884... Line 955...
884
        
955
        
885
  .preparepacket:
956
  .preparepacket:
-
 
957
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) \
886
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BAUDRATE_REQUEST shl 8)
958
                                + (SIO_SET_BAUDRATE_REQUEST shl 8)
887
        mov     word[ConfPacket+2], ax
959
        mov     word[ConfPacket+2], ax
888
        mov     word[ConfPacket+4], cx
960
        mov     word[ConfPacket+4], cx
889
        mov     word[ConfPacket+6], 0
961
        mov     word[ConfPacket+6], 0
Line 896... Line 968...
896
restore   inp_size
968
restore   inp_size
897
restore   output
969
restore   output
898
restore   out_size 
970
restore   out_size 
Line 899... Line -...
899
 
-
 
900
 
971
 
-
 
972
 
Line 901... Line 973...
901
align 4
973
proc control_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, \
902
proc control_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD   
974
                               .buffer:DWORD, .length:DWORD, .calldata:DWORD   
903
   
975
   
904
        DEBUGF 1, 'K : status is %d\n', [.status] 
976
        DEBUGF 1, 'K : status is %d\n', [.status] 
905
        mov     ecx, [.calldata]
977
        mov     ecx, [.calldata]
906
        mov     eax, [ecx]
978
        mov     eax, [ecx]
907
        mov     ebx, [ecx+4]
979
        mov     ebx, [ecx+4]
908
        mov     edx, [.status]
980
        mov     edx, [.status]
909
        mov     [ecx+8], edx
981
        mov     [ecx+8], edx
910
        xor     esi, esi
982
        xor     esi, esi
911
        xor     edx, edx
983
        xor     edx, edx
Line 912... Line 984...
912
        call    RaiseEvent              
984
        invoke  RaiseEvent              
-
 
985
        ret
Line 913... Line 986...
913
        ret
986
endp
914
endp
987
 
915
 
988
proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, \
916
proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD
989
                            .buffer:DWORD, .length:DWORD, .calldata:DWORD
Line 930... Line 1003...
930
  .error:
1003
  .error:
931
        mov     [ecx+8], dword -1
1004
        mov     [ecx+8], dword -1
932
  .ok:    
1005
  .ok:    
933
        xor     esi, esi
1006
        xor     esi, esi
934
        xor     edx, edx
1007
        xor     edx, edx
935
        call    RaiseEvent            
1008
        invoke  RaiseEvent            
936
        ret
1009
        ret
937
endp
1010
endp
Line 938... Line 1011...
938
 
1011
 
Line 939... Line 1012...
939
proc DeviceDisconnected stdcall uses  ebx esi edi, .device_data:DWORD
1012
proc DeviceDisconnected stdcall uses  ebx esi edi, .device_data:DWORD
940
 
1013
 
941
        DEBUGF 1, 'K : FTDI deleting device data %x\n', [.device_data]
1014
        DEBUGF 1, 'K : FTDI deleting device data 0x%x\n', [.device_data]
-
 
1015
        mov     eax, [.device_data] 
942
        mov     eax, [.device_data] 
1016
        call    linkedlist_unlink
943
        call    linkedlist_delete
1017
        invoke  Kfree
Line 944... Line 1018...
944
        ret           
1018
        ret           
Line 945... Line -...
945
endp
-
 
946
 
1019
endp
947
include 'linkedlist.inc'
-
 
-
 
1020
 
948
        
1021
include 'linkedlist.inc'
949
; Exported variable: kernel API version.
1022
 
950
align 4
1023
align 4
951
version dd      50005h
1024
 
952
; Structure with callback functions.
1025
; Structure with callback functions.
Line -... Line 1026...
-
 
1026
usb_functions:
-
 
1027
        dd      12
-
 
1028
        dd      AddDevice
953
usb_functions:
1029
        dd      DeviceDisconnected
954
        dd      12
1030
 
955
        dd      AddDevice
-
 
956
        dd      DeviceDisconnected
-
 
957
 
-
 
958
;for DEBUGF macro
-
 
959
include_debug_strings
-
 
960
 
-