3 * - By John Hodge (thePowersGang)
6 * - Common serial port code
12 #include <drv_serial.h>
14 #include <debug_hooks.h>
16 extern void Validate_VirtualMemoryUsage(void);
22 tSerial_OutFcn OutputFcn;
27 int Serial_Install(char **Arguments);
28 //tSerialPort *Serial_CreatePort( tSerial_OutFcn output, void *handle );
29 //void Serial_ByteReceived(tSerialPort *Port, char Ch);
30 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer);
31 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode);
32 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims);
33 void Serial_int_OutputDebug(void *unused, char ch);
36 MODULE_DEFINE(0, 0x100, Serial, Serial_Install, NULL, "PTY", NULL);
37 tSerialPort *gSerial_KernelDebugPort;
40 int Serial_Install(char **Arguments)
42 gSerial_KernelDebugPort = Serial_CreatePort( Serial_int_OutputDebug, NULL );
46 tSerialPort *Serial_CreatePort(tSerial_OutFcn output, void *handle)
48 tSerialPort *ret = malloc( sizeof(tSerialPort) );
49 // Automatically indexed
50 struct ptydims dims = {
54 struct ptymode mode = {
55 .OutputMode = PTYBUFFMT_TEXT,
56 .InputMode = PTYIMODE_CANON|PTYIMODE_ECHO
58 ret->PTY = PTY_Create("serial#", ret,
59 Serial_int_PTYOutput, Serial_int_PTYSetDims, Serial_int_PTYSetArrib,
62 ret->OutputFcn = output;
63 ret->OutHandle = handle;
67 void Serial_ByteReceived(tSerialPort *Port, char Ch)
69 LOG("Port=%p,Ch=%i", Port, Ch);
72 if( Port == gSerial_KernelDebugPort )
74 static tDebugHook info;
75 static int serial_debug_mode = 0;
76 // Kernel serial debug hooks.
77 if( serial_debug_mode == 2 )
81 serial_debug_mode = 0;
83 DebugHook_HandleInput(&info, 1, &Ch);
86 else if( serial_debug_mode )
88 if( Ch == 'X'-'A'+1 ) {
89 PTY_SendInput(Port->PTY, &Ch, 1);
90 serial_debug_mode = 0;
92 else if( Ch == '~' ) {
94 serial_debug_mode = 2;
97 DebugHook_HandleInput(&info, 1, &Ch);
98 serial_debug_mode = 0;
102 else if( Ch == 'X'-'A'+1 )
104 serial_debug_mode = 1;
114 LOG("Dispatch to PTY");
115 PTY_SendInput(Port->PTY, &Ch, 1);
118 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer)
120 tSerialPort *Port = Handle;
121 const char *buf = Buffer;
122 for( int i = 0; i < Length; i ++ )
123 Port->OutputFcn( Port->OutHandle, *buf++ );
125 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode)
129 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims)
134 void Serial_int_OutputDebug(void *unused, char ch)
136 Debug_PutCharDebug(ch);