source: cmedia/trunk/Drv16/commdbg.c@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 8.6 KB
Line 
1/* $Id: commdbg.c,v 1.2 2000/07/17 18:32:33 sandervl Exp $ */
2
3/******************************************************************************
4* Jazz16 Physical Device Driver
5* Production code and toolkit sample
6*
7* (c) Copyright IBM Corporation 1993. All rights reserved
8* (c) Copyright Media Vision Corporation 1993, 1994. All rights reserved
9*
10* DISCLAIMER OF WARRANTIES. The following [enclosed] code is
11* sample code created by IBM Corporation and Media Vision Corporation.
12* It is provided to you solely for the purpose of assisting you in the
13* development of your applications.
14* The code is provided "AS IS", without warranty of any kind.
15* IBM and Media Vision shall not be liable for any damages arising out of
16* your use of the sample code, even if they have been advised of the
17* possibility of such damages.
18*
19*******************************************************************************
20*
21* commdbg.c = debug routines to send data to COM: port
22*
23* This file contains routines to send debug information to COM: ports
24* during execution of device driver.
25* The routines provide 'C' printf like functions that send their output
26* to the serial port rather than stdout.
27* The calls to these routines are only called for debug versions of the
28* driver. See file debug.h for flags to turn on/off different debug options.
29*
30* MODIFICATION HISTORY:
31* DATE CHANGE DESCRIPTION
32* unknown Creation (Media Vision)
33* 07/30/93 Add headers for toolkit
34* 09/21/93 Header modifications
35******************************************************************************/
36
37#define INCL_NOPMAPI
38#define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
39#include <os2.h>
40#include "dbgos2.h"
41#include "commdbg.h"
42
43#define CR 0x0d
44#define LF 0x0a
45
46#define LEADING_ZEROES 0x8000
47#define SIGNIFICANT_FIELD 0x0007
48
49
50BOOL fLineTerminate = TRUE;
51int dbglevel = 2;
52
53static char hextab[]="0123456789ABCDEF";
54
55 //-------------------- DecWordToASCII -
56char far * cdecl DecWordToASCII(char far *StrPtr, USHORT wDecVal, USHORT Option)
57{
58 USHORT Power;
59 USHORT Digit;
60 USHORT fNonZero = Option & LEADING_ZEROES;
61
62 for( Power = 10000; Power; Power /= 10 )
63 {
64 Digit = 0;
65 while( wDecVal >= Power ) { Digit++; wDecVal -= Power; }
66 fNonZero |= Digit;
67
68 if( fNonZero || Power == 1 ) *StrPtr++ = (char)('0' + Digit);
69 }
70
71 return StrPtr;
72}
73
74
75#ifdef DEBUG //-------------------- DecLongToASCII -
76char far * cdecl DecLongToASCII(char far *StrPtr, ULONG lDecVal, USHORT Option)
77{
78 ULONG Power;
79 USHORT Digit;
80 USHORT fNonZero = Option & LEADING_ZEROES;
81
82 for( Power = 1000000000L; Power; Power /= 10 )
83 {
84 Digit = 0;
85 while( lDecVal >= Power ) { Digit++; lDecVal -= Power; }
86 fNonZero |= Digit;
87
88 if( fNonZero || Power == 1 ) *StrPtr++ = (char)('0' + Digit);
89 }
90
91 return StrPtr;
92}
93#endif
94
95 //-------------------- HexWordToASCII -
96char far * cdecl HexWordToASCII(char far *StrPtr, USHORT wHexVal, USHORT Option)
97{
98 USHORT Digit;
99 SHORT ShiftVal;
100 USHORT fNonZero = Option & LEADING_ZEROES;
101
102 for( ShiftVal = 12; ShiftVal >= 0; ShiftVal -= 4 )
103 {
104 Digit = (wHexVal >> ShiftVal) & 0xf;
105 fNonZero |= Digit;
106
107 if( fNonZero || !ShiftVal ) *StrPtr++ = hextab[Digit];
108 }
109
110 return StrPtr;
111}
112
113
114#ifdef DEBUG //-------------------- HexLongToASCII -
115char far * cdecl HexLongToASCII(char far *StrPtr, ULONG lHexVal, USHORT Option)
116{
117 USHORT Digit;
118 SHORT ShiftVal;
119 USHORT fNonZero = Option & LEADING_ZEROES;
120
121 for( ShiftVal = 28; ShiftVal >= 0; ShiftVal -= 4 )
122 {
123 Digit = (USHORT)(lHexVal >> ShiftVal) & 0xf;
124 fNonZero |= Digit;
125
126 if( fNonZero || !ShiftVal ) *StrPtr++ = hextab[Digit];
127 }
128
129 return StrPtr;
130}
131#endif
132
133
134#ifdef DEBUG //------------------------- PrintfOut -
135void cdecl PrintfOut(char far *DbgStr , ...)
136{
137 static char BuildString[1024];
138 char far *BuildPtr=BuildString;
139 char far *pStr=(char far *) DbgStr;
140 char far *SubStr;
141 union {
142 void far *VoidPtr;
143 USHORT far *WordPtr;
144 ULONG far *LongPtr;
145 ULONG far *StringPtr;
146 } Parm;
147 USHORT wBuildOption;
148
149 Parm.VoidPtr=(void far *) &DbgStr;
150 Parm.StringPtr++; // skip size of string pointer
151
152 while (*pStr)
153 {
154 // don't overflow target
155 if (BuildPtr >= (char far *) &BuildString[1024-2])
156 break;
157
158 switch (*pStr)
159 {
160 case '%':
161 wBuildOption=0;
162 pStr++;
163 if (*pStr=='0')
164 {
165 wBuildOption|=LEADING_ZEROES;
166 pStr++;
167 }
168 if (*pStr=='u') // always unsigned
169 pStr++;
170
171 switch(*pStr)
172 {
173 case 'x':
174 case 'X':
175 BuildPtr=HexWordToASCII(BuildPtr, *Parm.WordPtr++,wBuildOption);
176 pStr++;
177 continue;
178
179 case 'd':
180 BuildPtr=DecWordToASCII(BuildPtr, *Parm.WordPtr++,wBuildOption);
181 pStr++;
182 continue;
183
184 case 's':
185 SubStr=(char far *)*Parm.StringPtr;
186 while (*BuildPtr++ = *SubStr++);
187 Parm.StringPtr++;
188 BuildPtr--; // remove the \0
189 pStr++;
190 continue;
191
192 case 'l':
193 pStr++;
194 switch (*pStr)
195 {
196 case 'x':
197 case 'X':
198 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
199 pStr++;
200 continue;
201
202 case 'd':
203 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
204 pStr++;
205 continue;
206 } // end switch
207 continue; // dunno what he wants
208
209 case 0:
210 continue;
211 } // end switch
212 break;
213
214 case '\\':
215 pStr++;
216 switch (*pStr)
217 {
218 case 'n':
219 *BuildPtr++=LF;
220 pStr++;
221 continue;
222
223 case 'r':
224 *BuildPtr++=CR;
225 pStr++;
226 continue;
227
228 case 0:
229 continue;
230 break;
231 } // end switch
232
233 break;
234 } // end switch
235
236 *BuildPtr++=*pStr++;
237 } // end while
238
239 *BuildPtr=0; // cauterize the string
240 StringOut((char far *) BuildString); // print to comm port
241}
242#endif //DEBUG
243
244
245#ifdef DEBUG //------------------------- StringOut -
246void StringOut(char far *DbgStr)
247{
248 while (*DbgStr)
249 CharOut(*DbgStr++);
250
251 if (fLineTerminate)
252 {
253 CharOut(CR); // append carriage return,
254 CharOut(LF); // linefeed
255 }
256}
257#endif
258
259
260#ifdef DEBUG
261#define MAGIC_COMM_PORT 0x3f8 // pulled from word ptr 40:0
262//#define MAGIC_COMM_PORT 0x2f8 // pulled from word ptr 40:0
263
264
265#define UART_DATA 0x00 // UART Data port
266#define UART_INT_ENAB 0x01 // UART Interrupt enable
267#define UART_INT_ID 0x02 // interrupt ID
268#define UART_LINE_CTRL 0x03 // line control registers
269#define UART_MODEM_CTRL 0x04 // modem control register
270#define UART_LINE_STAT 0x05 // line status register
271#define UART_MODEM_STAT 0x06 // modem status regiser
272#define UART_DIVISOR_LO 0x00 // divisor latch least sig
273#define UART_DIVISOR_HI 0x01h // divisor latch most sig
274
275#define DELAY nop
276#endif
277
278#ifdef DEBUG //--------------------------- CharOut -
279void CharOut(char c)
280{
281 _asm {
282
283 mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port
284 add dx, UART_LINE_STAT
285
286ReadyCheck:
287 in al, dx // wait for comm port ready signal
288
289 DELAY
290 DELAY
291 DELAY
292
293 test al, 020h
294 jz ReadyCheck
295
296 // Send the character
297
298 add dx, UART_DATA - UART_LINE_STAT
299 mov al,c
300 out dx, al
301
302 DELAY
303 DELAY
304 DELAY
305 }
306}
307#endif
308
Note: See TracBrowser for help on using the repository browser.