hi_debug.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************************
  2. Copyright (C), 2016, Hisilicon Tech. Co., Ltd.
  3. ******************************************************************************
  4. File Name : hi_debug.h
  5. Version : Initial Draft
  6. Author : Hisilicon multimedia software group
  7. Created : 2016/07/15
  8. Last Modified :
  9. Description : all struct and maro definition for debug
  10. Function List :
  11. ******************************************************************************/
  12. #ifndef __HI_DEBUG_H__
  13. #define __HI_DEBUG_H__
  14. #ifndef __KERNEL__
  15. #include <stdio.h>
  16. #include <stdarg.h>
  17. #endif
  18. #include "hi_type.h"
  19. #include "hi_common.h"
  20. #ifdef __cplusplus
  21. #if __cplusplus
  22. extern "C"{
  23. #endif
  24. #endif /* __cplusplus */
  25. #define _EX__FILE_LINE(fxx,lxx) "[File]:"fxx"\n[Line]:"#lxx"\n[Info]:"
  26. #define EX__FILE_LINE(fxx,lxx) _EX__FILE_LINE(fxx,lxx)
  27. #define __FILE_LINE__ EX__FILE_LINE(__FILE__, __LINE__)
  28. #define HI_DBG_EMERG 0 /* system is unusable */
  29. #define HI_DBG_ALERT 1 /* action must be taken immediately */
  30. #define HI_DBG_CRIT 2 /* critical conditions */
  31. #define HI_DBG_ERR 3 /* error conditions */
  32. #define HI_DBG_WARN 4 /* warning conditions */
  33. #define HI_DBG_NOTICE 5 /* normal but significant condition */
  34. #define HI_DBG_INFO 6 /* informational */
  35. #define HI_DBG_DEBUG 7 /* debug-level messages */
  36. typedef struct hiLOG_LEVEL_CONF_S
  37. {
  38. MOD_ID_E enModId;
  39. HI_S32 s32Level;
  40. HI_CHAR cModName[16];
  41. } LOG_LEVEL_CONF_S;
  42. #ifndef __KERNEL__
  43. /******************************************************************************
  44. ** For User Mode : HI_PRINT, HI_ASSERT, HI_TRACE
  45. ******************************************************************************/
  46. #define HI_PRINT printf
  47. /* #ifdef HI_DEBUG */
  48. #if 1
  49. /* Using samples: HI_ASSERT(x>y); */
  50. #define HI_ASSERT(expr) \
  51. do{ \
  52. if (!(expr)) { \
  53. printf("\nASSERT failed at:\n"\
  54. " >File name: %s\n" \
  55. " >Function : %s\n" \
  56. " >Line No. : %d\n" \
  57. " >Condition: %s\n", \
  58. __FILE__,__FUNCTION__, __LINE__, #expr);\
  59. _exit(-1);\
  60. } \
  61. }while(0)
  62. /* Using samples:
  63. ** HI_TRACE(HI_DBG_DEBUG, HI_ID_CMPI, "Test %d, %s\n", 12, "Test");
  64. **/
  65. #define HI_TRACE(level, enModId, fmt...) fprintf(stderr,##fmt)
  66. #else
  67. #define HI_ASSERT(expr)
  68. #define HI_TRACE(level, enModId, fmt...)
  69. #endif
  70. #else
  71. /******************************************************************************
  72. ** For Linux Kernel : HI_PRINT, HI_ASSERT, HI_TRACE
  73. ******************************************************************************/
  74. //#include "hi_osal.h"
  75. #define HI_PRINT osal_printk
  76. extern HI_S32 HI_ChkLogLevel(HI_S32 s32Levle, MOD_ID_E enModId);
  77. int HI_LOG(HI_S32 level, MOD_ID_E enModId,const char *fmt, ...);
  78. /* #ifdef HI_DEBUG */
  79. #if 1
  80. /* Using samples: HI_ASSERT(x>y); */
  81. #define HI_ASSERT(expr) \
  82. do{ \
  83. if (!(expr)) { \
  84. osal_panic("\nASSERT failed at:\n" \
  85. " >File name: %s\n" \
  86. " >Function : %s\n" \
  87. " >Line No. : %d\n" \
  88. " >Condition: %s\n", \
  89. __FILE__,__FUNCTION__, __LINE__, #expr);\
  90. } \
  91. }while(0)
  92. /* Using samples:
  93. ** HI_TRACE(HI_DBG_DEBUG, HI_ID_CMPI, "Test %d, %s\n", 12, "Test");
  94. **/
  95. #define HI_TRACE HI_LOG
  96. #else
  97. #define HI_ASSERT(expr)
  98. #define HI_TRACE(level, enModId, fmt...)
  99. #endif
  100. #endif /* end of __KERNEL__ */
  101. #define HI_PRINT_BLOCK(pu8Datablock, u32Length) \
  102. { \
  103. HI_U32 u32ii = 0; \
  104. HI_U8* pu8VirAddr = (HI_U8*)(pu8Datablock); \
  105. if(HI_NULL != pu8VirAddr)\
  106. {\
  107. HI_PRINT("\n[Func]:%s [Line]:%d [Info]:%s\n", __FUNCTION__, __LINE__, #pu8Datablock); \
  108. for (u32ii = 0; u32ii < (u32Length);) \
  109. { \
  110. HI_PRINT(" %02X", *pu8VirAddr);\
  111. pu8VirAddr++;\
  112. u32ii++;\
  113. if(0 == (u32ii % 16))HI_PRINT("\n");\
  114. } \
  115. HI_PRINT("\n\n");\
  116. }\
  117. else\
  118. {\
  119. HI_PRINT("\n[Func]:%s [Line]:%d [Info]:pointer(%s) is null!\n", __FUNCTION__, __LINE__, #pu8Datablock); \
  120. }\
  121. }
  122. #ifdef __cplusplus
  123. #if __cplusplus
  124. }
  125. #endif
  126. #endif /* __cplusplus */
  127. #endif /* __HI_DEBUG_H__ */