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 // TODO: Make PTY code handle 'serial#' and auto-number
46 ret->PTY = PTY_Create("serial0", 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)
67 PTY_SendInput(Port->PTY, &Ch, 1);
70 void Serial_int_PTYOutput(void *Handle, size_t Length, const void *Buffer)
72 tSerialPort *Port = Handle;
73 const char *buf = Buffer;
74 for( int i = 0; i < Length; i ++ )
75 Port->OutputFcn( Port->OutHandle, *buf++ );
77 int Serial_int_PTYSetArrib(void *Handle, const struct ptymode *Mode)
81 int Serial_int_PTYSetDims(void *Handle, const struct ptydims *Dims)
86 void Serial_int_OutputDebug(void *unused, char ch)
88 Debug_PutCharDebug(ch);