1  /**********************************************************************
2  * Copyright (C) 2014-2015 Cadence Design Systems, Inc.- http://www.cadence.com
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  ***********************************************************************
17  * log.h
18  * System wide debug log messaging framework
19  ***********************************************************************/
20 
21 #ifndef _HAVE_DBG_LOG_
22 
23 #define _HAVE_DBG_LOG_ 1
24 
25 #include <stdio.h>
26 #include <assert.h>
27 
28 #ifdef DEBUG
29  #define CFP_DBG_MSG 1
30 #endif
31 
32 /**
33  * Modules definitions
34  */
35 #define CLIENT_MSG         0x01000000
36 
37 #define DBG_GEN_MSG        0xFFFFFFFF
38 
39 /**
40  * Log level:
41  * DBG_CRIT - critical
42  * DBG_WARN - warning
43  * DBG_FYI - fyi
44  * DBG_HIVERB - highly verbose
45  * DBG_INFLOOP - infinite loop debug
46  */
47 #define DBG_CRIT 0
48 #define DBG_WARN 5
49 #define DBG_FYI 10
50 #define DBG_HIVERB 100
51 #define DBG_INFLOOP 200
52 
53 /* module mask: */
54 #ifdef _HAVE_DBG_LOG_INT_
55 unsigned int g_dbg_enable_log  = 0;
56 #else
57 extern unsigned int g_dbg_enable_log;
58 #endif
59 
60 /* level, counter, state: */
61 #ifdef _HAVE_DBG_LOG_INT_
62 unsigned int g_dbg_log_lvl = DBG_CRIT;
63 unsigned int g_dbg_log_cnt = 0;
64 unsigned int g_dbg_state = 0;
65 #else
66 extern unsigned int g_dbg_log_lvl;
67 extern unsigned int g_dbg_log_cnt;
68 extern unsigned int g_dbg_state;
69 #endif
70 
71 #define cDbgMsg( _t, _x, ...) ( ((_x)==  0) || \
72                                 (((_t) & g_dbg_enable_log) && ((_x) <= g_dbg_log_lvl)) ? \
73                                 printf( __VA_ARGS__): 0 )
74 
75 
76 #ifdef CFP_DBG_MSG
77 #define DbgMsg( t, x, ...)  cDbgMsg( t, x, __VA_ARGS__ )
78 #else
79 #define DbgMsg( t, x, ...)
80 #endif
81 #ifdef CFP_VDBG_MSG
82 #define vDbgMsg( l, m, n, ...) DbgMsg( l, m, "[%-20.20s %4d %4d]-" n, __func__,\
83                                                    __LINE__, g_dbg_log_cnt++, __VA_ARGS__)
84 #else
85 #define vDbgMsg( t, x, n, ...)
86 #endif
87 #ifdef CFP_CVDBG_MSG
88 #define cvDbgMsg( l, m, n, ...) cDbgMsg( l, m, "[%-20.20s %4d %4d]-" n, __func__,\
89                                                    __LINE__, g_dbg_log_cnt++, __VA_ARGS__)
90 #else
91 #define cvDbgMsg( l, m, n, ...)
92 #endif
93 #ifdef CFP_EVDBG_MSG
94 #define evDbgMsg( l, m, n, ...) { cDbgMsg( l, m, "[%-20.20s %4d %4d]-" n, __func__,         \
95                                                    __LINE__, g_dbg_log_cnt++, __VA_ARGS__); \
96                                   assert(0); }
97 #else
98 #define evDbgMsg( l, m, n, ...)
99 #endif
100 
101 #define DbgMsgSetLvl( x ) (g_dbg_log_lvl = x)
102 #define DbgMsgEnableModule( x ) (g_dbg_enable_log |= (x) )
103 #define DbgMsgDisableModule( x ) (g_dbg_enable_log &= ~( (unsigned int) (x) ))
104 #define DbgMsgClearAll( _x ) ( g_dbg_enable_log = _x )
105 
106 #define SetDbgState( _x ) (g_dbg_state = _x )
107 #define GetDbgState       (g_dbg_state)
108 
109 #endif
110