3 * - By John Hodge (thePowersGang)
6 * - Common serial port code
11 #include <drv_serial.h>
13 #include <debug_hooks.h>
19 tSerial_OutFcn OutputFcn;
24 int Serial_Install(char **Arguments);
25 //tSerialPort *Serial_CreatePort( tSerial_OutFcn output, void *handle );
26 //void Serial_ByteReceived(tSerialPort *Port, char Ch);
27 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer);
28 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode);
29 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims);
30 void Serial_int_OutputDebug(void *unused, char ch);
33 MODULE_DEFINE(0, 0x100, Serial, Serial_Install, NULL, "PTY", NULL);
34 tSerialPort *gSerial_KernelDebugPort;
37 int Serial_Install(char **Arguments)
39 gSerial_KernelDebugPort = Serial_CreatePort( Serial_int_OutputDebug, NULL );
43 tSerialPort *Serial_CreatePort(tSerial_OutFcn output, void *handle)
45 tSerialPort *ret = malloc( sizeof(tSerialPort) );
46 // Automatically indexed
47 struct ptydims dims = {
51 struct ptymode mode = {
52 .OutputMode = PTYBUFFMT_TEXT,
53 .InputMode = PTYIMODE_CANON|PTYIMODE_ECHO
55 ret->PTY = PTY_Create("serial#", ret,
56 Serial_int_PTYOutput, Serial_int_PTYSetDims, Serial_int_PTYSetArrib,
59 ret->OutputFcn = output;
60 ret->OutHandle = handle;
64 void Serial_ByteReceived(tSerialPort *Port, char Ch)
68 if( Port == gSerial_KernelDebugPort )
70 static int serial_debug_mode = 0;
71 // Kernel serial debug hooks.
72 if( serial_debug_mode )
83 PTY_SendInput(Port->PTY, &Ch, 1);
86 serial_debug_mode = 0;
89 else if( Ch == 'X'-'A'+1 )
91 serial_debug_mode = 1;
101 PTY_SendInput(Port->PTY, &Ch, 1);
104 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer)
106 tSerialPort *Port = Handle;
107 const char *buf = Buffer;
108 for( int i = 0; i < Length; i ++ )
109 Port->OutputFcn( Port->OutHandle, *buf++ );
111 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode)
115 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims)
120 void Serial_int_OutputDebug(void *unused, char ch)
122 Debug_PutCharDebug(ch);