osi_log.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _OSI_LOG_H_
  13. #define _OSI_LOG_H_
  14. #include <stdarg.h>
  15. #ifndef _MSC_VER
  16. #include "kernel_config.h"
  17. #endif
  18. #include "osi_compiler.h"
  19. #include "quec_proj_config.h"
  20. OSI_EXTERN_C_BEGIN
  21. #ifndef DOXYGEN
  22. #ifndef OSI_LOCAL_LOG_LEVEL
  23. #define OSI_LOCAL_LOG_LEVEL OSI_LOG_LEVEL_INFO
  24. #endif
  25. #ifdef OSI_LOG_DISABLED
  26. #undef OSI_LOCAL_LOG_LEVEL
  27. #define OSI_LOCAL_LOG_LEVEL OSI_LOG_LEVEL_NEVER
  28. #endif
  29. #ifndef OSI_LOCAL_LOG_TAG
  30. #ifdef OSI_LOG_TAG
  31. #define OSI_LOCAL_LOG_TAG OSI_LOG_TAG
  32. #else
  33. #define OSI_LOCAL_LOG_TAG LOG_TAG_NONE
  34. #endif
  35. #endif
  36. #endif
  37. /**
  38. * trace level, larger value is less important
  39. */
  40. enum
  41. {
  42. OSI_LOG_LEVEL_NEVER, ///< only used in control, for not to output trace
  43. OSI_LOG_LEVEL_ERROR, ///< error
  44. OSI_LOG_LEVEL_WARN, ///< warning
  45. OSI_LOG_LEVEL_INFO, ///< information
  46. OSI_LOG_LEVEL_DEBUG, ///< for debug
  47. OSI_LOG_LEVEL_VERBOSE ///< verbose
  48. };
  49. /**
  50. * macro for trace tag
  51. */
  52. #define OSI_MAKE_LOG_TAG(a, b, c, d) ((unsigned)(a) | ((unsigned)(b) << 7) | ((unsigned)(c) << 14) | ((unsigned)(d) << 21))
  53. /**
  54. * macro for extended trace argument types
  55. */
  56. #define OSI_LOGPAR(...) __OSI_LOGPAR(__VA_ARGS__)
  57. /**
  58. * macros for trace level condition
  59. *
  60. * \code{.cpp}
  61. * if (OSI_LOGD_EN) {
  62. * ......
  63. * }
  64. * \endcode
  65. *
  66. * When DEBUG trace is not enabled, the above codes will be expanded as empty.
  67. */
  68. #define OSI_LOGE_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_ERROR)
  69. #define OSI_LOGW_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_WARN)
  70. #define OSI_LOGI_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_INFO)
  71. #define OSI_LOGD_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_DEBUG)
  72. #define OSI_LOGV_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_VERBOSE)
  73. /**
  74. * macros for basic trace
  75. *
  76. * When the trace level is not enabled, the macro will be expanded as empty.
  77. *
  78. * At most 16 arguments are supported.
  79. *
  80. * @param trcid trace ID, 0 for not use trace ID
  81. * @param fmt format string, only used when trace ID is 0
  82. */
  83. #define OSI_LOGE(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_ERROR, trcid, fmt, ##__VA_ARGS__)
  84. #define OSI_LOGW(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_WARN, trcid, fmt, ##__VA_ARGS__)
  85. #define OSI_LOGI(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_INFO, trcid, fmt, ##__VA_ARGS__)
  86. #define OSI_LOGD(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_DEBUG, trcid, fmt, ##__VA_ARGS__)
  87. #define OSI_LOGV(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_VERBOSE, trcid, fmt, ##__VA_ARGS__)
  88. /**
  89. * macros for extended trace
  90. *
  91. * When the trace level is not enabled, the macro will be expanded as empty.
  92. *
  93. * At most 16 arguments are supported.
  94. *
  95. * @param partype arguments types
  96. * @param trcid trace ID, 0 for not use trace ID
  97. * @param fmt format string, only used when trace ID is 0
  98. */
  99. #define OSI_LOGXE(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_ERROR, partype, trcid, fmt, ##__VA_ARGS__)
  100. #define OSI_LOGXW(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_WARN, partype, trcid, fmt, ##__VA_ARGS__)
  101. #define OSI_LOGXI(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_INFO, partype, trcid, fmt, ##__VA_ARGS__)
  102. #define OSI_LOGXD(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_DEBUG, partype, trcid, fmt, ##__VA_ARGS__)
  103. #define OSI_LOGXV(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_VERBOSE, partype, trcid, fmt, ##__VA_ARGS__)
  104. /**
  105. * macros for trace with format string parsing
  106. *
  107. * When the trace level is not enabled, the macro will be expanded as empty.
  108. *
  109. * At most 16 arguments are supported.
  110. *
  111. * @param fmt format string, only used when trace ID is 0
  112. */
  113. #define OSI_PRINTFE(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
  114. #define OSI_PRINTFW(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
  115. #define OSI_PRINTFI(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
  116. #define OSI_PRINTFD(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
  117. #define OSI_PRINTFV(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
  118. /**
  119. * macros for SX style trace and dump
  120. *
  121. * \p id is a complex bit fields. The definition follows SX definition.
  122. */
  123. #define OSI_SXPRINTF(id, fmt, ...) __OSI_SXPRINTF(id, fmt, ##__VA_ARGS__)
  124. #define OSI_SXDUMP(id, fmt, data, size) __OSI_SXDUMP(id, fmt, data, size)
  125. /**
  126. * macros for new SX style trace
  127. *
  128. * Only module level in \p id will be used. When SX style trace is wanted to
  129. * be kept, it is suggested to migrate to these 2 macros.
  130. */
  131. #define OSI_SX_TRACE(id, trcid, fmt, ...) __OSI_SX_TRACE(id, trcid, fmt, ##__VA_ARGS__)
  132. #define OSI_SX_TRACEX(id, partype, trcid, fmt, ...) __OSI_SX_TRACEX(id, partype, trcid, fmt, ##__VA_ARGS__)
  133. /**
  134. * macros for stack trace of pub modules
  135. */
  136. #define OSI_PUB_TRACE(module, category, trcid, fmt, ...) __OSI_PUB_TRACE(module, category, trcid, fmt, ##__VA_ARGS__)
  137. #define OSI_PUB_TRACEX(module, category, partype, trcid, fmt, ...) __OSI_PUB_TRACEX(module, category, partype, trcid, fmt, ##__VA_ARGS__)
  138. /**
  139. * macros for stack trace of lte modules
  140. */
  141. #define OSI_LTE_TRACE(module, category, trcid, fmt, ...) __OSI_LTE_TRACE(module, category, trcid, fmt, ##__VA_ARGS__)
  142. #define OSI_LTE_TRACEX(module, category, partype, trcid, fmt, ...) __OSI_LTE_TRACEX(module, category, partype, trcid, fmt, ##__VA_ARGS__)
  143. /**
  144. * macros for stack trace without module and category control
  145. *
  146. * It is suggested to use these 2 for quick debug only. The above macros
  147. * with module and category control should be used.
  148. */
  149. #define OSI_TRACE(trcid, fmt, ...) __OSI_TRACE(trcid, fmt, ##__VA_ARGS__)
  150. #define OSI_TRACEX(partype, trcid, fmt, ...) __OSI_TRACEX(partype, trcid, fmt, ##__VA_ARGS__)
  151. #define OSI_NAS_TRACE(category, fmtid, fmt, ...) OSI_PUB_TRACE(TRA_NAS, category, fmtid, fmt, ##__VA_ARGS__)
  152. #define OSI_NAS_TRACEX(category, partype, fmtid, fmt, ...) OSI_PUB_TRACEX(TRA_NAS, category, partype, fmtid, fmt, ##__VA_ARGS__)
  153. #define OSI_NAS_TRACE_DUMP(hint_info, dataLen, data) \
  154. OSI_PUB_TRACEX(TRA_NAS, TRA_S1, OSI_LOGPAR_SIM, 0x10007460, "nas_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  155. #define OSI_NASU_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_NASU, category, fmtid, fmt, ##__VA_ARGS__)
  156. #define OSI_NASU_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_NASU, category, partype, fmtid, fmt, ##__VA_ARGS__)
  157. #define OSI_NASU_TRACE_DUMP(hint_info, dataLen, data) \
  158. OSI_LTE_TRACEX(TRA_NAS, TRA_S1, OSI_LOGPAR_SIM, 0x10007461, "rab_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  159. #define OSI_ERRC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_ERRC, category, fmtid, fmt, ##__VA_ARGS__)
  160. #define OSI_ERRC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_ERRC, category, partype, fmtid, fmt, ##__VA_ARGS__)
  161. #define OSI_ERRC_TRACE_DUMP(hint_info, dataLen, data) \
  162. OSI_LTE_TRACEX(TRA_ERRC, TRA_S1, OSI_LOGPAR_SIM, 0x10007462, "errc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  163. #define OSI_LPP_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_LPP, category, fmtid, fmt, ##__VA_ARGS__)
  164. #define OSI_LPP_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_LPP, category, partype, fmtid, fmt, ##__VA_ARGS__)
  165. #define OSI_LPP_TRACE_DUMP(hint_info, dataLen, data) \
  166. OSI_LTE_TRACEX(TRA_LPP, TRA_S1, OSI_LOGPAR_SIM, 0x10007463, "lpp_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  167. #define OSI_EPDC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_EPDC, category, fmtid, fmt, ##__VA_ARGS__)
  168. #define OSI_EPDC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_EPDC, category, partype, fmtid, fmt, ##__VA_ARGS__)
  169. #define OSI_EPDC_TRACE_DUMP(hint_info, dataLen, data) \
  170. OSI_LTE_TRACEX(TRA_EPDC, TRA_S1, OSI_LOGPAR_SIM, 0x10007464, "epdc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  171. #define OSI_ROHC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_ROHC, category, fmtid, fmt, ##__VA_ARGS__)
  172. #define OSI_ROHC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_ROHC, category, partype, fmtid, fmt, ##__VA_ARGS__)
  173. #define OSI_ROHC_TRACE_DUMP(hint_info, dataLen, data) \
  174. OSI_LTE_TRACEX(TRA_ROHC, TRA_S1, OSI_LOGPAR_SIM, 0x10007465, "rohc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  175. #define OSI_ERLC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_ERLC, category, fmtid, fmt, ##__VA_ARGS__)
  176. #define OSI_ERLC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_ERLC, category, partype, fmtid, fmt, ##__VA_ARGS__)
  177. #define OSI_ERLC_TRACE_DUMP(hint_info, dataLen, data) \
  178. OSI_LTE_TRACEX(TRA_ERLC, TRA_S1, OSI_LOGPAR_SIM, 0x10007466, "erlc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  179. #define OSI_EMAC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_EMAC, category, fmtid, fmt, ##__VA_ARGS__)
  180. #define OSI_EMAC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_EMAC, category, partype, fmtid, fmt, ##__VA_ARGS__)
  181. #define OSI_EMAC_TRACE_DUMP(hint_info, dataLen, data) \
  182. OSI_LTE_TRACEX(TRA_EMAC, TRA_S1, OSI_LOGPAR_SIM, 0x10007467, "emac_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  183. #define OSI_NL1C_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_NL1C, category, fmtid, fmt, ##__VA_ARGS__)
  184. #define OSI_NL1C_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_NL1C, category, partype, fmtid, fmt, ##__VA_ARGS__)
  185. #define OSI_NL1C_TRACE_DUMP(hint_info, dataLen, data) \
  186. OSI_LTE_TRACEX(TRA_NL1C, TRA_S1, OSI_LOGPAR_SIM, 0x10007468, "nl1c_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data))
  187. /**
  188. * \brief trace vprintf by parsing format string
  189. *
  190. * This can be used to implement trace functions in third party library.
  191. * When there are chances to modify source codes, the appropriate macros
  192. * from above should be used.
  193. *
  194. * @param tag packed trace tag and trace level
  195. * @param fmt format string
  196. * @param ap variadic argument list
  197. */
  198. void osiTraceVprintf(unsigned tag, const char *fmt, va_list ap);
  199. #include "osi_log_imp.h"
  200. #ifdef CONFIG_FS_TRACE_ENABLE
  201. #include "osi_trace.h"
  202. #endif
  203. OSI_EXTERN_C_END
  204. #endif