Added ftdi_read_data. Small bug fixes

git-svn-id: svn://kolibrios.org@5014 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
gtament 2014-08-01 08:16:45 +00:00
parent ce330875f5
commit 3f20695fd0

View File

@ -122,8 +122,6 @@ struct ftdi_context
chipType db ? chipType db ?
baudrate dd ? baudrate dd ?
bitbangEnabled db ? bitbangEnabled db ?
readBufPtr dd ?
readBufOffs dd ?
readBufChunkSize dd ? readBufChunkSize dd ?
writeBufChunkSize dd ? writeBufChunkSize dd ?
interface dd ? interface dd ?
@ -206,6 +204,8 @@ 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.readBufChunkSize], 64
mov [eax + ftdi_context.writeBufChunkSize], 64
cmp [edx+usb_descr.bcdDevice], 0x400 cmp [edx+usb_descr.bcdDevice], 0x400
jnz @f jnz @f
@ -243,6 +243,8 @@ proc AddDevice stdcall uses ebx esi, .config_pipe:DWORD, .config_descr:DWORD, .i
DEBUGF 1,'K : Open second pipe\n' DEBUGF 1,'K : Open second pipe\n'
stdcall USBOpenPipe, [.config_pipe], 0x02, 0x40, BULK_PIPE, 0 stdcall USBOpenPipe, [.config_pipe], 0x02, 0x40, BULK_PIPE, 0
mov [ebx + ftdi_context.outEP], eax mov [ebx + ftdi_context.outEP], eax
mov eax, ebx
ret
.notftdi: .notftdi:
DEBUGF 1,'K : Skipping not FTDI device\n' DEBUGF 1,'K : Skipping not FTDI device\n'
@ -263,7 +265,7 @@ align 4
proc service_proc stdcall uses ebx esi edi, ioctl:DWORD proc service_proc stdcall uses ebx esi edi, ioctl:DWORD
locals locals
ConfPacket rb 8 ConfPacket rb 8
EventData rd 2 EventData rd 3
endl endl
mov edi, [ioctl] mov edi, [ioctl]
mov eax, [edi+io_code] mov eax, [edi+io_code]
@ -296,7 +298,13 @@ endl
.pid_ok: .pid_ok:
push eax edi push eax edi
mov ecx, 0x80000000
cmp eax, 17
je .bulkevent
cmp eax, 18
je .bulkevent
xor ecx, ecx xor ecx, ecx
.bulkevent:
xor esi, esi xor esi, esi
call CreateEvent call CreateEvent
mov [EventData], eax mov [EventData], eax
@ -309,35 +317,37 @@ endl
jz .ftdi_setrtshigh jz .ftdi_setrtshigh
dec eax ;6 dec eax ;6
jz .ftdi_setrtslow jz .ftdi_setrtslow
dec eax dec eax ;7
jz .ftdi_setdtrhigh jz .ftdi_setdtrhigh
dec eax dec eax ;8
jz .ftdi_setdtrlow jz .ftdi_setdtrlow
dec eax dec eax ;9
jz .ftdi_usb_reset jz .ftdi_usb_reset
dec eax dec eax ;10
jz .ftdi_setflowctrl jz .ftdi_setflowctrl
dec eax dec eax ;11
jz .ftdi_set_event_char jz .ftdi_set_event_char
dec eax dec eax ;12
jz .ftdi_set_error_char jz .ftdi_set_error_char
dec eax dec eax ;13
jz .ftdi_set_latency_timer jz .ftdi_set_latency_timer
dec eax dec eax ;14
jz .ftdi_get_latency_timer jz .ftdi_get_latency_timer
dec eax dec eax ;15
jz .ftdi_read_pins jz .ftdi_read_pins
dec eax dec eax ;16
jz .ftdi_poll_modem_status jz .ftdi_poll_modem_status
dec eax dec eax ;17
jz .ftdi_write_data jz .ftdi_write_data
dec eax dec eax ;18
jz .ftdi_read_data
dec eax ;19
jz .ftdi_set_baudrate jz .ftdi_set_baudrate
dec eax dec eax ;20
jz .ftdi_set_line_property jz .ftdi_set_line_property
dec eax dec eax ;21
jz .ftdi_purge_rx_buf jz .ftdi_purge_rx_buf
dec eax dec eax ;22
jz .ftdi_purge_tx_buf jz .ftdi_purge_tx_buf
.version: .version:
@ -599,27 +609,57 @@ C_CLK = 48000000
.ftdi_write_data: .ftdi_write_data:
mov edi, [edi+input] mov edi, [edi+input]
mov ebx, [edi+4] mov ebx, [edi+4]
mov eax, [edi+8]
xor ecx, ecx ; ecx - offset xor ecx, ecx ; ecx - offset
.dataleft: .dataleft:
mov edx, [ebx + ftdi_context.writeBufChunkSize] ; edx - write_size mov edx, [ebx + ftdi_context.writeBufChunkSize] ; edx - write_size
push ecx push ecx
add ecx, edx add ecx, edx
cmp ecx, [edi+8] cmp ecx, [edi+8] ; [edi+8] - size
pop ecx pop ecx
jle .morethanchunk jle .morethanchunk_write
mov edx, [edi+8] mov edx, [edi+8]
sub edx, ecx sub edx, ecx
.morethanchunk: .morethanchunk_write:
stdcall USBNormalTransferAsync, [ebx + ftdi_context.inEP], [edi+12+ecx], edx, bulk_callback, edx, 1 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 eax, [EventData]
mov ebx, [EventData+4] mov ebx, [EventData+4]
call WaitEvent call WaitEvent
add ecx, [EventData] pop ecx edx edi ebx
cmp [EventData+8], -1
jz .endswitch;jz .error
add ecx, [EventData+8]
cmp ecx, [edi+8] cmp ecx, [edi+8]
jl .dataleft jl .dataleft
jmp .endswitch 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: .ftdi_poll_modem_status:
mov edi, [edi+input] mov edi, [edi+input]
mov ebx, [edi+4] mov ebx, [edi+4]
@ -663,7 +703,11 @@ C_CLK = 48000000
.ftdi_get_list: .ftdi_get_list:
call linkedlist_gethead call linkedlist_gethead
mov edi, [edi+output] mov edi, [edi+output]
push edi
add edi, 4
xor ecx, ecx
.nextdev: .nextdev:
inc ecx
cmp [eax + ftdi_context.lockPID], 0 cmp [eax + ftdi_context.lockPID], 0
jnz .dev_is_locked jnz .dev_is_locked
mov dword[edi], 'NLKD' mov dword[edi], 'NLKD'
@ -678,14 +722,18 @@ C_CLK = 48000000
mov eax, [eax + ftdi_context.next_context] mov eax, [eax + ftdi_context.next_context]
test eax, eax test eax, eax
jnz .nextdev jnz .nextdev
pop edi
mov [edi], ecx
jmp .endswitch jmp .endswitch
.ftdi_lock: .ftdi_lock:
DEBUGF 1, 'K : FTDI lock attempt\n'
mov esi, [edi+input] mov esi, [edi+input]
mov ebx, [esi+4] mov ebx, [esi+4]
mov eax, [ebx + ftdi_context.lockPID] mov eax, [ebx + ftdi_context.lockPID]
test eax, eax test eax, eax
jnz .lockedby jnz .lockedby
DEBUGF 1, 'K : Lock success\n'
mov eax, [esi] mov eax, [esi]
mov [ebx + ftdi_context.lockPID], eax mov [ebx + ftdi_context.lockPID], eax
.lockedby: .lockedby:
@ -723,10 +771,11 @@ proc control_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buf
mov ecx, [.calldata] mov ecx, [.calldata]
mov eax, [ecx] mov eax, [ecx]
mov ebx, [ecx+4] mov ebx, [ecx+4]
mov edx, [.status]
mov [ecx+8], edx
xor esi, esi xor esi, esi
xor edx, edx xor edx, edx
call RaiseEvent call RaiseEvent
ret ret
endp endp
@ -736,20 +785,27 @@ proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer
mov ecx, [.calldata] mov ecx, [.calldata]
mov eax, [ecx] mov eax, [ecx]
mov ebx, [ecx+4] mov ebx, [ecx+4]
cmp [.status], 0
jg .error?
.error?:
cmp [.status], 9
jne .error
mov edx, [.length] mov edx, [.length]
mov edx, [edx] mov [ecx+8], edx
mov [ecx], edx jmp .ok
.error:
mov [ecx+8], dword -1
.ok:
xor esi, esi xor esi, esi
xor edx, edx xor edx, edx
;mov edx, 0x80000000
call RaiseEvent call RaiseEvent
ret ret
endp endp
proc DeviceDisconnected stdcall uses ebx esi edi, .device_data:DWORD proc DeviceDisconnected stdcall uses ebx esi edi, .device_data:DWORD
DEBUGF 1, 'K : FTDI deleting device data\n' DEBUGF 1, 'K : FTDI deleting device data %x\n', [.device_data]
mov eax, [.device_data] mov eax, [.device_data]
call linkedlist_delete call linkedlist_delete
ret ret