0
|
1 |
/*
|
|
2 |
* wlantrace.cpp
|
|
3 |
*
|
|
4 |
* Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
|
|
5 |
* All rights reserved.
|
|
6 |
*
|
|
7 |
* This program and the accompanying materials are made available under the
|
|
8 |
* terms of the Eclipse Public License v1.0 or BSD License which accompanies
|
|
9 |
* this distribution. The Eclipse Public License is available at
|
|
10 |
* http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.
|
|
11 |
*
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
14 |
* are met:
|
|
15 |
*
|
|
16 |
* * Redistributions of source code must retain the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
18 |
* * Redistributions in binary form must reproduce the above copyright
|
|
19 |
* notice, this list of conditions and the following disclaimer in
|
|
20 |
* the documentation and/or other materials provided with the
|
|
21 |
* distribution.
|
|
22 |
* * Neither the name Texas Instruments nor the names of its
|
|
23 |
* contributors may be used to endorse or promote products derived
|
|
24 |
* from this software without specific prior written permission.
|
|
25 |
*
|
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
27 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
28 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
29 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
30 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
31 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
32 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
33 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
34 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37 |
*/
|
|
38 |
|
|
39 |
|
|
40 |
/** \file wlantrace.cpp
|
|
41 |
* \brief Handle any event interrupt from the FW
|
|
42 |
*
|
|
43 |
* \see
|
|
44 |
*/
|
|
45 |
|
|
46 |
|
|
47 |
#include <kernel/kernel.h>
|
|
48 |
|
|
49 |
#ifdef __cplusplus
|
|
50 |
extern "C"
|
|
51 |
{
|
|
52 |
#include "CDebugOutput.h"
|
|
53 |
}
|
|
54 |
#endif
|
|
55 |
|
|
56 |
#include "gendebug.h"
|
|
57 |
#define __FILE_ID__ FILE_ID_143
|
|
58 |
|
|
59 |
#ifndef LOCAL
|
|
60 |
#define LOCAL static
|
|
61 |
#endif
|
|
62 |
|
|
63 |
#if WSTH /* Work station Test Harness */
|
|
64 |
#define OUTPUT(msg) printf msg; printf("\n");
|
|
65 |
#else
|
|
66 |
#define OUTPUT(msg) Kern::Printf msg;
|
|
67 |
#endif
|
|
68 |
|
|
69 |
#define TRACE_BUFFER_SIZE 250
|
|
70 |
#define MAX_FORMAT_WIDTH 10 /* must not be less than 10, which represents a 32 bit value in decimal */
|
|
71 |
|
|
72 |
|
|
73 |
TUint gModuleId;
|
|
74 |
|
|
75 |
/* order must be the same as that defined in wlanTraceConfig.h */
|
|
76 |
const char* const wlanModuleNameStringArray[] = {
|
|
77 |
"wlanResourceManager:",
|
|
78 |
"wlanSpiManager:",
|
|
79 |
"wlanPhysicalChannelOmap:",
|
|
80 |
"wlanIf:",
|
|
81 |
"wlanControl:",
|
|
82 |
};
|
|
83 |
|
|
84 |
typedef enum
|
|
85 |
{
|
|
86 |
uToAFormatDec = 10,
|
|
87 |
uToAFormatHex = 16
|
|
88 |
} utoaFormats;
|
|
89 |
|
|
90 |
void Assert( const TInt8* aFile, TInt aLine, TBool aExpression )
|
|
91 |
{
|
|
92 |
#ifndef NDEBUG
|
|
93 |
|
|
94 |
if ( !aExpression )
|
|
95 |
{
|
|
96 |
TraceDump( CRIT_LEVEL, (reinterpret_cast<const char*>(aFile)) );
|
|
97 |
TraceDump( CRIT_LEVEL, (("Line: %d"), aLine));
|
|
98 |
|
|
99 |
Kern::Fault(("[WLANPDD] Subsystem programmed fault"), 0);
|
|
100 |
}
|
|
101 |
else
|
|
102 |
{
|
|
103 |
// left intentionally empty
|
|
104 |
}
|
|
105 |
|
|
106 |
#endif // NDEBUG
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
LOCAL TUint32 wlanStrlen(const char* pBuffer)
|
|
111 |
{
|
|
112 |
TUint32 length = 0;
|
|
113 |
|
|
114 |
if(pBuffer)
|
|
115 |
{
|
|
116 |
while(*pBuffer++)
|
|
117 |
{
|
|
118 |
length++;
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
return length;
|
|
123 |
}
|
|
124 |
|
|
125 |
LOCAL TUint32 wlanStrcpy(char* pDestination, const char* pSource)
|
|
126 |
{
|
|
127 |
TUint32 charactersCopied = 0;
|
|
128 |
|
|
129 |
if(pSource && pDestination)
|
|
130 |
{
|
|
131 |
while(*pSource)
|
|
132 |
{
|
|
133 |
*pDestination++ = *pSource++;
|
|
134 |
charactersCopied++;
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
return charactersCopied;
|
|
139 |
}
|
|
140 |
|
|
141 |
LOCAL void wlanReverse(char* pStr)
|
|
142 |
{
|
|
143 |
TUint32 start;
|
|
144 |
TUint32 end;
|
|
145 |
char c;
|
|
146 |
|
|
147 |
for(start = 0, end = wlanStrlen(pStr)-1 ; start < end ; start++, end --)
|
|
148 |
{
|
|
149 |
c = *(pStr + start);
|
|
150 |
*(pStr + start) = *(pStr + end);
|
|
151 |
*(pStr + end) = c;
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
LOCAL void wlanUtoa(TUint32 n, char* pStr, utoaFormats base, char paddingCharacter, TUint32 width)
|
|
156 |
{
|
|
157 |
const char uppercaseHexValues[] = "0123456789ABCDEF";
|
|
158 |
/* const char lowercaseHexValues[] = "0123456789abcdef"; never implemented - what is the point.. */
|
|
159 |
TUint32 i = 0;
|
|
160 |
|
|
161 |
do
|
|
162 |
{
|
|
163 |
*(pStr + i++) = uppercaseHexValues[(n % base)];
|
|
164 |
width--; /* may wrap round - but handled by check below */
|
|
165 |
} while ((n /= base) > 0);
|
|
166 |
|
|
167 |
if(width < MAX_FORMAT_WIDTH)
|
|
168 |
{
|
|
169 |
while(width--)
|
|
170 |
*(pStr + i++) = paddingCharacter;
|
|
171 |
}
|
|
172 |
|
|
173 |
*(pStr + i) = '\0';
|
|
174 |
wlanReverse(pStr);
|
|
175 |
}
|
|
176 |
|
|
177 |
|
|
178 |
LOCAL bool wlanIsDigit(char character)
|
|
179 |
{
|
|
180 |
if(character >= '0' && character <= '9')
|
|
181 |
{
|
|
182 |
return true;
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
return false;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
|
|
191 |
void wlanPrintOutBuffer(char* const pBuffer, const char* const pPrefix, TUint32* bufferLength)
|
|
192 |
{
|
|
193 |
*(pBuffer + (*bufferLength)++) = '\0';
|
|
194 |
|
|
195 |
if(wlanStrlen(pBuffer) > TRACE_BUFFER_SIZE)
|
|
196 |
{
|
|
197 |
OUTPUT(("ERROR:INCREASE TRACE_BUFFER_SIZE - needed %d", *bufferLength))
|
|
198 |
}
|
|
199 |
|
|
200 |
#ifdef WSTH
|
|
201 |
printf(pBuffer);
|
|
202 |
printf("\n"); /* STI adds \n normally - but here we have to add it manually */
|
|
203 |
#else
|
|
204 |
Kern::Printf(pBuffer);
|
|
205 |
#endif
|
|
206 |
|
|
207 |
*bufferLength = 0;
|
|
208 |
*bufferLength += wlanStrcpy((pBuffer + *bufferLength), pPrefix); /* add trace identifier to new line */
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
void wlanPrintf(const char* const pPrefix, const char* pText, VA_LIST args)
|
|
213 |
{
|
|
214 |
char traceBuffer[TRACE_BUFFER_SIZE];
|
|
215 |
const char* pNullString = "<NULL>";
|
|
216 |
const char* pUnknown = "<UPF>"; /* Unknown Print Format */
|
|
217 |
char* pString;
|
|
218 |
TUint32 value;
|
|
219 |
TUint32 bufferPos = 0;
|
|
220 |
TUint32 error = 0;
|
|
221 |
TUint32 formatWidth;
|
|
222 |
char valueBuffer[MAX_FORMAT_WIDTH + 1]; /* for the terminator */
|
|
223 |
char paddingChar;
|
|
224 |
|
|
225 |
if(pText)
|
|
226 |
{
|
|
227 |
bufferPos += wlanStrcpy((traceBuffer + bufferPos), pPrefix); /* add trace identifier to first line */
|
|
228 |
for( ; *pText != '\0' && error == 0 ; pText++)
|
|
229 |
{
|
|
230 |
if (*pText != '%')
|
|
231 |
{
|
|
232 |
if(*pText == '\n')
|
|
233 |
{
|
|
234 |
wlanPrintOutBuffer(traceBuffer, pPrefix, &bufferPos);
|
|
235 |
}
|
|
236 |
else
|
|
237 |
{
|
|
238 |
traceBuffer[bufferPos++] = *pText;
|
|
239 |
}
|
|
240 |
continue;
|
|
241 |
}
|
|
242 |
else
|
|
243 |
{
|
|
244 |
pText++; /* skip % */
|
|
245 |
formatWidth = 0;
|
|
246 |
memset(valueBuffer, 0, MAX_FORMAT_WIDTH); /* reset the width buffer */
|
|
247 |
if(*pText == '0')
|
|
248 |
paddingChar = '0';
|
|
249 |
else
|
|
250 |
paddingChar = ' ';
|
|
251 |
|
|
252 |
while( wlanIsDigit(*pText) || *pText == '.')
|
|
253 |
{
|
|
254 |
if(*pText == '.')
|
|
255 |
{
|
|
256 |
while( wlanIsDigit(*pText) || *pText == '.')
|
|
257 |
pText++;
|
|
258 |
break; /* only deal with leading width - therefore not decimal places - however %f is not supported at time of writting */
|
|
259 |
}
|
|
260 |
else
|
|
261 |
{
|
|
262 |
formatWidth = (formatWidth * 10) + (*pText - '0');
|
|
263 |
pText++;
|
|
264 |
}
|
|
265 |
}
|
|
266 |
if(formatWidth > MAX_FORMAT_WIDTH)
|
|
267 |
{
|
|
268 |
OUTPUT(("ERROR:formatWidth too large - %d", formatWidth))
|
|
269 |
formatWidth = MAX_FORMAT_WIDTH;
|
|
270 |
}
|
|
271 |
}
|
|
272 |
|
|
273 |
if(*pText == '#')
|
|
274 |
{
|
|
275 |
pText++; /* skip the hash */
|
|
276 |
|
|
277 |
/* Now look at the formatting character */
|
|
278 |
switch(*pText)
|
|
279 |
{
|
|
280 |
case 'x':
|
|
281 |
case 'X':
|
|
282 |
case 'p':
|
|
283 |
traceBuffer[bufferPos++] = '0';
|
|
284 |
if(*pText == 'p')
|
|
285 |
traceBuffer[bufferPos++] = 'x';
|
|
286 |
else
|
|
287 |
traceBuffer[bufferPos++] = *pText;
|
|
288 |
formatWidth -= 2;
|
|
289 |
break;
|
|
290 |
|
|
291 |
case 'd':
|
|
292 |
/* do nothing - there is no formating needed */
|
|
293 |
break;
|
|
294 |
|
|
295 |
default:
|
|
296 |
OUTPUT(("ERROR:unknown hash formatting - %c", *pText))
|
|
297 |
break;
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
switch (*pText)
|
|
302 |
{
|
|
303 |
case 'd': /* signed */
|
|
304 |
value = va_arg(args, TUint32);
|
|
305 |
if( value & 0x8000000 ) /* MSB 0 = Not signed. MSB 1 = signed*/
|
|
306 |
{
|
|
307 |
/* Signed value */
|
|
308 |
traceBuffer[bufferPos++] = '-';
|
|
309 |
/* Ignore MSB which is the sign. Negate and inc by 1 to get the absolute value to be printed. */
|
|
310 |
value = ((~(value & 0x7FFFFFFF) & 0x7FFFFFFF) + 1);
|
|
311 |
}
|
|
312 |
wlanUtoa(value, valueBuffer, uToAFormatDec, paddingChar, formatWidth);
|
|
313 |
bufferPos += wlanStrcpy((traceBuffer + bufferPos), valueBuffer);
|
|
314 |
break;
|
|
315 |
|
|
316 |
case 'u': /* unsigned */
|
|
317 |
value = va_arg(args, TUint32);
|
|
318 |
wlanUtoa(value, valueBuffer, uToAFormatDec, paddingChar, formatWidth);
|
|
319 |
bufferPos += wlanStrcpy((traceBuffer + bufferPos), valueBuffer);
|
|
320 |
break;
|
|
321 |
|
|
322 |
case 'X': /* Fall through */
|
|
323 |
case 'x':
|
|
324 |
case 'p':
|
|
325 |
value = va_arg(args, TUint32);
|
|
326 |
wlanUtoa(value, valueBuffer, uToAFormatHex, paddingChar, formatWidth);
|
|
327 |
bufferPos += wlanStrcpy((traceBuffer + bufferPos), valueBuffer);
|
|
328 |
break;
|
|
329 |
|
|
330 |
case 'c':
|
|
331 |
traceBuffer[bufferPos++] = va_arg(args, int); /* all params are 32 bit - hence int */
|
|
332 |
break;
|
|
333 |
|
|
334 |
case 's':
|
|
335 |
pString = va_arg(args, char *);
|
|
336 |
if(pString == NULL)
|
|
337 |
{
|
|
338 |
pString = (char*)pNullString;
|
|
339 |
}
|
|
340 |
bufferPos += wlanStrcpy((traceBuffer + bufferPos), pString);
|
|
341 |
break;
|
|
342 |
|
|
343 |
default:
|
|
344 |
OUTPUT(("ERROR:unknown formating char found - %c", *pText))
|
|
345 |
bufferPos += wlanStrcpy((traceBuffer + bufferPos), pUnknown);
|
|
346 |
/* Break the loop: If we dont know the size of a given argument, we
|
|
347 |
cant know when subsequent arguments start so well have to bail out */
|
|
348 |
error = 1;
|
|
349 |
break;
|
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
if( bufferPos > wlanStrlen(pPrefix) )
|
|
354 |
{
|
|
355 |
wlanPrintOutBuffer(traceBuffer, pPrefix, &bufferPos);
|
|
356 |
}
|
|
357 |
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
|
|
362 |
#define WLAN_BYTES_PER_LINE 32
|
|
363 |
void wlanTraceData(TUint moduleId, const char* const pString, const TUint8* const pData, TUint dataLength)
|
|
364 |
{
|
|
365 |
|
|
366 |
const char* pPrefix = wlanModuleNameStringArray[moduleId];
|
|
367 |
TUint writeCounter = 0;
|
|
368 |
TUint readCounter = 0;
|
|
369 |
TUint numberOfLines = 0;
|
|
370 |
char line[WLAN_BYTES_PER_LINE*3+2]; /* 'XX ' = 3 bytes per input byte +2 for safety */
|
|
371 |
char character;
|
|
372 |
|
|
373 |
Kern::Printf("%s%s - length 0x%X (%d)", pPrefix, pString, dataLength, dataLength);
|
|
374 |
|
|
375 |
if(dataLength == 0 || !pData)
|
|
376 |
{
|
|
377 |
Kern::Printf("%s:zero length", pPrefix);
|
|
378 |
}
|
|
379 |
else
|
|
380 |
{
|
|
381 |
while(readCounter < dataLength)
|
|
382 |
{
|
|
383 |
character = (char)((pData[readCounter] >> 4) & 0x0f);
|
|
384 |
character = (char)(character + ((character < 0x0a) ? 0x30 : 0x37) );
|
|
385 |
line[writeCounter++] = character;
|
|
386 |
|
|
387 |
character = (char)(pData[readCounter] & 0x0f);
|
|
388 |
character = (char)(character + ( (character < 0x0a) ? 0x30 : 0x37) );
|
|
389 |
line[writeCounter++] = character;
|
|
390 |
line[writeCounter++] = ' ';
|
|
391 |
|
|
392 |
if(writeCounter == WLAN_BYTES_PER_LINE*3 /*&& readCounter < dataLength*/)
|
|
393 |
{
|
|
394 |
line[--writeCounter] = '\0';
|
|
395 |
Kern::Printf("%s[%3d]%s", pPrefix, WLAN_BYTES_PER_LINE*numberOfLines, line);
|
|
396 |
numberOfLines++;
|
|
397 |
writeCounter = 0;
|
|
398 |
}
|
|
399 |
readCounter++;
|
|
400 |
}
|
|
401 |
|
|
402 |
if(writeCounter)
|
|
403 |
{
|
|
404 |
line[--writeCounter] = '\0';
|
|
405 |
Kern::Printf("%s[%3d]%s", pPrefix, WLAN_BYTES_PER_LINE*numberOfLines, line);
|
|
406 |
}
|
|
407 |
}
|
|
408 |
}
|
|
409 |
|
|
410 |
void wlanTraceAscii(TUint moduleId, const char* const pString, const TUint8* pBuffer, TUint length)
|
|
411 |
{
|
|
412 |
char* pAscii = (char*)Kern::Alloc(length + 1);
|
|
413 |
TUint i = 0;
|
|
414 |
while(i < length)
|
|
415 |
{
|
|
416 |
pAscii[i++] = *pBuffer++;
|
|
417 |
}
|
|
418 |
pAscii[length] = '\0';
|
|
419 |
Kern::Printf("%s%s - '%s'", wlanModuleNameStringArray[moduleId], pString, pAscii);
|
|
420 |
Kern::Free(pAscii);
|
|
421 |
}
|
|
422 |
|
|
423 |
void wlanTrace(const char* const pFormat, ...)
|
|
424 |
{
|
|
425 |
VA_LIST args;
|
|
426 |
VA_START(args, pFormat);
|
|
427 |
wlanPrintf(wlanModuleNameStringArray[gModuleId], pFormat, args);
|
|
428 |
VA_END(args);
|
|
429 |
}
|
|
430 |
|
|
431 |
void wlanTraceLine(TUint moduleId, ... /* pFunction, line */)
|
|
432 |
{
|
|
433 |
VA_LIST args;
|
|
434 |
VA_START(args, moduleId);
|
|
435 |
wlanPrintf(wlanModuleNameStringArray[moduleId], "%s - line %d", args);
|
|
436 |
VA_END(args);
|
|
437 |
}
|
|
438 |
|
|
439 |
void wlanTraceEnterFn(TUint moduleId, ... /* pFunction */)
|
|
440 |
{
|
|
441 |
VA_LIST args;
|
|
442 |
VA_START(args, moduleId);
|
|
443 |
wlanPrintf(wlanModuleNameStringArray[moduleId], ":%s+", args);
|
|
444 |
VA_END(args);
|
|
445 |
}
|
|
446 |
|
|
447 |
void wlanTraceExitFn(TUint moduleId, ... /* pFunction */)
|
|
448 |
{
|
|
449 |
VA_LIST args;
|
|
450 |
VA_START(args, moduleId);
|
|
451 |
wlanPrintf(wlanModuleNameStringArray[moduleId], ":%s-", args);
|
|
452 |
VA_END(args);
|
|
453 |
}
|
|
454 |
|
|
455 |
void wlanTraceProcess(TUint moduleId, ... /* pFunction, thread */)
|
|
456 |
{
|
|
457 |
VA_LIST args;
|
|
458 |
VA_START(args, moduleId);
|
|
459 |
wlanPrintf(wlanModuleNameStringArray[moduleId], "%s - Thread = 0x%08x", args);
|
|
460 |
VA_END(args);
|
|
461 |
}
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
/*void Assert( const signed char* aFile, int aLine, int aExpression )
|
|
466 |
{
|
|
467 |
|
|
468 |
}
|
|
469 |
|
|
470 |
#endif */ /*_DEBUG */
|
|
471 |
|
|
472 |
|
|
473 |
|