Added getters and setter for chunksizes. Some optimizations. Added some checks and errors notification (work in progress).

git-svn-id: svn://kolibrios.org@5018 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
gtament 2014-08-06 15:09:22 +00:00
parent 098f10ccbc
commit 8297a4020c

View File

@ -124,6 +124,7 @@ baudrate dd ?
bitbangEnabled db ? bitbangEnabled db ?
readBufChunkSize dd ? readBufChunkSize dd ?
writeBufChunkSize dd ? writeBufChunkSize dd ?
maxPacketSize dd ?
interface dd ? interface dd ?
index dd ? index dd ?
inEP dd ? inEP dd ?
@ -181,14 +182,13 @@ proc START stdcall, .reason:DWORD
endp endp
proc AddDevice stdcall uses ebx esi, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD proc AddDevice stdcall uses ebx esi edi, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD
stdcall USBGetParam, [.config_pipe], 0 stdcall USBGetParam, [.config_pipe], 0
mov edx, eax mov edx, eax
DEBUGF 1,'K : Device detected Vendor: %x\n', [eax+usb_descr.idVendor] DEBUGF 1,'K : Detected device vendor: %x\n', [eax+usb_descr.idVendor]
cmp word[eax+usb_descr.idVendor], 0x0403 cmp word[eax+usb_descr.idVendor], 0x0403
jnz .notftdi jnz .notftdi
DEBUGF 1,'K : FTDI USB device detected\n'
movi eax, sizeof.ftdi_context movi eax, sizeof.ftdi_context
call Kmalloc call Kmalloc
test eax, eax test eax, eax
@ -204,44 +204,57 @@ proc AddDevice stdcall uses ebx esi, .config_pipe:DWORD, .config_descr:DWORD, .i
mov [eax + ftdi_context.nullP], ebx mov [eax + ftdi_context.nullP], ebx
mov [eax + ftdi_context.index], 0 mov [eax + ftdi_context.index], 0
mov [eax + ftdi_context.lockPID], 0 mov [eax + ftdi_context.lockPID], 0
mov [eax + ftdi_context.maxPacketSize], 64
mov [eax + ftdi_context.readBufChunkSize], 64 mov [eax + ftdi_context.readBufChunkSize], 64
mov [eax + ftdi_context.writeBufChunkSize], 64 mov [eax + ftdi_context.writeBufChunkSize], 64
cmp [edx+usb_descr.bcdDevice], 0x400 mov cx, [edx+usb_descr.bcdDevice]
cmp cx, 0x400
jnz @f jnz @f
mov [eax + ftdi_context.chipType], TYPE_BM mov [eax + ftdi_context.chipType], TYPE_BM
jmp .slow
@@: @@:
cmp [edx+usb_descr.bcdDevice], 0x200 cmp cx, 0x200
jnz @f jnz @f
mov [eax + ftdi_context.chipType], TYPE_AM mov [eax + ftdi_context.chipType], TYPE_AM
jmp .slow
@@: @@:
cmp [edx+usb_descr.bcdDevice], 0x500 cmp cx, 0x500
jnz @f jnz @f
mov [eax + ftdi_context.chipType], TYPE_2232C mov [eax + ftdi_context.chipType], TYPE_2232C
jmp .slow
@@: @@:
cmp [edx+usb_descr.bcdDevice], 0x600 cmp cx, 0x600
jnz @f jnz @f
mov [eax + ftdi_context.chipType], TYPE_R mov [eax + ftdi_context.chipType], TYPE_R
jmp .slow
@@: @@:
cmp [edx+usb_descr.bcdDevice], 0x700 cmp cx, 0x700
jnz @f jnz @f
mov [eax + ftdi_context.chipType], TYPE_2232H mov [eax + ftdi_context.chipType], TYPE_2232H
jmp .fast
@@: @@:
cmp [edx+usb_descr.bcdDevice], 0x900 cmp cx, 0x900
jnz @f jnz @f
mov [eax + ftdi_context.chipType], TYPE_232H mov [eax + ftdi_context.chipType], TYPE_232H
jmp .fast
@@: @@:
cmp [edx+usb_descr.bcdDevice], 0x1000 cmp cx, 0x1000
jnz @f jnz .slow
mov [eax + ftdi_context.chipType], TYPE_BM mov [eax + ftdi_context.chipType], TYPE_230X
@@: jmp .fast
DEBUGF 1,'K : Open first pipe\n' .fast:
add [eax + ftdi_context.maxPacketSize], 512-64
.slow:
mov ebx, eax mov ebx, eax
stdcall USBOpenPipe, [.config_pipe], 0x81, 0x40, BULK_PIPE, 0 stdcall USBOpenPipe, [.config_pipe], 0x81, [ebx + ftdi_context.maxPacketSize], BULK_PIPE, 0
test eax, eax
jz .nothing
mov [ebx + ftdi_context.inEP], eax mov [ebx + ftdi_context.inEP], eax
DEBUGF 1,'K : Open second pipe\n' stdcall USBOpenPipe, [.config_pipe], 0x02, [ebx + ftdi_context.maxPacketSize], BULK_PIPE, 0
stdcall USBOpenPipe, [.config_pipe], 0x02, 0x40, BULK_PIPE, 0 test eax, eax
jz .nothing
mov [ebx + ftdi_context.outEP], eax mov [ebx + ftdi_context.outEP], eax
mov eax, ebx mov eax, ebx
ret ret
@ -297,6 +310,18 @@ endl
jmp .endswitch jmp .endswitch
.pid_ok: .pid_ok:
dec eax
jz .ftdi_get_wchunksize ;5
dec eax
jz .ftdi_get_rchunksize ;7
mov edi, [edi+input]
dec eax
jz .ftdi_set_rchunksize ;6
dec eax
jz .ftdi_set_wchunksize ;4
push eax edi push eax edi
mov ecx, 0x80000000 mov ecx, 0x80000000
cmp eax, 17 cmp eax, 17
@ -311,52 +336,67 @@ endl
mov [EventData+4], edx mov [EventData+4], edx
pop edi eax pop edi eax
dec eax ;4
jz .ftdi_set_bitmode
dec eax ;5
jz .ftdi_setrtshigh
dec eax ;6
jz .ftdi_setrtslow
dec eax ;7
jz .ftdi_setdtrhigh
dec eax ;8 dec eax ;8
jz .ftdi_setdtrlow jz .ftdi_set_bitmode
dec eax ;9 dec eax ;9
jz .ftdi_usb_reset jz .ftdi_setrtshigh
dec eax ;10 dec eax ;10
jz .ftdi_setflowctrl jz .ftdi_setrtslow
dec eax ;11 dec eax ;11
jz .ftdi_set_event_char jz .ftdi_setdtrhigh
dec eax ;12 dec eax ;12
jz .ftdi_set_error_char jz .ftdi_setdtrlow
dec eax ;13 dec eax ;13
jz .ftdi_set_latency_timer jz .ftdi_usb_reset
dec eax ;14 dec eax ;14
jz .ftdi_get_latency_timer jz .ftdi_setflowctrl
dec eax ;15 dec eax ;15
jz .ftdi_read_pins jz .ftdi_set_event_char
dec eax ;16 dec eax ;16
jz .ftdi_poll_modem_status jz .ftdi_set_error_char
dec eax ;17 dec eax ;17
jz .ftdi_write_data jz .ftdi_set_latency_timer
dec eax ;18 dec eax ;18
jz .ftdi_read_data jz .ftdi_get_latency_timer
dec eax ;19 dec eax ;19
jz .ftdi_set_baudrate jz .ftdi_read_pins
dec eax ;20 dec eax ;20
jz .ftdi_set_line_property jz .ftdi_poll_modem_status
dec eax ;21 dec eax ;21
jz .ftdi_purge_rx_buf jz .ftdi_write_data
dec eax ;22 dec eax ;22
jz .ftdi_read_data
dec eax ;23
jz .ftdi_set_baudrate
dec eax ;24
jz .ftdi_set_line_property
dec eax ;25
jz .ftdi_purge_rx_buf
dec eax ;26
jz .ftdi_purge_tx_buf jz .ftdi_purge_tx_buf
jmp .error
.version: .version:
jmp .endswitch
.error:
mov esi, [edi+output]
mov [esi], dword 'ERR0'
or [esi], eax
.endswitch: .endswitch:
xor eax, eax xor eax, eax
ret ret
.ftdi_out_control_transfer: .eventdestroy:
mov ebx, [edi] mov eax, [EventData]
mov ebx, [EventData+4]
call DestroyEvent
jmp .endswitch
.ftdi_out_control_transfer_withinp:
mov dx, word[edi+8]
mov word[ConfPacket+2], dx
.ftdi_out_control_transfer_noinp:
mov ebx, [edi+4]
mov cx, word[ebx + ftdi_context.index] mov cx, word[ebx + ftdi_context.index]
mov word[ConfPacket+4], cx mov word[ConfPacket+4], cx
xor cx, cx xor cx, cx
@ -367,58 +407,283 @@ endl
lea esi, [ConfPacket] lea esi, [ConfPacket]
lea edi, [EventData] lea edi, [EventData]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, 0, 0, control_callback, edi, 0 stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, 0, 0, control_callback, edi, 0
DEBUGF 1, 'K : Returned value is %d\n', eax test eax, eax
jz .error
mov eax, [EventData] mov eax, [EventData]
mov ebx, [EventData+4] mov ebx, [EventData+4]
call WaitEvent call WaitEvent
jmp .endswitch jmp .endswitch
.ftdi_set_bitmode:
DEBUGF 1,'K : FTDI Seting bitmode\n'
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)
mov edi, [edi+input]
mov dx, word[edi+8]
mov word[ConfPacket+2], dx
jmp .ftdi_out_control_transfer
.ftdi_setrtshigh: .ftdi_setrtshigh:
DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n' DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n'
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_setrtslow: .ftdi_setrtslow:
DEBUGF 1,'K : FTDI Setting RTS pin LOW\n' DEBUGF 1,'K : FTDI Setting RTS pin LOW\n'
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_setdtrhigh: .ftdi_setdtrhigh:
DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n' DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n'
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_setdtrlow: .ftdi_setdtrlow:
DEBUGF 1,'K : FTDI Setting DTR pin LOW\n' DEBUGF 1,'K : FTDI Setting DTR pin LOW\n'
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_usb_reset: .ftdi_usb_reset:
DEBUGF 1,'K : FTDI Reseting\n' DEBUGF 1,'K : FTDI Reseting\n'
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_purge_rx_buf: .ftdi_purge_rx_buf:
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_purge_tx_buf: .ftdi_purge_tx_buf:
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16) mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16)
jmp .ftdi_out_control_transfer jmp .ftdi_out_control_transfer_noinp
.ftdi_set_bitmode:
DEBUGF 1,'K : FTDI Seting bitmode\n'
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)
jmp .ftdi_out_control_transfer_withinp
.ftdi_set_line_property:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
jmp .ftdi_out_control_transfer_withinp
.ftdi_set_latency_timer:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)
jmp .ftdi_out_control_transfer_withinp
.ftdi_set_event_char:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
jmp .ftdi_out_control_transfer_withinp
.ftdi_set_error_char:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
jmp .ftdi_out_control_transfer_withinp
.ftdi_setflowctrl:
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_FLOW_CTRL_REQUEST shl 8) + (0 shl 16)
mov ebx, [edi+4]
mov cx, word[edi+8]
or ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
xor cx, cx
mov word[ConfPacket+6], cx
jmp .own_index
.ftdi_read_pins:
mov ebx, [edi]
mov dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_READ_PINS_REQUEST shl 8) + (0 shl 16)
mov ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
mov word[ConfPacket+6], 1
lea esi, [ConfPacket]
lea edi, [EventData]
mov ecx, [ioctl]
mov ecx, [ecx+output]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, ecx, 1, control_callback, edi, 0
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
jmp .endswitch
.ftdi_set_wchunksize:
mov ebx, [edi+4]
mov ecx, [edi+8]
cmp [ebx + ftdi_context.maxPacketSize], ecx
jg .error
mov [ebx + ftdi_context.writeBufChunkSize], ecx
jmp .endswitch
.ftdi_get_wchunksize:
mov esi, [edi+output]
mov edi, [edi+input]
mov ebx, [edi+4]
mov ecx, [ebx + ftdi_context.writeBufChunkSize]
mov [esi], ecx
jmp .endswitch
.ftdi_set_rchunksize:
mov ebx, [edi+4]
mov ecx, [edi+8]
cmp [ebx + ftdi_context.maxPacketSize], ecx
jg .error
mov [ebx + ftdi_context.readBufChunkSize], ecx
jmp .endswitch
.ftdi_get_rchunksize:
mov esi, [edi+output]
mov edi, [edi+input]
mov ebx, [edi+4]
mov ecx, [ebx + ftdi_context.readBufChunkSize]
mov [esi], ecx
jmp .endswitch
.ftdi_write_data:
mov esi, edi
add esi, 12
mov ebx, [edi+4]
xor ecx, ecx ; ecx - offset
.write_loop:
mov edx, [edi+8] ; edx - write_size
sub edx, ecx
cmp edx, [ebx + ftdi_context.writeBufChunkSize]
jle .lessthanchunk_write
mov edx, [ebx + ftdi_context.writeBufChunkSize]
.lessthanchunk_write:
add esi, ecx
lea eax, [EventData]
push ecx ebx esi edi
stdcall USBNormalTransferAsync, [ebx + ftdi_context.inEP], esi, edx, bulk_callback, eax, 1
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
mov eax, [EventData]
mov ebx, [EventData+4]
call ClearEvent
pop edi esi ebx ecx
cmp [EventData+8], -1
jz .error
add ecx, [EventData+8]
cmp ecx, [edi+8]
jge .eventdestroy
jmp .write_loop
.ftdi_read_data:
mov edi, [ioctl]
mov esi, [edi+input]
mov edi, [edi+output]
mov ebx, [esi+4]
xor ecx, ecx
.read_loop:
mov edx, [esi+8]
cmp ecx, edx
jge .eventdestroy ;!!!
sub edx, ecx
cmp edx, [ebx + ftdi_context.readBufChunkSize]
jl .lessthanchunk_read
mov edx, [ebx + ftdi_context.readBufChunkSize]
.lessthanchunk_read:
lea eax, [EventData]
add edi, ecx
push esi edi ecx ebx
stdcall USBNormalTransferAsync, [ebx + ftdi_context.outEP], edi, edx, bulk_callback, eax, 1
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
mov eax, [EventData]
mov ebx, [EventData+4]
call ClearEvent
pop ebx ecx edi esi
cmp [EventData+8], -1
jz .error
add ecx, [EventData+8]
jmp .read_loop
.ftdi_poll_modem_status:
mov ebx, [edi+4]
mov dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_POLL_MODEM_STATUS_REQUEST shl 8) + (0 shl 16)
mov ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
mov word[ConfPacket+6], 1
lea esi, [ConfPacket]
lea edi, [EventData]
mov ecx, [ioctl]
mov ecx, [ecx+output]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, ecx, 2, control_callback, edi, 0
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
mov ax, word[ecx]
xchg ah, al
and ah, 0xFF
mov word[ecx], ax
jmp .endswitch
.ftdi_get_latency_timer:
mov ebx, [edi+4]
mov dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_GET_LATENCY_TIMER_REQUEST shl 8) + (0 shl 16)
mov ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
mov word[ConfPacket+6], 1
lea esi, [ConfPacket]
lea edi, [EventData]
mov ecx, [ioctl]
mov ecx, [ecx+output]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, ecx, 2, control_callback, edi, 0
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
jmp .endswitch
.ftdi_get_list:
call linkedlist_gethead
test eax, eax
jz .endswitch
mov edi, [edi+output]
push edi
add edi, 4
xor ecx, ecx
.nextdev:
inc ecx
cmp [eax + ftdi_context.lockPID], 0
jnz .dev_is_locked
mov dword[edi], 'NLKD'
jmp .nextfields
.dev_is_locked:
mov dword[edi], 'LCKD'
.nextfields:
mov bl, [eax + ftdi_context.chipType]
mov [edi+4], ebx
mov [edi+8], eax
add edi, 12
mov eax, [eax + ftdi_context.next_context]
test eax, eax
jnz .nextdev
pop edi
mov [edi], ecx
jmp .endswitch
.ftdi_lock:
DEBUGF 1, 'K : FTDI lock attempt\n'
mov esi, [edi+input]
mov ebx, [esi+4]
mov eax, [ebx + ftdi_context.lockPID]
test eax, eax
jnz .lockedby
DEBUGF 1, 'K : Lock success\n'
mov eax, [esi]
mov [ebx + ftdi_context.lockPID], eax
.lockedby:
mov edi, [edi+output]
mov [edi], eax
jmp .endswitch
.ftdi_unlock:
mov esi, [edi+input]
mov edi, [edi+output]
mov ebx, [esi+4]
mov eax, [ebx + ftdi_context.lockPID]
cmp eax, [esi]
jnz .unlockimp
mov [ebx + ftdi_context.lockPID], 0
mov dword[edi], 0
jmp .endswitch
.unlockimp:
mov [edi], eax
jmp .endswitch
H_CLK = 120000000 H_CLK = 120000000
C_CLK = 48000000 C_CLK = 48000000
.ftdi_set_baudrate: .ftdi_set_baudrate:
mov edi, [edi+input] mov ebx, [edi+4]
mov ebx, [edi]
cmp [ebx + ftdi_context.chipType], TYPE_2232H cmp [ebx + ftdi_context.chipType], TYPE_2232H
jl .c_clk jl .c_clk
imul eax, [edi+8], 10 imul eax, [edi+8], 10
@ -548,213 +813,6 @@ C_CLK = 48000000
mov word[ConfPacket+6], 0 mov word[ConfPacket+6], 0
jmp .own_index jmp .own_index
.ftdi_set_line_property:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
mov edi, [edi+input]
mov dx, word[edi+8]
mov word[ConfPacket+2], dx
jmp .ftdi_out_control_transfer
.ftdi_set_latency_timer:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)
mov edi, [edi+input]
mov dx, word[edi+8]
mov word[ConfPacket+2], dx
jmp .ftdi_out_control_transfer
.ftdi_set_event_char:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
mov edi, [edi+input]
mov dx, word[edi+8]
mov word[ConfPacket+2], dx
jmp .ftdi_out_control_transfer
.ftdi_set_error_char:
mov word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
mov edi, [edi+input]
mov dx, word[edi+8]
mov word[ConfPacket+2], dx
jmp .ftdi_out_control_transfer
.ftdi_setflowctrl:
mov dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_FLOW_CTRL_REQUEST shl 8) + (0 shl 16)
mov edi, [edi+input]
mov ebx, [edi]
mov cx, word[edi+8]
or ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
xor cx, cx
mov word[ConfPacket+6], cx
jmp .own_index
.ftdi_read_pins:
DEBUGF 1,'K : FTDI Reading pins\n'
mov edi, [edi+input]
mov ebx, [edi]
mov dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_READ_PINS_REQUEST shl 8) + (0 shl 16)
mov ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
mov word[ConfPacket+6], 1
lea esi, [ConfPacket]
lea edi, [EventData]
mov ecx, [ioctl]
mov ecx, [ecx+output]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, ecx, 1, control_callback, edi, 0
DEBUGF 1, 'K : Returned value is %d\n', eax
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
jmp .endswitch
.ftdi_write_data:
mov edi, [edi+input]
mov ebx, [edi+4]
xor ecx, ecx ; ecx - offset
.dataleft:
mov edx, [ebx + ftdi_context.writeBufChunkSize] ; edx - write_size
push ecx
add ecx, edx
cmp ecx, [edi+8] ; [edi+8] - size
pop ecx
jle .morethanchunk_write
mov edx, [edi+8]
sub edx, ecx
.morethanchunk_write:
lea eax, [EventData]
stdcall USBNormalTransferAsync, [ebx + ftdi_context.inEP], [edi+12+ecx], edx, bulk_callback, eax, 1
push ebx edi edx ecx
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
pop ecx edx edi ebx
cmp [EventData+8], -1
jz .endswitch;jz .error
add ecx, [EventData+8]
cmp ecx, [edi+8]
jl .dataleft
jmp .endswitch
.ftdi_read_data:
mov esi, [edi+input]
mov edi, [edi+output]
mov ebx, [esi+4]
xor ecx, ecx
.read_loop:
mov edx, [esi+8]
sub edx, ecx
test edx, edx
jz .endswitch
cmp edx, [ebx + ftdi_context.readBufChunkSize]
jl .lessthanchunk_read
mov edx, [ebx + ftdi_context.readBufChunkSize]
.lessthanchunk_read:
lea eax, [EventData]
stdcall USBNormalTransferAsync, [ebx + ftdi_context.outEP], [edi+ecx], edx, bulk_callback, eax, 1
push esi edi ecx ebx
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
pop ebx ecx edi esi
cmp [EventData+8], -1
jz .endswitch;jz .error
add ecx, [EventData+8]
jmp .read_loop
.ftdi_poll_modem_status:
mov edi, [edi+input]
mov ebx, [edi+4]
mov dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_POLL_MODEM_STATUS_REQUEST shl 8) + (0 shl 16)
mov ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
mov word[ConfPacket+6], 1
lea esi, [ConfPacket]
lea edi, [EventData]
mov ecx, [ioctl]
mov ecx, [ecx+output]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, ecx, 2, control_callback, edi, 0
DEBUGF 1, 'K : Returned value is %d\n', eax
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
mov ax, word[ecx]
xchg ah, al
and ah, 0xFF
mov word[ecx], ax
jmp .endswitch
.ftdi_get_latency_timer:
mov edi, [edi+input]
mov ebx, [edi+4]
mov dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_GET_LATENCY_TIMER_REQUEST shl 8) + (0 shl 16)
mov ecx, [ebx + ftdi_context.index]
mov word[ConfPacket+4], cx
mov word[ConfPacket+6], 1
lea esi, [ConfPacket]
lea edi, [EventData]
mov ecx, [ioctl]
mov ecx, [ecx+output]
stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, ecx, 2, control_callback, edi, 0
DEBUGF 1, 'K : Returned value is %d\n', eax
mov eax, [EventData]
mov ebx, [EventData+4]
call WaitEvent
jmp .endswitch
.ftdi_get_list:
call linkedlist_gethead
mov edi, [edi+output]
push edi
add edi, 4
xor ecx, ecx
.nextdev:
inc ecx
cmp [eax + ftdi_context.lockPID], 0
jnz .dev_is_locked
mov dword[edi], 'NLKD'
jmp .nextfields
.dev_is_locked:
mov dword[edi], 'LCKD'
.nextfields:
mov bl, [eax + ftdi_context.chipType]
mov [edi+4], ebx
mov [edi+8], eax
add edi, 12
mov eax, [eax + ftdi_context.next_context]
test eax, eax
jnz .nextdev
pop edi
mov [edi], ecx
jmp .endswitch
.ftdi_lock:
DEBUGF 1, 'K : FTDI lock attempt\n'
mov esi, [edi+input]
mov ebx, [esi+4]
mov eax, [ebx + ftdi_context.lockPID]
test eax, eax
jnz .lockedby
DEBUGF 1, 'K : Lock success\n'
mov eax, [esi]
mov [ebx + ftdi_context.lockPID], eax
.lockedby:
mov edi, [edi+output]
mov [edi], eax
jmp .endswitch
.ftdi_unlock:
mov esi, [edi+input]
mov edi, [edi+output]
mov ebx, [esi+4]
mov eax, [ebx + ftdi_context.lockPID]
cmp eax, [esi]
jnz .unlockimp
mov [ebx + ftdi_context.lockPID], 0
mov dword[edi], 0
jmp .endswitch
.unlockimp:
mov [edi], eax
jmp .endswitch
endp endp
restore handle restore handle
restore io_code restore io_code
@ -786,10 +844,10 @@ proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer
mov eax, [ecx] mov eax, [ecx]
mov ebx, [ecx+4] mov ebx, [ecx+4]
cmp [.status], 0 cmp [.status], 0
jg .error? jz .normal
.error?:
cmp [.status], 9 cmp [.status], 9
jne .error jne .error
.normal:
mov edx, [.length] mov edx, [.length]
mov [ecx+8], edx mov [ecx+8], edx
jmp .ok jmp .ok
@ -798,7 +856,6 @@ proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer
.ok: .ok:
xor esi, esi xor esi, esi
xor edx, edx xor edx, edx
;mov edx, 0x80000000
call RaiseEvent call RaiseEvent
ret ret
endp endp