3 * - By John Hodge (thePowersGang)
6 * - Common serial port code
11 #include <drv_serial.h>
13 #include <debug_hooks.h>
15 extern void Validate_VirtualMemoryUsage(void);
21 tSerial_OutFcn OutputFcn;
26 int Serial_Install(char **Arguments);
27 //tSerialPort *Serial_CreatePort( tSerial_OutFcn output, void *handle );
28 //void Serial_ByteReceived(tSerialPort *Port, char Ch);
29 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer);
30 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode);
31 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims);
32 void Serial_int_OutputDebug(void *unused, char ch);
35 MODULE_DEFINE(0, 0x100, Serial, Serial_Install, NULL, "PTY", NULL);
36 tSerialPort *gSerial_KernelDebugPort;
39 int Serial_Install(char **Arguments)
41 gSerial_KernelDebugPort = Serial_CreatePort( Serial_int_OutputDebug, NULL );
45 tSerialPort *Serial_CreatePort(tSerial_OutFcn output, void *handle)
47 tSerialPort *ret = malloc( sizeof(tSerialPort) );
48 // Automatically indexed
49 struct ptydims dims = {
53 struct ptymode mode = {
54 .OutputMode = PTYBUFFMT_TEXT,
55 .InputMode = PTYIMODE_CANON|PTYIMODE_ECHO
57 ret->PTY = PTY_Create("serial#", ret,
58 Serial_int_PTYOutput, Serial_int_PTYSetDims, Serial_int_PTYSetArrib,
61 ret->OutputFcn = output;
62 ret->OutHandle = handle;
66 void Serial_ByteReceived(tSerialPort *Port, char Ch)
70 if( Port == gSerial_KernelDebugPort )
72 static tDebugHook info;
73 static int serial_debug_mode = 0;
74 // Kernel serial debug hooks.
75 if( serial_debug_mode == 2 )
79 serial_debug_mode = 0;
81 DebugHook_HandleInput(&info, 1, &Ch);
84 else if( serial_debug_mode )
86 if( Ch == 'X'-'A'+1 ) {
87 PTY_SendInput(Port->PTY, &Ch, 1);
88 serial_debug_mode = 0;
90 else if( Ch == '~' ) {
92 serial_debug_mode = 2;
95 DebugHook_HandleInput(&info, 1, &Ch);
96 serial_debug_mode = 0;
100 else if( Ch == 'X'-'A'+1 )
102 serial_debug_mode = 1;
112 PTY_SendInput(Port->PTY, &Ch, 1);
115 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer)
117 tSerialPort *Port = Handle;
118 const char *buf = Buffer;
119 for( int i = 0; i < Length; i ++ )
120 Port->OutputFcn( Port->OutHandle, *buf++ );
122 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode)
126 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims)
131 void Serial_int_OutputDebug(void *unused, char ch)
133 Debug_PutCharDebug(ch);