Implement serial reconf
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 26s
Build system / Build (pull_request) Successful in 4m31s

This commit is contained in:
2025-05-22 21:26:05 +05:00
parent 7e63294b5e
commit 2dfb3ddff3
4 changed files with 124 additions and 34 deletions

View File

@@ -1,3 +1,5 @@
SERIAL_COMPATIBLE_API_VER = 0 ; increments in case of breaking changes
SERIAL_API_GET_VERSION = 0
SERIAL_API_SRV_ADD_PORT = 1
SERIAL_API_SRV_REMOVE_PORT = 2
@@ -21,14 +23,18 @@ SERIAL_CONF_PARITY_ODD = 2
SERIAL_CONF_PARITY_MARK = 3
SERIAL_CONF_PARITY_SPACE = 4
SERIAL_CONF_STOP_BITS_1 = 0
SERIAL_CONF_STOP_BITS_1_5 = 1
SERIAL_CONF_STOP_BITS_2 = 2
SERIAL_CONF_FLOW_CTRL_NONE = 0
struct SP_DRIVER
size dd ? ; size of this struct
startup dd ? ; void __stdcall (*startup)(void *drv_data, const struct serial_conf *conf);
shutdown dd ? ; void __stdcall (*shutdown)(void *drv_data);
reconf dd ? ; void __stdcall (*reconf)(void *drv_data, const struct serial_conf *conf);
tx dd ? ; void __stdcall (*tx)(void *drv_data);
startup dd ? ; int __stdcall (*startup)(void *drv_data, const struct serial_conf *conf);
shutdown dd ? ; int __stdcall (*shutdown)(void *drv_data);
reconf dd ? ; int __stdcall (*reconf)(void *drv_data, const struct serial_conf *conf);
tx dd ? ; int __stdcall (*tx)(void *drv_data);
ends
struct SP_CONF
@@ -123,6 +129,30 @@ proc serial_port_init
ret
endp
proc serial_port_get_version stdcall, version:dword
locals
.handler dd ?
.io_code dd ?
.input dd ?
.inp_size dd ?
.output dd ?
.out_size dd ?
endl
mov eax, [serial_drv_handle]
mov [.handler], eax
mov dword [.io_code], SERIAL_API_GET_VERSION
mov [.input], 0
mov dword [.inp_size], 0
mov eax, [version]
mov [.output], eax
mov dword [.out_size], 4
lea ecx, [.handler]
mcall SF_SYS_MISC, SSF_CONTROL_DRIVER
ret
endp
proc serial_port_open stdcall uses ebx, port_id:dword, conf:dword, handle:dword
locals
.handler dd ?

View File

@@ -9,8 +9,6 @@ __DEBUG_LEVEL__ = L_DBG
SERIAL_RING_BUF_SIZE = 32768
API_VERSION = 1
section '.flat' readable writable executable
include '../struct.inc'
@@ -23,6 +21,9 @@ include 'common.inc'
include 'ring_buf.inc'
include 'uart16550.inc'
CURRENT_API = 0x0001
API_VERSION = (SERIAL_COMPATIBLE_API_VER shl 16) + CURRENT_API
struct SERIAL_OBJ
magic dd ?
destroy dd ?
@@ -45,7 +46,7 @@ struct SERIAL_PORT
conf SP_CONF
ends
proc START c, reason:dword
proc START c, reason:dword, cmdline:dword
cmp [reason], DRV_ENTRY
jne .fail
@@ -347,15 +348,12 @@ proc sp_validate_conf
mov eax, [ecx + SP_CONF.baudrate]
test eax, eax
jz .fail
mov al, [ecx + SP_CONF.word_size]
cmp al, 8
jne .fail ; TODO implement different word size
mov al, [ecx + SP_CONF.stop_bits]
cmp al, 1
jne .fail ; TODO implement different stop bits count
cmp al, SERIAL_CONF_STOP_BITS_2
ja .fail
mov al, [ecx + SP_CONF.parity]
cmp al, SERIAL_CONF_PARITY_NONE
jne .fail ; TODO implement parity
cmp al, SERIAL_CONF_PARITY_SPACE
ja .fail
mov al, [ecx + SP_CONF.flow_ctrl]
cmp al, SERIAL_CONF_FLOW_CTRL_NONE
jne .fail ; TODO implement flow control
@@ -550,7 +548,6 @@ proc sp_setup
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

View File

@@ -350,10 +350,10 @@ endl
; calc stop bits
mov bx, LCR_STOP_1
mov al, [esi + SP_CONF.stop_bits]
cmp al, 1
cmp al, SERIAL_CONF_STOP_BITS_1
je .stop_bits_ok
or bx, LCR_STOP_2
cmp al, 2
cmp al, SERIAL_CONF_STOP_BITS_2
jne .fail
.stop_bits_ok:
or [lcr], bx