From: John Hodge Date: Sun, 22 Sep 2013 11:05:36 +0000 (+0800) Subject: Kernel - Added serial port 'driver' (wraps PTY) X-Git-Tag: rel0.15~199 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2837fec02aeec9ae4641872dab61fe73e37e75fe;p=tpg%2Facess2.git Kernel - Added serial port 'driver' (wraps PTY) --- diff --git a/KernelLand/Kernel/Makefile b/KernelLand/Kernel/Makefile index 0aa55aba..b05d01a2 100644 --- a/KernelLand/Kernel/Makefile +++ b/KernelLand/Kernel/Makefile @@ -61,7 +61,7 @@ OBJ += threads.o mutex.o semaphore.o workqueue.o events.o rwlock.o OBJ += drv/zero-one.o drv/proc.o drv/fifo.o drv/dgram_pipe.o drv/iocache.o drv/pci.o drv/vpci.o OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_vt100.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o OBJ += drv/vterm_2d.o -OBJ += drv/pty.o +OBJ += drv/pty.o drv/serial.o OBJ += binary.o bin/elf.o bin/pe.o OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o OBJ += vfs/memfile.o vfs/nodecache.o vfs/handle.o vfs/select.o vfs/mmap.o diff --git a/KernelLand/Kernel/drv/serial.c b/KernelLand/Kernel/drv/serial.c new file mode 100644 index 00000000..7a4192c4 --- /dev/null +++ b/KernelLand/Kernel/drv/serial.c @@ -0,0 +1,90 @@ +/* + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * drv/serial.c + * - Common serial port code + */ +#include +#include +#include +#include +#include + +// === TYPES === +struct sSerialPort +{ + tPTY *PTY; + tSerial_OutFcn OutputFcn; + void *OutHandle; +}; + +// === PROTOTYPES === + int Serial_Install(char **Arguments); +//tSerialPort *Serial_CreatePort( tSerial_OutFcn output, void *handle ); +//void Serial_ByteReceived(tSerialPort *Port, char Ch); +void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer); + int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode); + int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims); +void Serial_int_OutputDebug(void *unused, char ch); + +// === GLOBALS === +MODULE_DEFINE(0, 0x100, Serial, Serial_Install, NULL, "PTY", NULL); +tSerialPort *gSerial_KernelDebugPort; + +// === CODE === +int Serial_Install(char **Arguments) +{ + gSerial_KernelDebugPort = Serial_CreatePort( Serial_int_OutputDebug, NULL ); + return 0; +} + +tSerialPort *Serial_CreatePort(tSerial_OutFcn output, void *handle) +{ + tSerialPort *ret = malloc( sizeof(tSerialPort) ); + // TODO: Make PTY code handle 'serial#' and auto-number + ret->PTY = PTY_Create("serial0", ret, Serial_int_PTYOutput, Serial_int_PTYSetDims, Serial_int_PTYSetArrib); + ret->OutputFcn = output; + ret->OutHandle = handle; + struct ptymode mode = { + .OutputMode = PTYBUFFMT_TEXT, + .InputMode = PTYIMODE_CANON|PTYIMODE_ECHO + }; + struct ptydims dims = { + .W = 80, .H = 25, + .PW = 0, .PH = 0 + }; + PTY_SetAttrib(ret->PTY, &dims, &mode, 0); + return ret; +} + +void Serial_ByteReceived(tSerialPort *Port, char Ch) +{ + if( !Port ) + return ; + if( Ch == '\r' ) + Ch = '\n'; + PTY_SendInput(Port->PTY, &Ch, 1); +} + +void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer) +{ + tSerialPort *Port = Handle; + const char *buf = Buffer; + for( int i = 0; i < Length; i ++ ) + Port->OutputFcn( Port->OutHandle, *buf++ ); +} +int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode) +{ + return 0; +} +int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims) +{ + return 0; +} + +void Serial_int_OutputDebug(void *unused, char ch) +{ + Debug_PutCharDebug(ch); +} + diff --git a/KernelLand/Kernel/include/drv_serial.h b/KernelLand/Kernel/include/drv_serial.h new file mode 100644 index 00000000..6d6088f0 --- /dev/null +++ b/KernelLand/Kernel/include/drv_serial.h @@ -0,0 +1,20 @@ +/* + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * drv/serial.c + * - Common serial port code + */ +#ifndef _DRV_SERIAL_H_ +#define _DRV_SERIAL_H_ + +typedef void (*tSerial_OutFcn)(void *Handle, char Ch); +typedef struct sSerialPort tSerialPort; + +extern tSerialPort *gSerial_KernelDebugPort; + +extern tSerialPort *Serial_CreatePort( tSerial_OutFcn output, void *handle ); +extern void Serial_ByteReceived(tSerialPort *Port, char Ch); + +#endif +