forked from KolibriOS/kolibrios
Add func to change port settings
This commit is contained in:
parent
e0fc16dd5a
commit
5a1bfc3f9b
@ -185,6 +185,36 @@ endl
|
||||
ret
|
||||
endp
|
||||
|
||||
proc serial_port_setup stdcall uses ebx, handle:dword, conf:dword
|
||||
locals
|
||||
.handler dd ?
|
||||
.io_code dd ?
|
||||
.input dd ?
|
||||
.inp_size dd ?
|
||||
.output dd ?
|
||||
.out_size dd ?
|
||||
endl
|
||||
push [conf]
|
||||
push [handle]
|
||||
mov eax, [serial_drv_handle]
|
||||
mov [.handler], eax
|
||||
mov dword [.io_code], SERIAL_API_SETUP_PORT
|
||||
mov [.input], esp
|
||||
mov dword [.inp_size], 8
|
||||
sub esp, 4
|
||||
mov [.output], esp
|
||||
mov dword [.out_size], 4
|
||||
|
||||
mov eax, SF_SYS_MISC
|
||||
mov ebx, SSF_CONTROL_DRIVER
|
||||
lea ecx, [.handler]
|
||||
int 0x40
|
||||
|
||||
pop eax
|
||||
add esp, 8
|
||||
ret
|
||||
endp
|
||||
|
||||
proc serial_port_read stdcall uses ebx, handle:dword, dest:dword, count_ptr:dword
|
||||
locals
|
||||
.handler dd ?
|
||||
|
@ -71,9 +71,10 @@ srv_calls:
|
||||
dd service_proc.drv_handle_event
|
||||
dd service_proc.open
|
||||
dd service_proc.close
|
||||
dd 0 ; service_proc.setup
|
||||
dd service_proc.setup
|
||||
dd service_proc.read
|
||||
dd service_proc.write
|
||||
; TODO enumeration
|
||||
srv_calls_end:
|
||||
|
||||
proc service_proc stdcall uses ebx esi edi, ioctl:dword
|
||||
@ -141,8 +142,6 @@ proc service_proc stdcall uses ebx esi edi, ioctl:dword
|
||||
jb .err
|
||||
mov ebx, [edx + IOCTL.input]
|
||||
mov ecx, [edx + IOCTL.output]
|
||||
DEBUGF L_DBG, "serial.sys: input %x, output %x\n", ebx, ecx
|
||||
DEBUGF L_DBG, "serial.sys: port_id %x, port_conf %x\n", [ebx], [ebx + 4]
|
||||
stdcall sp_open, [ebx], [ebx + 4], ecx
|
||||
ret
|
||||
|
||||
@ -156,6 +155,26 @@ proc service_proc stdcall uses ebx esi edi, ioctl:dword
|
||||
call sp_close
|
||||
ret
|
||||
|
||||
.setup:
|
||||
; in:
|
||||
; +0 port handle
|
||||
; +4 addr to SERIAL_CONF
|
||||
; out:
|
||||
; +0 result
|
||||
cmp [edx + IOCTL.inp_size], 8
|
||||
jb .err
|
||||
cmp [edx + IOCTL.out_size], 4
|
||||
jb .err
|
||||
mov ebx, [edx + IOCTL.input]
|
||||
push edx
|
||||
mov eax, [ebx]
|
||||
mov esi, [ebx + 4]
|
||||
call sp_setup
|
||||
pop edx
|
||||
mov ebx, [edx + IOCTL.output]
|
||||
mov [ebx], eax
|
||||
ret
|
||||
|
||||
.read:
|
||||
; in:
|
||||
; +0 port handle
|
||||
@ -208,7 +227,7 @@ endp
|
||||
; struct SERIAL_PORT __fastcall *add_port(const struct SP_DRIVER *drv, const void *drv_data);
|
||||
align 4
|
||||
proc add_port uses edi
|
||||
DEBUGF L_DBG, "serial.sys: add port driver %x data %x\n", ecx, edx
|
||||
DEBUGF L_DBG, "serial.sys: add port drv=%x drv_data=%x\n", ecx, edx
|
||||
|
||||
mov eax, [ecx + SP_DRIVER.size]
|
||||
cmp eax, sizeof.SP_DRIVER
|
||||
@ -499,11 +518,58 @@ proc sp_close uses ebx esi
|
||||
lea ecx, [ebx + SERIAL_PORT.mtx]
|
||||
invoke MutexUnlock
|
||||
|
||||
DEBUGF L_DBG, "serial.sys: sp_close ok, return\n"
|
||||
xor eax, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
; @param eax port handle
|
||||
; @param esi pointer to SP_CONF
|
||||
; @return eax = 0 on success
|
||||
proc sp_setup
|
||||
test esi, esi
|
||||
jz .fail
|
||||
cmp [eax + SERIAL_OBJ.magic], 'UART'
|
||||
jne .fail
|
||||
mov ebx, eax
|
||||
mov ecx, esi
|
||||
call sp_validate_conf
|
||||
test eax, eax
|
||||
jz @f
|
||||
DEBUGF L_DBG, "serial.sys: invalid conf %x\n", ecx
|
||||
mov eax, SERIAL_API_ERR_CONF
|
||||
ret
|
||||
@@:
|
||||
; lock mutex
|
||||
mov edi, [ebx + SERIAL_OBJ.port]
|
||||
lea ecx, [edi + SERIAL_PORT.mtx]
|
||||
invoke MutexLock
|
||||
; reconfigure port
|
||||
mov eax, [edi + SERIAL_PORT.drv]
|
||||
mov ecx, [edi + SERIAL_PORT.drv_data]
|
||||
stdcall dword [eax + SP_DRIVER.reconf], ecx, esi
|
||||
xor eax, eax
|
||||
push eax
|
||||
test eax, eax
|
||||
jnz @f
|
||||
; copy conf if success
|
||||
mov eax, [esi + SP_CONF.size]
|
||||
mov [edi + SERIAL_PORT.conf + SP_CONF.size], eax
|
||||
mov eax, [esi + SP_CONF.baudrate]
|
||||
mov [edi + SERIAL_PORT.conf + SP_CONF.baudrate], eax
|
||||
mov eax, dword [esi + SP_CONF.word_size]
|
||||
mov dword [edi + SERIAL_PORT.conf + SP_CONF.word_size], eax
|
||||
@@:
|
||||
; unlock mutex
|
||||
lea ecx, [edi + SERIAL_PORT.mtx]
|
||||
invoke MutexUnlock
|
||||
pop eax
|
||||
ret
|
||||
.fail:
|
||||
or eax, -1
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
; @param eax serial obj
|
||||
proc sp_destroy
|
||||
|
@ -1123,10 +1123,11 @@ proc uart_shutdown stdcall uses ebx, data:dword
|
||||
ret
|
||||
endp
|
||||
|
||||
proc uart_reconf stdcall uses ebx esi, data:dword, conf:dword
|
||||
mov ebx, [data]
|
||||
proc uart_reconf stdcall uses ebx esi, dev:dword, conf:dword
|
||||
mov ebx, [dev]
|
||||
mov esi, [conf]
|
||||
stdcall ftdi_set_baudrate, ebx, [esi + SP_CONF.baudrate]
|
||||
; TODO set word_size, parity, etc.
|
||||
ret
|
||||
endp
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user