rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | #ifndef __INC_HIF_TRACE_H |
| 2 | #define __INC_HIF_TRACE_H |
| 3 | |
| 4 | #include "dhl_trace.h" |
| 5 | |
| 6 | /* |
| 7 | * Purpose: |
| 8 | * Allow DHL index trace like message can be shown in console. |
| 9 | * |
| 10 | * Limitation: |
| 11 | * 1. Not support string and floating point format specifiers. |
| 12 | * |
| 13 | * Usage: |
| 14 | * step 1. Define HIF_CONSOLE_TRACE_ENABLED to 1 if you want to print |
| 15 | * dhl_trace() message to console, otherwise, define it to 0 |
| 16 | * |
| 17 | * step 2. Write your own trace message header file and use the |
| 18 | * compiler flag HIF_CONSOLE_TRACE_ENABLED to prevent including |
| 19 | * DHL realted header files. |
| 20 | * |
| 21 | * step 3. Include hif_trace.h and your trace message header file. |
| 22 | * Please note that, except for the trace message header file, |
| 23 | * you are also required to follow follow DHL logging API user |
| 24 | * guide to use DHL logging facilities. |
| 25 | * |
| 26 | * step 4. Use hif_trace_error() and hif_trace_info() to print |
| 27 | * DHL indexed trace like message to console or ELT as you |
| 28 | * specified in step 1. |
| 29 | * |
| 30 | * Example: |
| 31 | * Assume your module ID is MOD_XXX and the file and function prefix is xxx. |
| 32 | * |
| 33 | * In xxx_trace.h |
| 34 | * |
| 35 | * #if HIF_CONSOLE_TRACE_ENABLED != 1 |
| 36 | * #ifndef GEN_FOR_PC |
| 37 | * #include "kal_public_defs.h" |
| 38 | * #endif |
| 39 | * |
| 40 | * #include "dhl_trace.h" |
| 41 | * #include "dhl_def.h" |
| 42 | * |
| 43 | * #if !defined(GEN_FOR_PC) |
| 44 | * #if defined(__DHL_MODULE__) || defined(__CUSTOM_RELEASE__) |
| 45 | * #include "rndis_trace_gen.h" |
| 46 | * #endif |
| 47 | * #endif |
| 48 | * #endif |
| 49 | * BEGIN_TRACE_MAP(MOD_RNDIS) |
| 50 | * TRC_MSG(XXX_SHOW_CODE_MSG_INDEX, "[XXX] xxx_func() got code(%d)") |
| 51 | * TRC_MSG(XXX_ERROR_MSG_INDEX, "[XXX] xxx_func() failed!") |
| 52 | * END_TRACE_MAP(MOD_RNDIS) |
| 53 | * |
| 54 | * In Option.mak: |
| 55 | * |
| 56 | * COMP_TRACE_DEFS += YOUR_MODULE_PATH\include\xxx_trace.h |
| 57 | * |
| 58 | * In xxx_debug.h: |
| 59 | * |
| 60 | * #define HIF_CONSOLE_TRACE_ENABLED 1 |
| 61 | * #include "hif_trace.h" |
| 62 | * #include "xxx_trace.h" |
| 63 | * |
| 64 | * In xxx_yyy.c: |
| 65 | * |
| 66 | * #include "hif_debug.h" |
| 67 | * |
| 68 | * void xxx_func(int code) { |
| 69 | * hif_trace_info(XXX_SHOW_CODE_MSG_INDEX, code); |
| 70 | * if (OK != code) { |
| 71 | * hif_trace_error(XXX_ERROR_MSG_INDEX); |
| 72 | * } |
| 73 | * } |
| 74 | */ |
| 75 | #if HIF_CONSOLE_TRACE_ENABLED==1 |
| 76 | /* |
| 77 | * Print indexed trace to console. |
| 78 | */ |
| 79 | #if defined(__MTK_TARGET__) |
| 80 | #define hif_console_trace dbg_print |
| 81 | #define HIF_NEW_LINE "\r\n" |
| 82 | #else |
| 83 | #define hif_console_trace kal_printf |
| 84 | #define HIF_NEW_LINE "\n" |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__GNUC__) |
| 88 | #define __UNUSED_ATTR__ __attribute__ ((unused)) |
| 89 | #else |
| 90 | #define __UNUSED_ATTR__ |
| 91 | #endif |
| 92 | |
| 93 | #define hif_trace_error(...) hif_console_trace(__VA_ARGS__) |
| 94 | #define hif_trace_info(...) hif_console_trace(__VA_ARGS__) |
| 95 | |
| 96 | #if defined(BEGIN_TRACE_MAP) |
| 97 | #undef BEGIN_TRACE_MAP |
| 98 | #endif |
| 99 | #if defined(TRC_MSG) |
| 100 | #undef TRC_MSG |
| 101 | #endif |
| 102 | #if defined(END_TRACE_MAP) |
| 103 | #undef END_TRACE_MAP |
| 104 | #endif |
| 105 | #define BEGIN_TRACE_MAP(_mod) |
| 106 | #define TRC_MSG(_msg_index, _fmt) static char _msg_index [] __UNUSED_ATTR__ = _fmt HIF_NEW_LINE; |
| 107 | #define END_TRACE_MAP(_mod) |
| 108 | #else |
| 109 | /* |
| 110 | * Use DHL logging. |
| 111 | */ |
| 112 | #define hif_trace_error(trc_name, ...) MD_TRC_##trc_name(__VA_ARGS__) |
| 113 | #define hif_trace_info(trc_name, ...) MD_TRC_##trc_name(__VA_ARGS__) |
| 114 | #define hif_trace_debug(trc_name, ...) MD_TRC_##trc_name(__VA_ARGS__) |
| 115 | #endif /* HIF_CONSOLE_TRACE_ENABLED */ |
| 116 | |
| 117 | #if HIF_DATA_TRACE_ENABLED==1 |
| 118 | #ifdef __MTK_TARGET__ |
| 119 | #define hif_data_trace(FUNC_NAME, ...) do { if(KAL_FALSE == kal_query_systemInit()){FUNC_NAME ( __VA_ARGS__ ) ;} } while (0) |
| 120 | #else |
| 121 | /* |
| 122 | * (2013/08/20) Do to VC compiler bug in variadic macro replacement, it needs to divide Variadic macro into 2 parts to workaround. |
| 123 | * http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement |
| 124 | */ |
| 125 | #define hif_data_trace_arg(FUNC_NAME, args_list) do{ FUNC_NAME args_list ; } while (0) |
| 126 | #define hif_data_trace(FUNC_NAME, ...) do{ hif_data_trace_arg(FUNC_NAME, (__VA_ARGS__)); } while (0) |
| 127 | #endif /* __MTK_TARGET__ */ |
| 128 | #else |
| 129 | #define hif_data_trace(FUNC_NAME, ...) |
| 130 | #endif /* HIF_DATA_TRACE_ENABLED */ |
| 131 | |
| 132 | #if __SENSITIVE_DATA_MOSAIC__ |
| 133 | #define hif_data_trace_usir(FUNC_NAME, ...) do { if(KAL_FALSE == dhl_mask_sensitive_trace_on()){hif_data_trace(FUNC_NAME, __VA_ARGS__);} } while (0) |
| 134 | #else |
| 135 | #define hif_data_trace_usir(FUNC_NAME, ...) hif_data_trace(FUNC_NAME, __VA_ARGS__) |
| 136 | #endif |
| 137 | |
| 138 | #endif /* __INC_HIF_TRACE_H */ |