]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/fvid2.git/blob - trace.h
c44da6d94e82588a8084f8fba8e976e4afe43bca
[keystone-rtos/fvid2.git] / trace.h
1 /*
2  *  Copyright (c) Texas Instruments Incorporated 2018
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
33 /**
34  *  \file       trace.h
35  *
36  *  \brief      Kernel Trace enabling/disabling/application interface.
37  *
38  *              This will have the definitions for kernel side traces
39  *              statements and also details of variable traces
40  *              supported in existing implementation.
41  */
43 #ifndef FVID2TRACE_H_
44 #define FVID2TRACE_H_
46 #include <ti/csl/tistdtypes.h>
48  #if defined (USE_STD_ASSERT)
49 #include <assert.h>
50 #endif
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
56 /** \brief The global trace variable containing current trace configuration. */
57 extern int32_t curTrace;
59 /*!
60  *  @def    GT_TRACESTATE_MASK
61  *  @brief  Trace state mask
62  */
63 #define GT_TRACESTATE_MASK                 0x0000000FU
65 /*!
66  *  @def    GT_TRACESTATE_SHIFT
67  *  @brief  Bit shift for trace state
68  */
69 #define GT_TRACESTATE_SHIFT                0U
71 /*!
72  *  @def    GT_TRACEENTER_MASK
73  *  @brief  Trace enter mask
74  */
75 #define GT_TRACEENTER_MASK                 0x000000F0U
77 /*!
78  *  @def    GT_TRACEENTER_SHIFT
79  *  @brief  Bit shift for trace enter
80  */
81 #define GT_TRACEENTER_SHIFT                4U
83 /*!
84  *  @def    GT_TRACESETFAILURE_MASK
85  *  @brief  Trace Set Failure Reason mask
86  */
87 #define GT_TRACESETFAILURE_MASK            0x00000F00U
89 /*!
90  *  @def    GT_TRACESETFAILURE_SHIFT
91  *  @brief  Bit shift for trace Set Failure Reason
92  */
93 #define GT_TRACESETFAILURE_SHIFT           8U
95 /*!
96  *  @def    GT_TRACECLASS_MASK
97  *  @brief  GT class mask
98  */
99 #define GT_TRACECLASS_MASK                 0x000F0000U
101 /*!
102  *  @def    GT_TRACECLASS_SHIFT
103  *  @brief  Bit shift for GT class mask
104  */
105 #define GT_TRACECLASS_SHIFT                16U
107 /*!
108  *  @brief  Default Mask to use with GT_assert
109  */
110 #define GT_DEFAULT_MASK                    (GT_ERR | GT_TraceState_Enable)
112 /*!
113  *  @brief   Enumerates the types of states of trace (enable/disable)
114  */
115 typedef enum {
116     GT_TraceState_Disable = 0x00000000U,
117     /*!< Disable trace */
118     GT_TraceState_Enable = 0x00000001U,
119     /*!< Enable trace */
120     GT_TraceState_EndValue = 0x00000002U
121                              /*!< End delimiter indicating start of invalid
122                               *values for this enum */
123 } GT_TraceState;
125 /*!
126  *  @brief   Enumerates the states of enter/leave trace (enable/disable)
127  */
128 typedef enum {
129     GT_TraceEnter_Disable = 0x00000000U,
130     /*!< Disable GT_ENTER trace prints */
131     GT_TraceEnter_Enable = 0x00000010U,
132     /*!< Enable GT_ENTER trace prints */
133     GT_TraceEnter_EndValue = 0x00000020U
134                              /*!< End delimiter indicating start of invalid
135                               *values for this enum */
136 } GT_TraceEnter;
138 /*!
139  *  @brief   Enumerates the states of SetFailureReason trace (enable/disable)
140  */
141 typedef enum {
142     GT_TraceSetFailure_Disable = 0x00000000U,
143     /*!< Disable Set Failure trace prints */
144     GT_TraceSetFailure_Enable = 0x00000100U,
145     /*!< Enable Set Failure trace prints */
146     GT_TraceSetFailure_EndValue = 0x00000200U
147                                   /*!< End delimiter indicating start of invalid
148                                    *values for this enum */
149 } GT_TraceSetFailure;
151 /*!
152  *  @brief   Enumerates the types of trace classes
153  */
154 typedef enum {
155     GT_ERR = 0x00010000U,
156     /*!< Class 1 trace: Used for errors/warnings */
157     GT_CRIT = 0x00020000U,
158     /*!< Class 2 trace: Used for critical information */
159     GT_INFO = 0x00030000U,
160     /*!< Class 3 trace: Used for additional information */
161     GT_INFO1 = 0x00040000U,
162     /*!< Class 4 trace: Used for additional information (sub level 1) */
163     GT_DEBUG = 0x00050000U,
164     /*!< Class 5 trace: Used for block level information */
165     GT_ENTER = 0x00060000U,
166     /*!< Indicates a function entry class of trace */
167     GT_LEAVE = 0x00070000U
168                /*!< Indicates a function leave class of trace */
169 } GT_TraceClass;
171 /**
172  *  \brief Prints to Shared memory and CCS console
173  *
174  *  This function prints the provided formatted string to shared memory and CCS
175  *  console
176  *
177  *  \param format       [IN] Formatted string followed by variable arguments
178  *
179  */
180 void Fvid2_printf(const char *format, ...);
182 /**
183  *  \brief Prints to Shared memory only
184  *
185  *  This function prints the provided formatted string to shared memory only
186  *
187  *  \param format       [IN] Formatted string followed by variable arguments
188  *
189  */
190 void Fvid2_rprintf(const char *format, ...);
192 /** \brief assert function. */
193 static inline void GT_assertLocal(uint32_t    enableMask,
194                                   uint32_t    condition,
195                                   const char *str,
196                                   const char *fileName,
197                                   int32_t     lineNum);
199 /** \brief GT_assert */
200 #define GT_assert(x, y)                                           \
201     (GT_assertLocal((uint32_t) (x), (uint32_t) (y), (const char *) # y, \
202                     (const char *) __FILE__, (int32_t) __LINE__))
204 static inline void GT_assertLocal(uint32_t    enableMask,
205                                   uint32_t    condition,
206                                   const char *str,
207                                   const char *fileName,
208                                   int32_t     lineNum)
210 #if defined (ASSERT_ENABLE)
211     if ((!(condition)) != 0)
212     {
213         Fvid2_printf(" Assertion @ Line: %d in %s: %s : failed !!!\n",
214                    lineNum, fileName, str);
215  #if defined (USE_STD_ASSERT)
216         assert((!(condition)) != 0);
217  #else
218         while (TRUE)
219         {
220             ;
221         }
222  #endif /* #if defined(USE_STD_ASSERT) */
223     }
224 #endif  /* if defined(ASSERT_ENABLE) */
226     return;
229 #if defined (TRACE_ENABLE)
230 /** \brief Function to report the FVID2 failure and log the trace. */
231 void GT_failureReasonSet(int32_t      enableMask,
232                          const char  *func,
233                          const char  *fileName,
234                          int32_t      lineNum,
235                          uint32_t     status,
236                          const char  *msg);
237 /** \brief Function to report the FVID2 failure and log the trace. */
238 #define GT_setFailureReason(maskType, classType, func, status, msg) \
239     (GT_failureReasonSet((maskType), (const char *) (func),         \
240                          (const char *) __FILE__, (int32_t) __LINE__, \
241                          (status), (const char *) (msg)))
243 #else /* if defined (TRACE_ENABLE) */
245 /** \brief Function to report the FVID2 failure and log the trace. */
246 #define GT_setFailureReason(maskType, classType, func, status, msg) \
247     do {                                                            \
248         if (maskType) {                                             \
249         }                                                           \
250         if (classType) {                                            \
251         }                                                           \
252         if (status) {                                               \
253         }                                                           \
254         if ((uint32_t) (msg)) {                                     \
255         }                                                           \
256     } while (FALSE)
258 #endif /* if defined (TRACE_ENABLE) */
260 /**
261  *  \brief Log the trace with zero parameters and information string.
262  *
263  *  \param  maskType   [IN] Trace mask
264  *  \param  classType  [IN] Trace class type
265  *  \param  fileName   [IN] File Name
266  *  \param  lineNum    [IN] Line Number
267  *  \param  infoString [IN] Print string
268  *
269  */
270 void GT_trace0(uint32_t      maskType,
271                GT_TraceClass classType,
272                const char   *fileName,
273                int32_t       lineNum,
274                const char   *infoString);
275 /**
276  *  \brief Function to log the trace with one additional parameter.
277  *
278  *  \param  maskType   [IN] Trace mask
279  *  \param  classType  [IN] Trace class type
280  *  \param  fileName   [IN] File Name
281  *  \param  lineNum    [IN] Line Number
282  *  \param  infoString [IN] Print string
283  *  \param  param0     [IN] Parameter 0
284  *
285  */
286 void GT_trace1(uint32_t      maskType,
287                GT_TraceClass classType,
288                const char   *fileName,
289                int32_t       lineNum,
290                const char   *infoString,
291                uint32_t      param0);
293 /**
294  *  \brief Function to log the trace with two additional parameters.
295  *
296  *  \param  maskType   [IN] Trace mask
297  *  \param  classType  [IN] Trace class type
298  *  \param  fileName   [IN] File Name
299  *  \param  lineNum    [IN] Line Number
300  *  \param  infoString [IN] Print string
301  *  \param  param0     [IN] Parameter 0
302  *  \param  param1     [IN] Parameter 1
303  *
304  */
305 void GT_trace2(uint32_t      maskType,
306                GT_TraceClass classType,
307                const char   *fileName,
308                int32_t       lineNum,
309                const char   *infoString,
310                uint32_t      param0,
311                uint32_t      param1);
313 /**
314  *  \brief Function to log the trace with three additional parameters.
315  *
316  *  \param  maskType   [IN] Trace mask
317  *  \param  classType  [IN] Trace class type
318  *  \param  fileName   [IN] File Name
319  *  \param  lineNum    [IN] Line Number
320  *  \param  infoString [IN] Print string
321  *  \param  param0     [IN] Parameter 0
322  *  \param  param1     [IN] Parameter 1
323  *  \param  param2     [IN] Parameter 2
324  *
325  */
326 void GT_trace3(uint32_t      maskType,
327                GT_TraceClass classType,
328                const char   *fileName,
329                int32_t       lineNum,
330                const char   *infoString,
331                uint32_t      param0,
332                uint32_t      param1,
333                uint32_t      param2);
335 /**
336  *  \brief Function to log the trace with four additional parameters.
337  *
338  *  \param  maskType   [IN] Trace mask
339  *  \param  classType  [IN] Trace class type
340  *  \param  fileName   [IN] File Name
341  *  \param  lineNum    [IN] Line Number
342  *  \param  infoString [IN] Print string
343  *  \param  param0     [IN] Parameter 0
344  *  \param  param1     [IN] Parameter 1
345  *  \param  param2     [IN] Parameter 2
346  *  \param  param3     [IN] Parameter 3
347  *
348  */
349 void GT_trace4(uint32_t      maskType,
350                GT_TraceClass classType,
351                const char   *fileName,
352                int32_t       lineNum,
353                const char   *infoString,
354                uint32_t      param0,
355                uint32_t      param1,
356                uint32_t      param2,
357                uint32_t      param3);
359 /**
360  *  \brief Function to log the trace with five additional parameters.
361  *
362  *  \param  maskType   [IN] Trace mask
363  *  \param  classType  [IN] Trace class type
364  *  \param  fileName   [IN] File Name
365  *  \param  lineNum    [IN] Line Number
366  *  \param  infoString [IN] Print string
367  *  \param  param0     [IN] Parameter 0
368  *  \param  param1     [IN] Parameter 1
369  *  \param  param2     [IN] Parameter 2
370  *  \param  param3     [IN] Parameter 3
371  *  \param  param4     [IN] Parameter 4
372  *
373  */
374 void GT_trace5(uint32_t      maskType,
375                GT_TraceClass classType,
376                const char   *fileName,
377                int32_t       lineNum,
378                const char   *infoString,
379                uint32_t      param0,
380                uint32_t      param1,
381                uint32_t      param2,
382                uint32_t      param3,
383                uint32_t      param4);
385 /**
386  *  \brief Function to log the trace with six additional parameters.
387  *
388  *  \param  maskType   [IN] Trace mask
389  *  \param  classType  [IN] Trace class type
390  *  \param  fileName   [IN] File Name
391  *  \param  lineNum    [IN] Line Number
392  *  \param  infoString [IN] Print string
393  *  \param  param0     [IN] Parameter 0
394  *  \param  param1     [IN] Parameter 1
395  *  \param  param2     [IN] Parameter 2
396  *  \param  param3     [IN] Parameter 3
397  *  \param  param4     [IN] Parameter 4
398  *  \param  param5     [IN] Parameter 5
399  *
400  */
401 void GT_trace6(uint32_t      maskType,
402                GT_TraceClass classType,
403                const char   *fileName,
404                int32_t       lineNum,
405                const char   *infoString,
406                uint32_t      param0,
407                uint32_t      param1,
408                uint32_t      param2,
409                uint32_t      param3,
410                uint32_t      param4,
411                uint32_t      param5);
413 /**
414  *  \brief Function to log the trace with seven additional parameters.
415  *
416  *  \param  maskType   [IN] Trace mask
417  *  \param  classType  [IN] Trace class type
418  *  \param  fileName   [IN] File Name
419  *  \param  lineNum    [IN] Line Number
420  *  \param  infoString [IN] Print string
421  *  \param  param0     [IN] Parameter 0
422  *  \param  param1     [IN] Parameter 1
423  *  \param  param2     [IN] Parameter 2
424  *  \param  param3     [IN] Parameter 3
425  *  \param  param4     [IN] Parameter 4
426  *  \param  param5     [IN] Parameter 5
427  *  \param  param6     [IN] Parameter 6
428  *
429  */
430 void GT_trace7(uint32_t      maskType,
431                GT_TraceClass classType,
432                const char   *fileName,
433                int32_t       lineNum,
434                const char   *infoString,
435                uint32_t      param0,
436                uint32_t      param1,
437                uint32_t      param2,
438                uint32_t      param3,
439                uint32_t      param4,
440                uint32_t      param5,
441                uint32_t      param6);
443 #if defined (TRACE_ENABLE)
444 /** \brief Log the trace with zero parameters and information string. */
445 #define GT_0trace(maskType, classType, infoString)        \
446     (GT_trace0((maskType), (classType),                   \
447                (const char *) __FILE__, (int32_t) __LINE__, \
448                (const char *) (infoString)))
450 /** \brief Function to log the trace with one additional parameters. */
451 #define GT_1trace(maskType, classType, infoString, param0) \
452     (GT_trace1((maskType), (classType),                    \
453                (const char *) __FILE__, (int32_t) __LINE__,  \
454                (const char *) (infoString), (uint32_t) (param0)))
456 /** \brief Function to log the trace with two additional parameters. */
457 #define GT_2trace(maskType, classType, infoString, param0, param1) \
458     (GT_trace2((maskType), (classType),                            \
459                (const char *) __FILE__, (int32_t) __LINE__,          \
460                (const char *) (infoString), (uint32_t) (param0), (uint32_t) (param1)))
462 /** \brief Function to log the trace with three additional parameters. */
463 #define GT_3trace(maskType, classType, infoString, param0, param1, param2) \
464     (GT_trace3((maskType), (classType),                                    \
465                (const char *) __FILE__, (int32_t) __LINE__,                  \
466                (const char *) (infoString),                                \
467                (uint32_t) (param0),                                          \
468                (uint32_t) (param1),                                          \
469                (uint32_t) (param2)))
471 /** \brief Function to log the trace with four additional parameters. */
472 #define GT_4trace(maskType, classType, infoString,        \
473                   param0, param1, param2, param3)         \
474     (GT_trace4((maskType), (classType),                   \
475                (const char *) __FILE__, (int32_t) __LINE__, \
476                (const char *) (infoString),               \
477                (uint32_t) (param0),                         \
478                (uint32_t) (param1),                         \
479                (uint32_t) (param2),                         \
480                (uint32_t) (param3)))
482 /** \brief Function to log the trace with five additional parameters. */
483 #define GT_5trace(maskType, classType, infoString,        \
484                   param0, param1, param2, param3, param4) \
485     (GT_trace5((maskType), (classType),                   \
486                (const char *) __FILE__, (int32_t) __LINE__, \
487                (const char *) (infoString),               \
488                (uint32_t) (param0),                         \
489                (uint32_t) (param1),                         \
490                (uint32_t) (param2),                         \
491                (uint32_t) (param3),                         \
492                (uint32_t) (param4)))
494 /** \brief Function to log the trace with six additional parameters. */
495 #define GT_6trace(maskType, classType, infoString,                \
496                   param0, param1, param2, param3, param4, param5) \
497     (GT_trace6((maskType), (classType),                           \
498                (const char *) __FILE__, (int32_t) __LINE__,         \
499                (const char *) (infoString),                       \
500                (uint32_t) (param0),                                 \
501                (uint32_t) (param1),                                 \
502                (uint32_t) (param2),                                 \
503                (uint32_t) (param3),                                 \
504                (uint32_t) (param4),                                 \
505                (uint32_t) (param5)))
507 /** \brief Function to log the trace with seven additional parameters. */
508 #define GT_7trace(maskType, classType, infoString,                        \
509                   param0, param1, param2, param3, param4, param5, param6) \
510     (GT_trace7((maskType), (classType),                                   \
511                (const char *) __FILE__, (int32_t) __LINE__,                 \
512                (const char *) (infoString),                               \
513                (uint32_t) (param0),                                         \
514                (uint32_t) (param1),                                         \
515                (uint32_t) (param2),                                         \
516                (uint32_t) (param3),                                         \
517                (uint32_t) (param4),                                         \
518                (uint32_t) (param5),                                         \
519                (uint32_t) (param6)))
521 #else   /* if defined (TRACE_ENABLE) */
523 /** \brief Log the trace with zero parameters and information string. */
524 #define GT_0trace(maskType, classType, infoString)
525 /** \brief Function to log the trace with one additional parameter. */
526 #define GT_1trace(maskType, classType, infoString, param0)
527 /** \brief Function to log the trace with two additional parameters. */
528 #define GT_2trace(maskType, classType, infoString, param0, param1)
529 /** \brief Function to log the trace with three additional parameters. */
530 #define GT_3trace(maskType, classType, infoString, param0, param1, param2)
531 /** \brief Function to log the trace with four additional parameters. */
532 #define GT_4trace(maskType, classType, infoString, param0, param1, param2, \
533                   param3)
534 /** \brief Function to log the trace with five additional parameters. */
535 #define GT_5trace(maskType, classType, infoString, param0, param1, param2, \
536                   param3, param4)
537 /** \brief Function to log the trace with six additional parameters. */
538 #define GT_6trace(maskType, classType, infoString, param0, param1, param2, \
539                   param3, param4, param5)
540 /** \brief Function to log the trace with seven additional parameters. */
541 #define GT_7trace(maskType, classType, infoString, param0, param1, param2, \
542                   param3, param4, param5, param6)
544 #endif  /* if defined (TRACE_ENABLE) */
546 #ifdef __cplusplus
548 #endif
550 #endif /* ifndef FVID2TRACE_H_ */