3 Copyright (c) 1998-2001 Klaus P. Gerlicher
25 15-Nov-2000: general cleanup of source files
29 This file may be distributed under the terms of the GNU Public License.
33 ////////////////////////////////////////////////////
42 #include "serial_port.h"
44 #define STANDARD_DEBUG_PREFIX "pICE: "
46 ////////////////////////////////////////////////////
49 LONG lDebugLevel = 10;
52 USHORT usDebugPortBase;
54 extern BOOLEAN bIsPrintkPatched;
55 ////////////////////////////////////////////////////
58 void DebugSendString(LPSTR s);
61 //*************************************************************************
64 // internal debug print
65 //*************************************************************************
66 VOID Pice_dprintf(ULONG DebugLevel, PCHAR DebugMessage, ...)
70 va_start(ap, DebugMessage);
71 if (/*DebugLevel <= lDebugLevel*/ DebugLevel == 2)
73 save_flags(ulDebugFlags);
75 PICE_vsprintf(tempDebug, DebugMessage, ap);
76 //ei DebugSendString(tempDebug);
77 Print(OUTPUT_WINDOW, tempDebug);
78 //DbgPrint("%s", tempDebug);
79 restore_flags(ulDebugFlags);
84 //************************************************************************
87 // Output a character to the serial port
88 //************************************************************************
89 BOOLEAN DebugSendByte(UCHAR x)
95 // Wait for transmitter to clear
96 while ((inportb((USHORT)(usDebugPortBase + LSR)) & XMTRDY) == 0)
102 outportb((USHORT)(usDebugPortBase + TXR), x);
107 ///************************************************************************
110 ///************************************************************************
111 void DebugSendString(LPSTR s)
113 ULONG len = PICE_strlen(s),i;
122 ///************************************************************************
125 ///************************************************************************
126 void DebugSetSpeed(ULONG baudrate)
131 divisor = (ULONG) (115200L/baudrate);
133 c = inportb((USHORT)(usDebugPortBase + LCR));
134 outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)(c | 0x80)); // Set DLAB
135 outportb((USHORT)(usDebugPortBase + DLL), (UCHAR)(divisor & 0x00FF));
136 outportb((USHORT)(usDebugPortBase + DLH), (UCHAR)((divisor >> 8) & 0x00FF));
137 outportb((USHORT)(usDebugPortBase + LCR), c); // Reset DLAB
141 ///************************************************************************
144 // Set other communications parameters
145 //************************************************************************
146 void DebugSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit)
151 if (usDebugPortBase == 0) return ;
152 if (Bits < 5 || Bits > 8) return ;
153 if (StopBit != 1 && StopBit != 2) return ;
154 if (Parity != NO_PARITY && Parity != ODD_PARITY && Parity != EVEN_PARITY)
158 setting |= ((StopBit == 1) ? 0x00 : 0x04);
161 c = inportb((USHORT)(usDebugPortBase + LCR));
162 outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)(c & ~0x80)); // Reset DLAB
165 outportb((USHORT)(usDebugPortBase + IER), (UCHAR)0);
167 outportb((USHORT)(usDebugPortBase + FCR), (UCHAR)0);
169 outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)setting);
171 outportb((USHORT)(usDebugPortBase + MCR), DTR | RTS);
177 ///************************************************************************
178 // DebugSetupSerial()
180 ///************************************************************************
181 void DebugSetupSerial(ULONG port,ULONG baudrate)
183 USHORT ports[]={COM1BASE,COM2BASE};
185 usDebugPortBase = ports[port-1];
186 DebugSetOthers(NO_PARITY,8,1);
187 DebugSetSpeed(baudrate);