ReactOS  0.4.15-dev-341-g17c5fb8
debug.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4 
5 Module Name:
6 
7  debug.c
8 
9 Abstract:
10 
11  debug output
12 
13 Environment:
14 
15  LINUX 2.2.X
16  Kernel mode only
17 
18 Author:
19 
20  Klaus P. Gerlicher
21 
22 Revision History:
23 
24  04-Feb-1999: created
25  15-Nov-2000: general cleanup of source files
26 
27 Copyright notice:
28 
29  This file may be distributed under the terms of the GNU Public License.
30 
31 --*/
32 
34 // INCLUDES
36 #ifdef DEBUG
37 #include "remods.h"
38 
39 #include "precomp.h"
40 #include <stdarg.h>
41 #include "serial.h"
42 #include "serial_port.h"
43 
44 #define STANDARD_DEBUG_PREFIX "pICE: "
45 
47 // GLOBALS
49 LONG lDebugLevel = 10;
50 ULONG ulDebugFlags;
51 char tempDebug[2048];
52 USHORT usDebugPortBase;
53 
56 // FUNCTIONS
58 void DebugSendString(LPSTR s);
59 
60 
61 //*************************************************************************
62 // Pice_dprintf()
63 //
64 // internal debug print
65 //*************************************************************************
66 VOID Pice_dprintf(ULONG DebugLevel, PCHAR DebugMessage, ...)
67 {
68  va_list ap;
69 
70  va_start(ap, DebugMessage);
71  if (/*DebugLevel <= lDebugLevel*/ DebugLevel == 2)
72  {
73  save_flags(ulDebugFlags);
74  cli();
75  PICE_vsprintf(tempDebug, DebugMessage, ap);
76  //ei DebugSendString(tempDebug);
77  Print(OUTPUT_WINDOW, tempDebug);
78  //DbgPrint("%s", tempDebug);
79  restore_flags(ulDebugFlags);
80  }
81  va_end(ap);
82 }
83 
84 //************************************************************************
85 // SendByte()
86 //
87 // Output a character to the serial port
88 //************************************************************************
89 BOOLEAN DebugSendByte(UCHAR x)
90 {
91  ULONG timeout;
92 
93  timeout = 0x00FFFFL;
94 
95  // Wait for transmitter to clear
96  while ((inportb((USHORT)(usDebugPortBase + LSR)) & XMTRDY) == 0)
97  if (!(--timeout))
98  {
99  return FALSE;
100  }
101 
102  outportb((USHORT)(usDebugPortBase + TXR), x);
103 
104  return TRUE;
105 }
106 
108 // DebugSetSpeed()
109 //
111 void DebugSendString(LPSTR s)
112 {
113  ULONG len = PICE_strlen(s),i;
114 
115  for(i=0;i<len;i++)
116  {
117  DebugSendByte(s[i]);
118  }
119  DebugSendByte('\r');
120 }
121 
123 // DebugSetSpeed()
124 //
126 void DebugSetSpeed(ULONG baudrate)
127 {
128  UCHAR c;
129  ULONG divisor;
130 
131  divisor = (ULONG) (115200L/baudrate);
132 
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
138 
139 }
140 
142 // DebugSetOthers()
143 //
144 // Set other communications parameters
145 //************************************************************************
146 void DebugSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit)
147 {
148  ULONG setting;
149  UCHAR c;
150 
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)
155  return;
156 
157  setting = Bits-5;
158  setting |= ((StopBit == 1) ? 0x00 : 0x04);
159  setting |= Parity;
160 
161  c = inportb((USHORT)(usDebugPortBase + LCR));
162  outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)(c & ~0x80)); // Reset DLAB
163 
164  // no ints
165  outportb((USHORT)(usDebugPortBase + IER), (UCHAR)0);
166 
167  outportb((USHORT)(usDebugPortBase + FCR), (UCHAR)0);
168 
169  outportb((USHORT)(usDebugPortBase + LCR), (UCHAR)setting);
170 
171  outportb((USHORT)(usDebugPortBase + MCR), DTR | RTS);
172 
173 
174  return ;
175 }
176 
178 // DebugSetupSerial()
179 //
181 void DebugSetupSerial(ULONG port,ULONG baudrate)
182 {
183  USHORT ports[]={COM1BASE,COM2BASE};
184 #if 0 //ei temporary
185  usDebugPortBase = ports[port-1];
186  DebugSetOthers(NO_PARITY,8,1);
187  DebugSetSpeed(baudrate);
188 #endif
189 }
190 #endif // DEBUG
191 
192 // EOF
signed char * PCHAR
Definition: retypes.h:7
return
Definition: dirsup.c:529
#define TRUE
Definition: types.h:120
UCHAR inportb(PUCHAR port)
Definition: utils.c:2174
#define COM2BASE
Definition: serial_port.h:36
#define COM1BASE
Definition: serial_port.h:35
#define TXR
Definition: serial_port.h:60
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
Definition: dhcpd.h:245
char * LPSTR
Definition: xmlstorage.h:182
ULONG DebugLevel
Definition: fbtusb.c:26
GLbitfield GLuint64 timeout
Definition: glext.h:7164
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:776
#define save_flags(x)
Definition: utils.h:285
#define ODD_PARITY
Definition: serial.c:90
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define va_end(ap)
Definition: acmsvcex.h:90
long LONG
Definition: pedump.c:60
#define RTS
Definition: serial_port.h:127
#define IER
Definition: serial_port.h:62
unsigned char BOOLEAN
char * va_list
Definition: acmsvcex.h:78
#define LSR
Definition: serial_port.h:67
int PICE_vsprintf(char *buf, const char *fmt, va_list args)
Definition: utils.c:1850
void outportb(PUCHAR port, UCHAR data)
Definition: utils.c:2154
#define MCR
Definition: serial_port.h:66
const GLubyte * c
Definition: glext.h:8905
RECT cli
Definition: sndrec32.cpp:79
#define LCR
Definition: serial_port.h:65
#define XMTRDY
Definition: serial_port.h:109
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOLEAN bIsPrintkPatched
Definition: output.c:56
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
#define DLH
Definition: serial_port.h:70
GLdouble s
Definition: gl.h:2039
GLuint divisor
Definition: glext.h:6313
#define NO_PARITY
Definition: serial.c:89
unsigned short USHORT
Definition: pedump.c:61
#define EVEN_PARITY
Definition: serial.c:91
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define restore_flags(x)
Definition: utils.h:286
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
#define DTR
Definition: serial_port.h:126
#define FCR
Definition: serial_port.h:64
USHORT port
Definition: uri.c:228
#define DLL
Definition: serial_port.h:69