Subversion Repositories Kolibri OS

Rev

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

Rev 4985 Rev 4992
Line 100... Line 100...
100
SIO_SET_RTS_HIGH=( 2 or ( SIO_SET_RTS_MASK shl 8 ))
100
SIO_SET_RTS_HIGH=( 2 or ( SIO_SET_RTS_MASK shl 8 ))
101
SIO_SET_RTS_LOW =( 0 or ( SIO_SET_RTS_MASK shl 8 ))
101
SIO_SET_RTS_LOW =( 0 or ( SIO_SET_RTS_MASK shl 8 ))
Line 102... Line 102...
102
 
102
 
Line -... Line 103...
-
 
103
SIO_RTS_CTS_HS =(0x1 shl 8)
-
 
104
 
-
 
105
;FTDI chip type
-
 
106
TYPE_AM=0
-
 
107
TYPE_BM=1
-
 
108
TYPE_2232C=2
-
 
109
TYPE_R=3
-
 
110
TYPE_2232H=4
-
 
111
TYPE_4232H=5
-
 
112
TYPE_232H=6
103
SIO_RTS_CTS_HS =(0x1 shl 8)
113
TYPE_230X=7
104
 
114
 
105
;strings
115
;strings
Line 106... Line 116...
106
my_driver       db      'usbother',0
116
my_driver       db      'usbother',0
Line 190... Line 200...
190
        DEBUGF 1,'K : Adding struct to list %x\n', eax
200
        DEBUGF 1,'K : Adding struct to list %x\n', eax
191
        call    linkedlist.add
201
        call    linkedlist.add
Line 192... Line 202...
192
        
202
        
193
        mov     ebx, [.config_pipe]
203
        mov     ebx, [.config_pipe]
-
 
204
        mov     [eax + ftdi_context.nullP], ebx
Line 194... Line 205...
194
        mov     [eax + ftdi_context.nullP], ebx
205
        mov     [eax + ftdi_context.index], 0
195
        
206
        
196
        DEBUGF 1,'K : Open first pipe\n'
207
        DEBUGF 1,'K : Open first pipe\n'
197
        mov     ebx, eax
208
        mov     ebx, eax
Line 250... Line 261...
250
  .endswitch:
261
  .endswitch:
251
        xor     eax, eax
262
        xor     eax, eax
252
	    ret 
263
	    ret 
Line 253... Line 264...
253
        
264
        
-
 
265
  .ftdi_out_control_transfer:
-
 
266
        mov     ebx, [edi]
-
 
267
        mov     cx, word[ebx + ftdi_context.index]
-
 
268
        mov     word[ConfPacket+4], cx
-
 
269
        xor     cx, cx
-
 
270
        mov     word[ConfPacket+6], cx
-
 
271
  .own_index:
254
  .ftdi_out_control_transfer:
272
        mov    ebx, [edi]
255
        DEBUGF 1,'K : ConfPacket %x %x\n', [ConfPacket], [ConfPacket+4]  
-
 
256
        mov     ecx, [edi+input]
-
 
257
        mov     ebx, [ecx] 
273
        DEBUGF 1,'K : ConfPacket %x %x\n', [ConfPacket], [ConfPacket+4]          
258
        lea     esi, [ConfPacket]
274
        lea     esi, [ConfPacket]
259
        lea     edi, [EventData]        
275
        lea     edi, [EventData]        
260
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, 0, 0, control_callback, edi, 0
276
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, 0, 0, control_callback, edi, 0
261
        DEBUGF 1, 'K : Returned value is %d\n', eax
277
        DEBUGF 1, 'K : Returned value is %d\n', eax
Line 268... Line 284...
268
        DEBUGF 1,'K : FTDI Seting bitmode\n'                   
284
        DEBUGF 1,'K : FTDI Seting bitmode\n'                   
269
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)
285
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)
270
        mov     edi, [edi+input]        
286
        mov     edi, [edi+input]        
271
        mov     dx, word[edi+4]                
287
        mov     dx, word[edi+4]                
272
        mov     word[ConfPacket+2], dx
288
        mov     word[ConfPacket+2], dx                                        
273
        mov     dword[ConfPacket+4], 0                                         
-
 
274
        jmp     .ftdi_out_control_transfer     
289
        jmp     .ftdi_out_control_transfer     
275
        jmp     .endswitch
-
 
Line 276... Line 290...
276
 
290
 
277
  .ftdi_setrtshigh:
291
  .ftdi_setrtshigh:
278
        DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n'                     
292
        DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n'                     
279
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16)
-
 
280
        mov     dword[ConfPacket+4], 0
293
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16)
281
        jmp     .ftdi_out_control_transfer         
-
 
Line 282... Line 294...
282
        jmp     .endswitch
294
        jmp     .ftdi_out_control_transfer         
283
 
295
 
284
  .ftdi_setrtslow:
296
  .ftdi_setrtslow:
285
        DEBUGF 1,'K : FTDI Setting RTS pin LOW\n'             
-
 
286
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16)
297
        DEBUGF 1,'K : FTDI Setting RTS pin LOW\n'             
287
        mov     dword[ConfPacket+4], 0
-
 
Line 288... Line 298...
288
        jmp     .ftdi_out_control_transfer         
298
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16)
289
        jmp     .endswitch
299
        jmp     .ftdi_out_control_transfer         
290
        
300
        
291
  .ftdi_setdtrhigh:
-
 
292
        DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n'                     
301
  .ftdi_setdtrhigh:
293
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16)
-
 
Line 294... Line 302...
294
        mov     dword[ConfPacket+4], 0
302
        DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n'                     
295
        jmp     .ftdi_out_control_transfer         
303
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16)
296
        jmp     .endswitch
304
        jmp     .ftdi_out_control_transfer         
297
 
-
 
298
  .ftdi_setdtrlow:
305
 
299
        DEBUGF 1,'K : FTDI Setting DTR pin LOW\n'             
-
 
Line 300... Line 306...
300
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16)
306
  .ftdi_setdtrlow:
301
        mov     dword[ConfPacket+4], 0
307
        DEBUGF 1,'K : FTDI Setting DTR pin LOW\n'             
302
        jmp     .ftdi_out_control_transfer         
308
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16)
303
        jmp     .endswitch
-
 
304
        
309
        jmp     .ftdi_out_control_transfer         
305
  .ftdi_usb_reset:
-
 
Line 306... Line 310...
306
        DEBUGF 1,'K : FTDI Reseting\n'
310
        
307
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16)
311
  .ftdi_usb_reset:
308
        mov     dword[ConfPacket+4], 0
-
 
309
        jmp     .ftdi_out_control_transfer         
312
        DEBUGF 1,'K : FTDI Reseting\n'
310
        jmp     .endswitch
-
 
Line 311... Line 313...
311
        
313
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16)
312
  .ftdi_purge_rx_buf:
314
        jmp     .ftdi_out_control_transfer
313
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16)
-
 
314
        mov     dword[ConfPacket+4], 0
315
        
315
        jmp     .ftdi_out_control_transfer         
-
 
Line -... Line 316...
-
 
316
  .ftdi_purge_rx_buf:
-
 
317
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16)
316
        jmp     .endswitch
318
        jmp     .ftdi_out_control_transfer
-
 
319
        
-
 
320
  .ftdi_purge_tx_buf:
-
 
321
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16)
-
 
322
        jmp     .ftdi_out_control_transfer
-
 
323
 
-
 
324
H_CLK = 120000000
-
 
325
C_CLK = 48000000        
-
 
326
  .ftdi_set_baudrate:
-
 
327
        mov     edi, [edi+input]
-
 
328
        mov     ebx, [edi]
-
 
329
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
-
 
330
        jl      .c_clk        
-
 
331
        imul    eax, [edi+4], 10
-
 
332
        cmp     eax, H_CLK / 0x3FFF        
-
 
333
        jle     .c_clk
-
 
334
  .h_clk:       
-
 
335
        cmp     dword[edi+4], H_CLK/10
-
 
336
        jl      .h_nextbaud1
-
 
337
        xor     edx, edx
-
 
338
        mov     ecx, H_CLK/10
-
 
339
        jmp     .calcend
-
 
340
        
-
 
341
  .c_clk:
-
 
342
        cmp     dword[edi+4], C_CLK/10
-
 
343
        jl      .c_nextbaud1
-
 
344
        xor     edx, edx
-
 
345
        mov     ecx, C_CLK/10
-
 
346
        jmp     .calcend  
-
 
347
  
-
 
348
  .h_nextbaud1:
-
 
349
        cmp     dword[edi+4], H_CLK/(10 + 10/2)
-
 
350
        jl      .h_nextbaud2
-
 
351
        mov     edx, 1
-
 
352
        mov     ecx, H_CLK/(10 + 10/2)
-
 
353
        jmp     .calcend
-
 
354
        
-
 
355
  .c_nextbaud1:
-
 
356
        cmp     dword[edi+4], C_CLK/(10 + 10/2)
-
 
357
        jl      .c_nextbaud2
-
 
358
        mov     edx, 1
-
 
359
        mov     ecx, C_CLK/(10 + 10/2)
-
 
360
        jmp     .calcend        
-
 
361
        
-
 
362
  .h_nextbaud2:      
-
 
363
        cmp     dword[edi+4], H_CLK/(2*10)
-
 
364
        jl      .h_nextbaud3
-
 
365
        mov     edx, 2
-
 
366
        mov     ecx, H_CLK/(2*10)
-
 
367
        jmp     .calcend
-
 
368
        
-
 
369
  .c_nextbaud2:      
-
 
370
        cmp     dword[edi+4], C_CLK/(2*10)
-
 
371
        jl      .c_nextbaud3
-
 
372
        mov     edx, 2
-
 
373
        mov     ecx, C_CLK/(2*10)
-
 
374
        jmp     .calcend        
-
 
375
        
-
 
376
  .h_nextbaud3:
-
 
377
        mov     eax, H_CLK*16/10  ; eax - best_divisor
-
 
378
        div     dword[edi+4]      ; [edi+4] - baudrate
317
        
379
        push    eax
-
 
380
        and     eax, 1
-
 
381
        pop     eax
-
 
382
        shr     eax, 1
-
 
383
        jz      .h_rounddowndiv     ; jump by result of and eax, 1
-
 
384
        inc     eax
-
 
385
  .h_rounddowndiv:
-
 
386
        cmp     eax, 0x20000
-
 
387
        jle     .h_best_divok
-
 
388
        mov     eax, 0x1FFFF
-
 
389
  .h_best_divok:
-
 
390
        mov     ecx, eax        
-
 
391
        mov     eax, H_CLK*16/10
318
  .ftdi_purge_tx_buf:
392
        div     ecx
-
 
393
        xchg    ecx, eax            ; ecx - best_baud
-
 
394
        push    ecx
-
 
395
        and     ecx, 1
-
 
396
        pop     ecx
-
 
397
        shr     ecx, 1
-
 
398
        jz      .rounddownbaud
-
 
399
        inc     ecx
-
 
400
        jmp     .rounddownbaud
-
 
401
        
-
 
402
  .c_nextbaud3:
-
 
403
        mov     eax, C_CLK*16/10  ; eax - best_divisor
-
 
404
        div     dword[edi+4]      ; [edi+4] - baudrate
-
 
405
        push    eax
-
 
406
        and     eax, 1
-
 
407
        pop     eax
-
 
408
        shr     eax, 1
-
 
409
        jz      .c_rounddowndiv     ; jump by result of and eax, 1
-
 
410
        inc     eax
-
 
411
  .c_rounddowndiv:
-
 
412
        cmp     eax, 0x20000
-
 
413
        jle     .c_best_divok
-
 
414
        mov     eax, 0x1FFFF
-
 
415
  .c_best_divok:
-
 
416
        mov     ecx, eax        
-
 
417
        mov     eax, C_CLK*16/10
-
 
418
        div     ecx
-
 
419
        xchg    ecx, eax            ; ecx - best_baud
-
 
420
        push    ecx
-
 
421
        and     ecx, 1
-
 
422
        pop     ecx
-
 
423
        shr     ecx, 1
-
 
424
        jz      .rounddownbaud
-
 
425
        inc     ecx
-
 
426
        
-
 
427
  .rounddownbaud:
-
 
428
        mov     edx, eax            ; edx - encoded_divisor
-
 
429
        shr     edx, 3
-
 
430
        and     eax, 0x7
-
 
431
        push    esp
-
 
432
        push    7 6 5 1 4 2 3 0
-
 
433
        mov     eax, [esp+eax*4]
-
 
434
        shl     eax, 14
-
 
435
        or      edx, eax
-
 
436
        mov     esp, [esp+36]
-
 
437
        
-
 
438
  .calcend:
-
 
439
        mov     eax, edx        ; eax - *value
-
 
440
        mov     ecx, edx        ; ecx - *index
-
 
441
        and     eax, 0xFFFF
-
 
442
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
-
 
443
        jge     .foxyindex        
-
 
444
        shr     ecx, 16
-
 
445
        jmp     .preparepacket
-
 
446
  .foxyindex:
-
 
447
        shr     ecx, 8
319
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16)
448
        and     ecx, 0xFF00
Line 320... Line 449...
320
        mov     dword[ConfPacket+4], 0
449
        or      ecx, [ebx + ftdi_context.index]
321
        jmp     .ftdi_out_control_transfer         
450
        
322
        jmp     .endswitch
451
  .preparepacket:
323
        
452
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BAUDRATE_REQUEST shl 8)
324
  .ftdi_set_baudrate:
453
        mov     word[ConfPacket+2], ax
325
        ;!!!!!!!!!!!!!!!!!!!!
-
 
326
        ;jmp     .ftdi_out_control_transfer         
454
        mov     word[ConfPacket+4], cx
327
        jmp     .endswitch
-
 
Line 328... Line 455...
328
        
455
        mov     word[ConfPacket+6], 0
329
  .ftdi_set_line_property:
456
        jmp     .own_index
330
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
457
     
331
        mov     edi, [edi+input]        
458
  .ftdi_set_line_property:
332
        mov     dx, word[edi+4]                
459
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
333
        mov     word[ConfPacket+2], dx
-
 
334
        mov     dword[ConfPacket+4], 0
460
        mov     edi, [edi+input]        
335
        jmp     .ftdi_out_control_transfer         
-
 
Line 336... Line 461...
336
        jmp     .endswitch  
461
        mov     dx, word[edi+4]                
337
        
462
        mov     word[ConfPacket+2], dx
338
  .ftdi_set_latency_timer:
463
        jmp     .ftdi_out_control_transfer
339
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)
464
        
340
        mov     edi, [edi+input]        
465
  .ftdi_set_latency_timer:
341
        mov     dx, word[edi+4]                
-
 
342
        mov     word[ConfPacket+2], dx
466
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)
343
        mov     dword[ConfPacket+4], 0
-
 
Line 344... Line 467...
344
        jmp     .ftdi_out_control_transfer         
467
        mov     edi, [edi+input]        
345
        jmp     .endswitch
468
        mov     dx, word[edi+4]                
346
        
469
        mov     word[ConfPacket+2], dx        
347
  .ftdi_set_event_char:
470
        jmp     .ftdi_out_control_transfer
348
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
471
        
349
        mov     edi, [edi+input]        
-
 
350
        mov     dx, word[edi+4]                
472
  .ftdi_set_event_char:
351
        mov     word[ConfPacket+2], dx
-
 
Line -... Line 473...
-
 
473
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
-
 
474
        mov     edi, [edi+input]        
-
 
475
        mov     dx, word[edi+4]                
-
 
476
        mov     word[ConfPacket+2], dx
-
 
477
        jmp     .ftdi_out_control_transfer
-
 
478
 
-
 
479
  .ftdi_set_error_char:
-
 
480
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
-
 
481
        mov     edi, [edi+input]        
-
 
482
        mov     dx, word[edi+4]                
Line 352... Line 483...
352
        mov     dword[ConfPacket+4], 0
483
        mov     word[ConfPacket+2], dx
353
        jmp     .ftdi_out_control_transfer         
484
        jmp     .ftdi_out_control_transfer 
354
        jmp     .endswitch
485
        
355
 
486
  .ftdi_setflowctrl: