1 /*
2  * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __MPP_LOG_H__
17 #define __MPP_LOG_H__
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 
22 #include "rk_type.h"
23 
24 /*
25  * mpp runtime log system usage:
26  * mpp_err is for error status message, it will print for sure.
27  * mpp_log is for important message like open/close/reset/flush, it will print too.
28  * mpp_dbg is for all optional message. it can be controlled by debug and flag.
29  */
30 
31 #define mpp_log(fmt, ...)   _mpp_log(MODULE_TAG, fmt, NULL, ## __VA_ARGS__)
32 #define mpp_err(fmt, ...)   _mpp_err(MODULE_TAG, fmt, NULL, ## __VA_ARGS__)
33 
34 #define _mpp_dbg( flag, fmt, ...) \
35     do { \
36             if ( flag) \
37             mpp_log(fmt, ## __VA_ARGS__); \
38     } while (0)
39 
40 #define mpp_dbg(flag, fmt, ...) _mpp_dbg(flag, fmt, ## __VA_ARGS__)
41 
42 /*
43  * _f function will add function name to the log
44  */
45 #define mpp_log_f(fmt, ...)  _mpp_log(MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__)
46 #define mpp_err_f(fmt, ...)  _mpp_err(MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__)
47 #define _mpp_dbg_f(flag, fmt, ...) \
48     do { \
49             if ( flag) \
50             mpp_log_f(fmt, ## __VA_ARGS__); \
51     } while (0)
52 
53 #define mpp_dbg_f(flag, fmt, ...) _mpp_dbg_f(flag, fmt, ## __VA_ARGS__)
54 
55 
56 #define MPP_DBG_TIMING                  (0x00000001)
57 #define MPP_DBG_PTS                     (0x00000002)
58 #define MPP_DBG_INFO                    (0x00000004)
59 #define MPP_DBG_PLATFORM                (0x00000010)
60 
61 #define MPP_DBG_DUMP_LOG                (0x00000100)
62 #define MPP_DBG_DUMP_IN                 (0x00000200)
63 #define MPP_DBG_DUMP_OUT                (0x00000400)
64 #define MPP_DBG_DUMP_CFG                (0x00000800)
65 
66 #define mpp_dbg_pts(fmt, ...)           mpp_dbg(MPP_DBG_PTS, fmt, ## __VA_ARGS__)
67 #define mpp_dbg_info(fmt, ...)          mpp_dbg(MPP_DBG_INFO, fmt, ## __VA_ARGS__)
68 #define mpp_dbg_platform(fmt, ...)      mpp_dbg(MPP_DBG_PLATFORM, fmt, ## __VA_ARGS__)
69 
70 #define MPP_ABORT                       (0x10000000)
71 
72 /*
73  * mpp_dbg usage:
74  *
75  * in h264d module define module debug flag variable like: h265d_debug
76  * then define h265d_dbg macro as follow :
77  *
78  * extern RK_U32 h265d_debug;
79  *
80  * #define H265D_DBG_FUNCTION          (0x00000001)
81  * #define H265D_DBG_VPS               (0x00000002)
82  * #define H265D_DBG_SPS               (0x00000004)
83  * #define H265D_DBG_PPS               (0x00000008)
84  * #define H265D_DBG_SLICE_HDR         (0x00000010)
85  *
86  * #define h265d_dbg(flag, fmt, ...) mpp_dbg(h265d_debug, flag, fmt, ## __VA_ARGS__)
87  *
88  * finally use environment control the debug flag
89  *
90  * mpp_get_env_u32("h264d_debug", &h265d_debug, 0)
91  *
92  */
93 /*
94  * sub-module debug flag usage example:
95  * +------+-------------------+
96  * | 8bit |      24bit        |
97  * +------+-------------------+
98  *  0~15 bit: software debug print
99  * 16~23 bit: hardware debug print
100  * 24~31 bit: information print format
101  */
102 
103 #define mpp_abort() do {                \
104     if ( MPP_ABORT) {        \
105         abort();                        \
106     }                                   \
107 } while (0)
108 
109 #define MPP_STRINGS(x)      MPP_TO_STRING(x)
110 #define MPP_TO_STRING(x)    #x
111 
112 #define mpp_assert(cond) do {                                           \
113     if (!(cond)) {                                                      \
114         mpp_err("Assertion %s failed at %s:%d\n",                       \
115                MPP_STRINGS(cond), __FUNCTION__, __LINE__);              \
116         mpp_abort();                                                    \
117     }                                                                   \
118 } while (0)
119 
120 
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
124 
125 
126 void mpp_log_set_flag(RK_U32 flag);
127 RK_U32 mpp_log_get_flag(void);
128 
129 void _mpp_log(const char *tag, const char *fmt, const char *func, ...);
130 void _mpp_err(const char *tag, const char *fmt, const char *func, ...);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* __MPP_LOG_H__ */
137