3 * - By John Hodge (thePowersGang)
6 * - Common serial port code
11 #include <drv_serial.h>
18 tSerial_OutFcn OutputFcn;
23 int Serial_Install(char **Arguments);
24 //tSerialPort *Serial_CreatePort( tSerial_OutFcn output, void *handle );
25 //void Serial_ByteReceived(tSerialPort *Port, char Ch);
26 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer);
27 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode);
28 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims);
29 void Serial_int_OutputDebug(void *unused, char ch);
32 MODULE_DEFINE(0, 0x100, Serial, Serial_Install, NULL, "PTY", NULL);
33 tSerialPort *gSerial_KernelDebugPort;
36 int Serial_Install(char **Arguments)
38 gSerial_KernelDebugPort = Serial_CreatePort( Serial_int_OutputDebug, NULL );
42 tSerialPort *Serial_CreatePort(tSerial_OutFcn output, void *handle)
44 tSerialPort *ret = malloc( sizeof(tSerialPort) );
45 // Automatically indexed
46 ret->PTY = PTY_Create("serial#", ret, Serial_int_PTYOutput, Serial_int_PTYSetDims, Serial_int_PTYSetArrib);
47 ret->OutputFcn = output;
48 ret->OutHandle = handle;
49 struct ptymode mode = {
50 .OutputMode = PTYBUFFMT_TEXT,
51 .InputMode = PTYIMODE_CANON|PTYIMODE_ECHO
53 struct ptydims dims = {
57 PTY_SetAttrib(ret->PTY, &dims, &mode, 0);
61 void Serial_ByteReceived(tSerialPort *Port, char Ch)
65 if( Port == gSerial_KernelDebugPort )
67 static int serial_debug_mode = 0;
68 // Kernel serial debug hooks.
69 if( serial_debug_mode )
80 PTY_SendInput(Port->PTY, &Ch, 1);
83 serial_debug_mode = 0;
86 else if( Ch == 'X'-'A'+1 )
88 serial_debug_mode = 1;
98 PTY_SendInput(Port->PTY, &Ch, 1);
101 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer)
103 tSerialPort *Port = Handle;
104 const char *buf = Buffer;
105 for( int i = 0; i < Length; i ++ )
106 Port->OutputFcn( Port->OutHandle, *buf++ );
108 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode)
112 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims)
117 void Serial_int_OutputDebug(void *unused, char ch)
119 Debug_PutCharDebug(ch);