Kernel - Added serial port 'driver' (wraps PTY)
authorJohn Hodge <[email protected]>
Sun, 22 Sep 2013 11:05:36 +0000 (19:05 +0800)
committerJohn Hodge <[email protected]>
Sun, 22 Sep 2013 11:05:36 +0000 (19:05 +0800)
KernelLand/Kernel/Makefile
KernelLand/Kernel/drv/serial.c [new file with mode: 0644]
KernelLand/Kernel/include/drv_serial.h [new file with mode: 0644]

index 0aa55ab..b05d01a 100644 (file)
@@ -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 (file)
index 0000000..7a4192c
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Acess2 Kernel
+ * - By John Hodge (thePowersGang)
+ *
+ * drv/serial.c
+ * - Common serial port code
+ */
+#include <acess.h>
+#include <modules.h>
+#include <fs_devfs.h>
+#include <drv_serial.h>
+#include <drv_pty.h>
+
+// === 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 (file)
index 0000000..6d6088f
--- /dev/null
@@ -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
+

UCC git Repository :: git.ucc.asn.au