1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */ 2 /* 3 * Copyright (c) 2022 Rockchip Electronics Co., Ltd. 4 */ 5 6 #ifndef __MPP_DEBUG_H__ 7 #define __MPP_DEBUG_H__ 8 9 #include <stdlib.h> 10 11 #include "rk_type.h" 12 #include "mpp_err.h" 13 #include "mpp_log.h" 14 15 #define MPP_DBG_TIMING (0x00000001) 16 #define MPP_DBG_PTS (0x00000002) 17 #define MPP_DBG_INFO (0x00000004) 18 #define MPP_DBG_PLATFORM (0x00000010) 19 20 #define MPP_DBG_DUMP_LOG (0x00000100) 21 #define MPP_DBG_DUMP_IN (0x00000200) 22 #define MPP_DBG_DUMP_OUT (0x00000400) 23 #define MPP_DBG_DUMP_CFG (0x00000800) 24 25 #define _mpp_dbg(debug, flag, fmt, ...) mpp_log_c((debug) & (flag), fmt, ## __VA_ARGS__) 26 #define _mpp_dbg_f(debug, flag, fmt, ...) mpp_log_cf((debug) & (flag), fmt, ## __VA_ARGS__) 27 28 #define mpp_dbg(flag, fmt, ...) _mpp_dbg(mpp_debug, flag, fmt, ## __VA_ARGS__) 29 #define mpp_dbg_f(flag, fmt, ...) _mpp_dbg_f(mpp_debug, flag, fmt, ## __VA_ARGS__) 30 31 #define mpp_dbg_pts(fmt, ...) mpp_dbg(MPP_DBG_PTS, fmt, ## __VA_ARGS__) 32 #define mpp_dbg_info(fmt, ...) mpp_dbg(MPP_DBG_INFO, fmt, ## __VA_ARGS__) 33 #define mpp_dbg_platform(fmt, ...) mpp_dbg(MPP_DBG_PLATFORM, fmt, ## __VA_ARGS__) 34 35 #define MPP_ABORT (0x10000000) 36 37 /* 38 * mpp_dbg usage: 39 * 40 * in h264d module define module debug flag variable like: h265d_debug 41 * then define h265d_dbg macro as follow : 42 * 43 * extern RK_U32 h265d_debug; 44 * 45 * #define H265D_DBG_FUNCTION (0x00000001) 46 * #define H265D_DBG_VPS (0x00000002) 47 * #define H265D_DBG_SPS (0x00000004) 48 * #define H265D_DBG_PPS (0x00000008) 49 * #define H265D_DBG_SLICE_HDR (0x00000010) 50 * 51 * #define h265d_dbg(flag, fmt, ...) mpp_dbg(h265d_debug, flag, fmt, ## __VA_ARGS__) 52 * 53 * finally use environment control the debug flag 54 * 55 * mpp_get_env_u32("h264d_debug", &h265d_debug, 0) 56 * 57 */ 58 /* 59 * sub-module debug flag usage example: 60 * +------+-------------------+ 61 * | 8bit | 24bit | 62 * +------+-------------------+ 63 * 0~15 bit: software debug print 64 * 16~23 bit: hardware debug print 65 * 24~31 bit: information print format 66 */ 67 68 #define mpp_abort() do { \ 69 if (mpp_debug & MPP_ABORT) { \ 70 abort(); \ 71 } \ 72 } while (0) 73 74 #define MPP_STRINGS(x) MPP_TO_STRING(x) 75 #define MPP_TO_STRING(x) #x 76 77 #define mpp_assert(cond) do { \ 78 if (!(cond)) { \ 79 mpp_err("Assertion %s failed at %s:%d\n", \ 80 MPP_STRINGS(cond), __FUNCTION__, __LINE__); \ 81 mpp_abort(); \ 82 } \ 83 } while (0) 84 85 /* llog for long log */ 86 87 #define mpp_llogf(fmt, ...) mpp_llog(MPP_LOG_FATAL, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 88 #define mpp_lloge(fmt, ...) mpp_llog(MPP_LOG_ERROR, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 89 #define mpp_llogw(fmt, ...) mpp_llog(MPP_LOG_WARN, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 90 #define mpp_llogi(fmt, ...) mpp_llog(MPP_LOG_INFO, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 91 #define mpp_llogd(fmt, ...) mpp_llog(MPP_LOG_DEBUG, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 92 #define mpp_llogv(fmt, ...) mpp_llog(MPP_LOG_VERBOSE, MODULE_TAG, fmt, NULL, ## __VA_ARGS__) 93 94 #define mpp_llogf_f(fmt, ...) mpp_llog(MPP_LOG_FATAL, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 95 #define mpp_lloge_f(fmt, ...) mpp_llog(MPP_LOG_ERROR, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 96 #define mpp_llogw_f(fmt, ...) mpp_llog(MPP_LOG_WARN, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 97 #define mpp_llogi_f(fmt, ...) mpp_llog(MPP_LOG_INFO, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 98 #define mpp_llogd_f(fmt, ...) mpp_llog(MPP_LOG_DEBUG, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 99 #define mpp_llogv_f(fmt, ...) mpp_llog(MPP_LOG_VERBOSE, MODULE_TAG, fmt, __FUNCTION__, ## __VA_ARGS__) 100 101 #ifdef __cplusplus 102 extern "C" { 103 #endif 104 105 extern RK_U32 mpp_debug; 106 void mpp_llog(int level, const char *tag, const char *fmt, const char *func, ...); 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #endif /*__MPP_DEBUG_H__*/ 113