xref: /OK3568_Linux_fs/external/rockit/mpi/sdk/include/rk_debug.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* GPL-2.0 WITH Linux-syscall-note OR Apache 2.0 */
2 /* Copyright (c) 2021 Fuzhou Rockchip Electronics Co., Ltd */
3 
4 #ifndef INCLUDE_RT_MPI_RK_DEBUG_H_
5 #define INCLUDE_RT_MPI_RK_DEBUG_H_
6 #ifndef __BUILD_KO__
7 #include <stdio.h>
8 #include <stdarg.h>
9 #endif
10 #include "rk_type.h"
11 #include "rk_common.h"
12 
13 #ifdef __cplusplus
14 #if __cplusplus
15 extern "C" {
16 #endif
17 #endif /* __cplusplus */
18 
19 #define RK_DBG_FATAL      1   /* fatal error                          */
20 #define RK_DBG_ERR        2   /* error conditions                     */
21 #define RK_DBG_WARN       3   /* warning conditions                   */
22 #define RK_DBG_INFO       4   /* informational                        */
23 #define RK_DBG_DEBUG      5   /* debug-level messages                 */
24 #define RK_DBG_VERBOSE    6   /* verbose                              */
25 
26 typedef struct rkLOG_LEVEL_CONF_S {
27     MOD_ID_E  enModId;
28     RK_S32    s32Level;
29     RK_CHAR   cModName[16];
30 } LOG_LEVEL_CONF_S;
31 
32 /******************************************************************************
33 ** For User Mode : RK_PRINT, RK_ASSERT, RK_TRACE
34 ******************************************************************************/
35 
36 #define RK_PRINT                     printf
37 
38 #define CONFIG_RK_LOG_TRACE_SUPPORT  1
39 #ifndef DBG_LEVEL
40 #define DBG_LEVEL                    RK_DBG_DEBUG
41 #endif
42 #ifndef DBG_MOD_ID
43 #define DBG_MOD_ID                   RK_ID_CMPI
44 #endif
45 
46 /* #ifdef RK_DEBUG */
47 #ifdef CONFIG_RK_LOG_TRACE_SUPPORT
48     /* Using samples:   RK_ASSERT(x>y); */
49     #define RK_ASSERT(expr)                   \
50         do {                                  \
51             if (!(expr)) {                    \
52                 printf("\nASSERT at:\n"       \
53                     "  >Function : %s\n"      \
54                     "  >Line No. : %d\n"      \
55                     "  >Condition: %s\n",     \
56                     __FUNCTION__, __LINE__, #expr);\
57                 _exit(-1);\
58             } \
59         } while (0)
60 
61     /* Using samples:
62      * RK_TRACE(RK_DBG_DEBUG, "Test %d, %s\n", 12, "Test");
63      */
64     #define RK_TRACE(level, fmt, ...)                       \
65         do {                                                \
66             RK_LOG(level, DBG_MOD_ID, fmt, __FUNCTION__,    \
67                     __LINE__, ##__VA_ARGS__);               \
68         } while (0)
69 #else
70     #define RK_ASSERT(expr)
71     #define RK_TRACE(level, fmt, ...)
72 #endif
73 
74 #define RK_LOGE(fmt, ...)      RK_TRACE(RK_DBG_ERR,     fmt, ##__VA_ARGS__)
75 #define RK_LOGW(fmt, ...)      RK_TRACE(RK_DBG_WARN,    fmt, ##__VA_ARGS__)
76 #define RK_LOGI(fmt, ...)      RK_TRACE(RK_DBG_INFO,    fmt, ##__VA_ARGS__)
77 #define RK_LOGD(fmt, ...)      RK_TRACE(RK_DBG_DEBUG,   fmt, ##__VA_ARGS__)
78 #define RK_LOGV(fmt, ...)      RK_TRACE(RK_DBG_VERBOSE, fmt, ##__VA_ARGS__)
79 
80 void RK_LOG(RK_S32 level, RK_S32 modId, const char *fmt,
81                 const char *fname, const RK_U32 row, ...);
82 
83 #ifdef __cplusplus
84 #if __cplusplus
85 }
86 #endif
87 #endif /* __cplusplus */
88 
89 #endif  // INCLUDE_RT_MPI_RK_DEBUG_H_
90