d789b90718d3040a6b6a7e20ee6e92011ab928be
1 /*
2 * @file Trace.c
3 *
4 * @brief Trace implementation.
5 *
6 * This abstracts and implements the definitions for
7 * user side traces statements and also details
8 * of variable traces supported in existing
9 * implementation.
10 *
11 *
12 * @ver 02.00.00.46_alpha1
13 *
14 * ============================================================================
15 *
16 * Copyright (c) 2008-2015, Texas Instruments Incorporated
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 *
22 * * Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 *
25 * * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * * Neither the name of Texas Instruments Incorporated nor the names of
30 * its contributors may be used to endorse or promote products derived
31 * from this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
35 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
40 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
41 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
42 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * Contact information for paper mail:
45 * Texas Instruments
46 * Post Office Box 655303
47 * Dallas, Texas 75265
48 * Contact information:
49 * http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
50 * DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
51 * ============================================================================
52 *
53 */
56 /* Standard headers */
57 #include <ti/syslink/Std.h>
59 /* OSAL and kernel utils */
60 #include <ti/syslink/utils/Trace.h>
61 #include <TraceDrv.h>
62 #include <TraceDrvDefs.h>
63 #include <ti/syslink/utils/OsalPrint.h>
65 #if defined (__cplusplus)
66 extern "C" {
67 #endif
70 /*!
71 * @brief Global trace flag.
72 * Enable failure traces by default.
73 */
74 Int curTrace = -1;//(GT_TraceState_Enable << GT_TRACESETFAILURE_SHIFT);
76 int GT_getMask(void)
77 {
78 if (curTrace == -1) {
79 char *val = getenv("IPC_DEBUG_TRACE_LEVEL");
80 int envTrace = val ? strtol(val, NULL, 0) : 2;
81 curTrace = 0;
82 switch (envTrace) {
83 case 7:
84 curTrace |= (GT_TraceState_Enable << GT_TRACESTATE_SHIFT);
85 curTrace |= (GT_TraceState_Enable << GT_TRACEENTER_SHIFT);
86 case 6:
87 curTrace |= (GT_TraceState_Enable << GT_TRACESTATE_SHIFT);
88 curTrace = (curTrace & ~GT_TRACECLASS_MASK) | (GT_1CLASS);
89 case 5:
90 curTrace |= (GT_TraceState_Enable << GT_TRACESTATE_SHIFT);
91 if (!(curTrace & GT_TRACECLASS_MASK))
92 curTrace = (curTrace & ~GT_TRACECLASS_MASK) | (GT_2CLASS);
93 case 4:
94 curTrace |= (GT_TraceState_Enable << GT_TRACESTATE_SHIFT);
95 if (!(curTrace & GT_TRACECLASS_MASK))
96 curTrace = (curTrace & ~GT_TRACECLASS_MASK) | (GT_3CLASS);
97 case 3:
98 case 2:
99 case 1:
100 case 0:
101 default:
102 curTrace |= (GT_TraceState_Enable << GT_TRACESTATE_SHIFT);
103 if (!(curTrace & GT_TRACECLASS_MASK))
104 curTrace = (curTrace & ~GT_TRACECLASS_MASK) | (GT_4CLASS);
105 curTrace |= (GT_TraceState_Enable << GT_TRACESETFAILURE_SHIFT);
106 break;
107 }
108 }
109 return curTrace;
110 }
112 /*!
113 * @brief Function to log the trace with zero parameters and just
114 * information string.
115 * @param mask type of traces.
116 * @param classtype One of three classes in Ipc where this trace need
117 * to be enabed.
118 * @param The debug string.
119 */
120 Void
121 _GT_0trace (UInt32 mask, GT_TraceClass classtype, Char * infoString)
122 {
123 /* Check if trace is enabled. */
124 mask = GT_getMask();
125 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
126 == GT_TraceState_Enable) {
127 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
128 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
129 Osal_printf (infoString);
130 }
131 }
132 else {
133 /* Check if specified class is enabled. */
134 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
135 /* Print if specified class is greater than or equal to class
136 * for this specific print.
137 */
138 Osal_printf (infoString);
139 }
140 }
141 }
142 }
145 /*!
146 * @brief Function to log the trace with one additional parameter
147 * @param mask type of traces
148 * @param classtype One of three classes in Ipc where this trace
149 * need to be enabed.
150 * @param The debug string.
151 * @param param The additional parameter which needs to be logged.
152 */
153 Void
154 _GT_1trace (UInt32 mask,
155 GT_TraceClass classtype,
156 Char * infoString,
157 UInt32 param)
158 {
159 /* Check if trace is enabled. */
160 mask = GT_getMask();
161 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
162 == GT_TraceState_Enable) {
163 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
164 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
165 Osal_printf (infoString, param);
166 }
167 }
168 else {
169 /* Check if specified class is enabled. */
170 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
171 /* Print if specified class is greater than or equal to class
172 * for this specific print.
173 */
174 Osal_printf (infoString, param);
175 }
176 }
177 }
178 }
181 /*!
182 * @brief Function to log the trace with two additional parameters
183 * @param mask type of traces
184 * @param classtype One of three classes in Ipc where this trace
185 * need to be enabed.
186 * @param The debug string.
187 * @param param0 The first parameter which needs to be logged.
188 * @param param1 The second parameter which needs to be logged.
189 */
190 Void
191 _GT_2trace (UInt32 mask,
192 GT_TraceClass classtype,
193 Char * infoString,
194 UInt32 param0,
195 UInt32 param1)
196 {
197 /* Check if trace is enabled. */
198 mask = GT_getMask();
199 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
200 == GT_TraceState_Enable) {
201 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
202 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
203 Osal_printf (infoString, param0, param1);
204 }
205 }
206 else {
207 /* Check if specified class is enabled. */
208 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
209 /* Print if specified class is greater than or equal to class
210 * for this specific print.
211 */
212 Osal_printf (infoString, param0, param1);
213 }
214 }
215 }
216 }
219 /*!
220 * @brief Function to log the trace with three parameters.
221 * @param mask type of traces
222 * @param classtype One of three classes in Ipc where this trace
223 * need to be enabed.
224 * @param The debug string.
225 * @param param0 The first parameter which needs to be logged.
226 * @param param1 The second parameter which needs to be logged.
227 * @param param2 The third parameter which needs to be logged.
228 */
229 Void
230 _GT_3trace (UInt32 mask,
231 GT_TraceClass classtype,
232 Char* infoString,
233 UInt32 param0,
234 UInt32 param1,
235 UInt32 param2)
236 {
237 /* Check if trace is enabled. */
238 mask = GT_getMask();
239 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
240 == GT_TraceState_Enable) {
241 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
242 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
243 Osal_printf (infoString, param0, param1, param2);
244 }
245 }
246 else {
247 /* Check if specified class is enabled. */
248 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
249 /* Print if specified class is greater than or equal to class
250 * for this specific print.
251 */
252 Osal_printf (infoString, param0, param1, param2);
253 }
254 }
255 }
256 }
259 /*!
260 * @brief Function to log the trace with four parameters.
261 * @param mask type of traces
262 * @param classtype One of three classes in Ipc where this trace
263 * need to be enabed.
264 * @param The debug string.
265 * @param param0 The first parameter which needs to be logged.
266 * @param param1 The second parameter which needs to be logged.
267 * @param param2 The third parameter which needs to be logged.
268 * @param param3 The fourth parameter which needs to be logged.
269 */
270 Void
271 _GT_4trace (UInt32 mask,
272 GT_TraceClass classtype,
273 Char* infoString,
274 UInt32 param0,
275 UInt32 param1,
276 UInt32 param2,
277 UInt32 param3)
278 {
279 /* Check if trace is enabled. */
280 mask = GT_getMask();
281 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
282 == GT_TraceState_Enable) {
283 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
284 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
285 Osal_printf (infoString, param0, param1, param2, param3);
286 }
287 }
288 else {
289 /* Check if specified class is enabled. */
290 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
291 /* Print if specified class is greater than or equal to class
292 * for this specific print.
293 */
294 Osal_printf (infoString, param0, param1, param2, param3);
295 }
296 }
297 }
298 }
301 /*!
302 * @brief Function to log the trace with five parameters.
303 * @param mask type of traces
304 * @param classtype One of three classes in Ipc where this trace
305 * need to be enabed.
306 * @param The debug string.
307 * @param param0 The first parameter which needs to be logged.
308 * @param param1 The second parameter which needs to be logged.
309 * @param param2 The third parameter which needs to be logged.
310 * @param param3 The fourth parameter which needs to be logged.
311 * @param param4 The fifth parameter which needs to be logged.
312 */
313 Void
314 _GT_5trace (UInt32 mask,
315 GT_TraceClass classtype,
316 Char* infoString,
317 UInt32 param0,
318 UInt32 param1,
319 UInt32 param2,
320 UInt32 param3,
321 UInt32 param4)
322 {
323 /* Check if trace is enabled. */
324 mask = GT_getMask();
325 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
326 == GT_TraceState_Enable) {
327 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
328 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
329 Osal_printf (infoString,
330 param0,
331 param1,
332 param2,
333 param3,
334 param4);
335 }
336 }
337 else {
338 /* Check if specified class is enabled. */
339 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
340 /* Print if specified class is greater than or equal to class
341 * for this specific print.
342 */
343 Osal_printf (infoString,
344 param0,
345 param1,
346 param2,
347 param3,
348 param4);
349 }
350 }
351 }
352 }
355 /*!
356 * @brief Function to log the trace with six parameters.
357 * @param mask type of traces
358 * @param classtype One of three classes in Ipc where this trace
359 * need to be enabed.
360 * @param The debug string.
361 * @param param0 The first parameter which needs to be logged.
362 * @param param1 The second parameter which needs to be logged.
363 * @param param2 The third parameter which needs to be logged.
364 * @param param3 The fourth parameter which needs to be logged.
365 * @param param4 The fifth parameter which needs to be logged.
366 * @param param5 The sixth parameter which needs to be logged.
367 */
368 Void
369 _GT_6trace (UInt32 mask,
370 GT_TraceClass classtype,
371 Char* infoString,
372 UInt32 param0,
373 UInt32 param1,
374 UInt32 param2,
375 UInt32 param3,
376 UInt32 param4,
377 UInt32 param5)
378 {
379 /* Check if trace is enabled. */
380 mask = GT_getMask();
381 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
382 == GT_TraceState_Enable) {
383 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
384 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
385 Osal_printf (infoString,
386 param0,
387 param1,
388 param2,
389 param3,
390 param4,
391 param5);
392 }
393 }
394 else {
395 /* Check if specified class is enabled. */
396 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
397 /* Print if specified class is greater than or equal to class
398 * for this specific print.
399 */
400 Osal_printf (infoString,
401 param0,
402 param1,
403 param2,
404 param3,
405 param4,
406 param5);
407 }
408 }
409 }
410 }
413 /*!
414 * @brief Function to log the trace with six parameters.
415 * @param mask type of traces
416 * @param classtype One of three classes in Ipc where this trace
417 * need to be enabed.
418 * @param The debug string.
419 * @param param0 The first parameter which needs to be logged.
420 * @param param1 The second parameter which needs to be logged.
421 * @param param2 The third parameter which needs to be logged.
422 * @param param3 The fourth parameter which needs to be logged.
423 * @param param4 The fifth parameter which needs to be logged.
424 * @param param5 The sixth parameter which needs to be logged.
425 * @param param6 The seventh parameter which needs to be logged.
426 */
427 Void
428 _GT_7trace (UInt32 mask,
429 GT_TraceClass classtype,
430 Char* infoString,
431 UInt32 param0,
432 UInt32 param1,
433 UInt32 param2,
434 UInt32 param3,
435 UInt32 param4,
436 UInt32 param5,
437 UInt32 param6)
438 {
439 /* Check if trace is enabled. */
440 mask = GT_getMask();
441 if ( ((mask & GT_TRACESTATE_MASK) >> GT_TRACESTATE_SHIFT)
442 == GT_TraceState_Enable) {
443 if ((classtype == GT_ENTER) || (classtype == GT_LEAVE)) {
444 if ((mask & GT_TRACEENTER_MASK) == GT_TraceEnter_Enable) {
445 Osal_printf (infoString,
446 param0,
447 param1,
448 param2,
449 param3,
450 param4,
451 param5,
452 param6);
453 }
454 }
455 else {
456 /* Check if specified class is enabled. */
457 if ((mask & GT_TRACECLASS_MASK) <= classtype) {
458 /* Print if specified class is greater than or equal to class
459 * for this specific print.
460 */
461 Osal_printf (infoString,
462 param0,
463 param1,
464 param2,
465 param3,
466 param4,
467 param5,
468 param6);
469 }
470 }
471 }
472 }
475 /*!
476 * @brief Function to report the ipc failure and log the trace. This
477 * is mostly the fatal error and system can not recover without
478 * module restart.
479 * @param mask Indicates whether SetFailure is enabled.
480 * @param func Name of the function where this oc.cured
481 * @param fileName Where the condition has occured.
482 * @param lineNo Line number of the current file where this failure
483 * has occured.
484 * @param status What was the code we got/set for this failure
485 * @param msg Any additional information which can be useful for
486 * deciphering the error condition.
487 */
488 Void _GT_setFailureReason (Int mask,
489 Char * func,
490 Char * fileName,
491 UInt32 lineNo,
492 UInt32 status,
493 Char * msg)
494 {
495 mask = GT_getMask();
496 if ( ((mask & GT_TRACESETFAILURE_MASK) >> GT_TRACESETFAILURE_SHIFT)
497 == GT_TraceState_Enable) {
498 Osal_printf ("*** %s: %s\tError [0x%x] at Line no: %d in file %s\n",
499 func,
500 msg,
501 status,
502 lineNo,
503 fileName);
504 }
505 }
508 /*!
509 * @brief Function to change the trace mask setting.
510 *
511 * @param mask Trace mask to be set
512 * @param type Type of trace to be set
513 */
514 UInt32 _GT_setTrace (UInt32 mask, GT_TraceType type)
515 {
516 TraceDrv_CmdArgs cmdArgs;
518 GT_1trace (curTrace, GT_1CLASS, "Setting Trace to: [0x%x]\n", mask);
520 cmdArgs.args.setTrace.mask = mask;
521 cmdArgs.args.setTrace.type = type;
522 TraceDrv_ioctl (CMD_TRACEDRV_SETTRACE, &cmdArgs);
524 /*! @retval old-mask Operation successfully completed. */
525 return cmdArgs.args.setTrace.oldMask;
526 }
529 #if defined (__cplusplus)
530 }
531 #endif /* defined (__cplusplus) */