Rev 5023 | Rev 5036 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5023 | Rev 5035 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
- | 6 | ;; FTDI chips driver for KolibriOS ;; |
|
- | 7 | ;; ;; |
|
- | 8 | ;; Written by gtament@gmail.com ;; |
|
- | 9 | ;; ;; |
|
- | 10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
|
- | 11 | ;; Version 2, June 1991 ;; |
|
- | 12 | ;; ;; |
|
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 14... | ||
7 | 14 | ||
Line 8... | Line 15... | ||
8 | format MS COFF |
15 | format MS COFF |
Line 13... | Line 20... | ||
13 | __DEBUG_LEVEL__ = 1 |
20 | __DEBUG_LEVEL__ = 1 |
Line 14... | Line 21... | ||
14 | 21 | ||
15 | node equ ftdi_context |
22 | node equ ftdi_context |
Line 16... | Line 23... | ||
16 | node.next equ ftdi_context.next_context |
23 | node.next equ ftdi_context.next_context |
17 | 24 | ||
18 | include '../../proc32.inc' |
25 | include '../proc32.inc' |
19 | include '../../imports.inc' |
26 | include '../imports.inc' |
Line 20... | Line 27... | ||
20 | include '../../fdo.inc' |
27 | include '../fdo.inc' |
21 | include '../../struct.inc' |
28 | include '../struct.inc' |
Line 22... | Line 29... | ||
22 | 29 | ||
Line 309... | Line 316... | ||
309 | dec eax |
316 | dec eax |
310 | jz .ftdi_unlock ;3 |
317 | jz .ftdi_unlock ;3 |
Line 311... | Line 318... | ||
311 | 318 | ||
312 | mov ebx, [esi+4] |
319 | mov ebx, [esi+4] |
- | 320 | mov ecx, [ebx + ftdi_context.lockPID] |
|
- | 321 | cmp dword[esi], 0 |
|
313 | mov ecx, [ebx + ftdi_context.lockPID] |
322 | jz .error |
314 | cmp ecx, [esi] |
323 | cmp ecx, [esi] |
315 | jz .pid_ok |
324 | jz .pid_ok |
316 | mov esi, [edi+output] |
325 | mov esi, [edi+output] |
317 | mov dword[esi], 'LCKD' |
326 | mov dword[esi], 'LCKD' |
Line 388... | Line 397... | ||
388 | jmp .endswitch |
397 | jmp .endswitch |
389 | .error: |
398 | .error: |
390 | mov esi, [edi+output] |
399 | mov esi, [edi+output] |
391 | mov [esi], dword 'ERR0' |
400 | mov [esi], dword 'ERR0' |
392 | or [esi], eax |
401 | or [esi], eax |
- | 402 | ret |
|
393 | .endswitch: |
403 | .endswitch: |
394 | xor eax, eax |
404 | xor eax, eax |
395 | ret |
405 | ret |
Line 396... | Line 406... | ||
396 | 406 | ||
Line 428... | Line 438... | ||
428 | mov ebx, [EventData+4] |
438 | mov ebx, [EventData+4] |
429 | call WaitEvent |
439 | call WaitEvent |
430 | jmp .endswitch |
440 | jmp .endswitch |
Line 431... | Line 441... | ||
431 | 441 | ||
432 | .ftdi_setrtshigh: |
442 | .ftdi_setrtshigh: |
433 | DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n' |
443 | ;DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n' |
434 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16) |
444 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16) |
Line 435... | Line 445... | ||
435 | jmp .ftdi_out_control_transfer_noinp |
445 | jmp .ftdi_out_control_transfer_noinp |
436 | 446 | ||
437 | .ftdi_setrtslow: |
447 | .ftdi_setrtslow: |
438 | DEBUGF 1,'K : FTDI Setting RTS pin LOW\n' |
448 | ;DEBUGF 1,'K : FTDI Setting RTS pin LOW\n' |
Line 439... | Line 449... | ||
439 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16) |
449 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16) |
440 | jmp .ftdi_out_control_transfer_noinp |
450 | jmp .ftdi_out_control_transfer_noinp |
441 | 451 | ||
442 | .ftdi_setdtrhigh: |
452 | .ftdi_setdtrhigh: |
Line 443... | Line 453... | ||
443 | DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n' |
453 | ;DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n' |
444 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16) |
454 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16) |
445 | jmp .ftdi_out_control_transfer_noinp |
455 | jmp .ftdi_out_control_transfer_noinp |
446 | 456 | ||
Line 447... | Line 457... | ||
447 | .ftdi_setdtrlow: |
457 | .ftdi_setdtrlow: |
448 | DEBUGF 1,'K : FTDI Setting DTR pin LOW\n' |
458 | ;DEBUGF 1,'K : FTDI Setting DTR pin LOW\n' |
449 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16) |
459 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16) |
450 | jmp .ftdi_out_control_transfer_noinp |
460 | jmp .ftdi_out_control_transfer_noinp |
Line 451... | Line 461... | ||
451 | 461 | ||
452 | .ftdi_usb_reset: |
462 | .ftdi_usb_reset: |
Line 461... | Line 471... | ||
461 | .ftdi_purge_tx_buf: |
471 | .ftdi_purge_tx_buf: |
462 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16) |
472 | mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16) |
463 | jmp .ftdi_out_control_transfer_noinp |
473 | jmp .ftdi_out_control_transfer_noinp |
Line 464... | Line 474... | ||
464 | 474 | ||
465 | .ftdi_set_bitmode: |
- | |
466 | DEBUGF 1,'K : FTDI Seting bitmode\n' |
475 | .ftdi_set_bitmode: |
467 | mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8) |
476 | mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8) |
Line 468... | Line 477... | ||
468 | jmp .ftdi_out_control_transfer_withinp |
477 | jmp .ftdi_out_control_transfer_withinp |
469 | 478 | ||
Line 600... | Line 609... | ||
600 | mov esi, nomemory_msg |
609 | mov esi, nomemory_msg |
601 | call SysMsgBoardStr |
610 | call SysMsgBoardStr |
602 | jmp .eventdestroy |
611 | jmp .eventdestroy |
603 | @@: |
612 | @@: |
604 | mov edi, eax |
613 | mov edi, eax |
605 | mov dword[ConfPacket], eax |
614 | mov dword[ConfPacket], eax ; Store in ConfPAcket ptr to allocated memory |
606 | ;---Dirty hack end |
615 | ;---Dirty hack end |
607 | xor ecx, ecx |
616 | xor ecx, ecx |
608 | .read_loop: |
617 | .read_loop: |
609 | mov edx, [esi+8] |
618 | mov edx, [esi+8] |
610 | cmp ecx, edx |
619 | cmp ecx, edx |
Line 626... | Line 635... | ||
626 | call ClearEvent |
635 | call ClearEvent |
627 | pop ebx ecx edi esi |
636 | pop ebx ecx edi esi |
628 | cmp [EventData+8], -1 |
637 | cmp [EventData+8], -1 |
629 | jz .error |
638 | jz .error |
630 | add ecx, [EventData+8] |
639 | add ecx, [EventData+8] |
- | 640 | DEBUGF 1, 'K : In buffer %x\n', [edi] |
|
631 | jmp .read_loop |
641 | jmp .read_loop |
632 | ;---Dirty hack begin |
642 | ;---Dirty hack begin |
633 | .read_end: |
643 | .read_end: |
634 | mov esi, dword[ConfPacket] |
644 | mov esi, dword[ConfPacket] |
635 | mov edi, [ioctl] |
645 | mov edi, [ioctl] |
Line 703... | Line 713... | ||
703 | pop edi |
713 | pop edi |
704 | mov [edi], ecx |
714 | mov [edi], ecx |
705 | jmp .endswitch |
715 | jmp .endswitch |
Line 706... | Line 716... | ||
706 | 716 | ||
707 | .ftdi_lock: |
- | |
708 | DEBUGF 1, 'K : FTDI lock attempt\n' |
717 | .ftdi_lock: |
709 | mov esi, [edi+input] |
718 | mov esi, [edi+input] |
710 | mov ebx, [esi+4] |
719 | mov ebx, [esi+4] |
- | 720 | mov eax, [ebx + ftdi_context.lockPID] |
|
711 | mov eax, [ebx + ftdi_context.lockPID] |
721 | DEBUGF 1, 'K : to PID %x from PID %x\n', [esi], eax |
712 | test eax, eax |
722 | test eax, eax |
713 | jnz .lockedby |
- | |
714 | DEBUGF 1, 'K : Lock success\n' |
723 | jnz .lockedby |
715 | mov eax, [esi] |
724 | mov eax, [esi] |
716 | mov [ebx + ftdi_context.lockPID], eax |
725 | mov [ebx + ftdi_context.lockPID], eax |
717 | .lockedby: |
726 | .lockedby: |
718 | mov edi, [edi+output] |
727 | mov edi, [edi+output] |
Line 722... | Line 731... | ||
722 | .ftdi_unlock: |
731 | .ftdi_unlock: |
723 | mov esi, [edi+input] |
732 | mov esi, [edi+input] |
724 | mov edi, [edi+output] |
733 | mov edi, [edi+output] |
725 | mov ebx, [esi+4] |
734 | mov ebx, [esi+4] |
726 | mov eax, [ebx + ftdi_context.lockPID] |
735 | mov eax, [ebx + ftdi_context.lockPID] |
- | 736 | DEBUGF 1, 'K : to PID %x from PID %x\n', [esi], eax |
|
727 | cmp eax, [esi] |
737 | cmp eax, [esi] |
728 | jnz .unlockimp |
738 | jnz .unlockimp |
729 | mov [ebx + ftdi_context.lockPID], 0 |
739 | mov [ebx + ftdi_context.lockPID], 0 |
730 | mov dword[edi], 0 |
740 | mov dword[edi], 0 |
731 | jmp .endswitch |
741 | jmp .endswitch |
Line 841... | Line 851... | ||
841 | 851 | ||
842 | .rounddownbaud: |
852 | .rounddownbaud: |
843 | mov edx, eax ; edx - encoded_divisor |
853 | mov edx, eax ; edx - encoded_divisor |
844 | shr edx, 3 |
854 | shr edx, 3 |
845 | and eax, 0x7 |
- | |
846 | push esp |
855 | and eax, 0x7 |
847 | push 7 6 5 1 4 2 3 0 |
856 | push 7 6 5 1 4 2 3 0 |
848 | mov eax, [esp+eax*4] |
857 | mov eax, [esp+eax*4] |
849 | shl eax, 14 |
858 | shl eax, 14 |
850 | or edx, eax |
859 | or edx, eax |
Line 851... | Line 860... | ||
851 | mov esp, [esp+36] |
860 | add esp, 32 |
852 | 861 | ||
853 | .calcend: |
862 | .calcend: |
854 | mov eax, edx ; eax - *value |
863 | mov eax, edx ; eax - *value |