umf_debug.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef _UMF_DEBUG_H_
  2. #define _UMF_DEBUG_H_
  3. #include <drv_debug.h>
  4. extern unsigned int sisdbgconf1;
  5. extern unsigned int sisdbgconf2;
  6. //========================================================================================================
  7. // for console mode debug using
  8. extern char RSTMP[256];
  9. extern void con_SaveDbgMsgtoUSB(unsigned char bTx, short len, unsigned char *pStr);
  10. #define RSDBG(fmt, args...) do {sprintf(RSTMP, "[UMF] " fmt, ## args); con_SaveDbgMsgtoUSB(3, 256, (unsigned char *)RSTMP);}while(0)
  11. //========================================================================================================
  12. #ifndef CONFIG_SUPPORT_DEBUG_MESSAGE
  13. #define UMFDBG(level, fmt, args...)
  14. #define UMFDBG2(level, fmt, args...)
  15. #define DEBUG_ERR(fmt, arg...)
  16. #else
  17. #define UMFDEBUG
  18. #ifdef UMFDEBUG
  19. #define UMFDBG(level, fmt, args...) do {if (sisdbgconf1 & DBGCFG_UMF) fprintf(stderr, "[UMF] " fmt, ## args);}while(0)
  20. //#define UMFDBG(level, fmt, args...) RSDBG(fmt, ##args) // use to save umf debug message to usb.
  21. #define UMFDBG2(level, fmt, args...) do {if (sisdbgconf2 & DBGCFG_UMF) fprintf(stderr, fmt, ## args);}while(0)
  22. #define DEBUG_ERR(fmt, arg...) printf("\33[1;31m[%s:%d]"fmt"\33[0m", __FUNCTION__, __LINE__, ##arg)
  23. #else
  24. #define UMFDBG(level, fmt, args...)
  25. #define UMFDBG2(level, fmt, args...)
  26. #define DEBUG_ERR(fmt, arg...)
  27. #endif
  28. #endif
  29. //========================================================================================================
  30. #define ENABLE_UMFDBG_PRINT_FUNCTION 0
  31. #if ENABLE_UMFDBG_PRINT_FUNCTION
  32. #define UMFDBG_FUNCIN(x) UMFDBG(0, "FUNC ==>, %s\n", __FUNCTION__)
  33. #define UMFDBG_FUNCOUT(x) UMFDBG(0, "<== FUNC, %s %d\n", __FUNCTION__, __LINE__)
  34. #else
  35. #define UMFDBG_FUNCIN(x)
  36. #define UMFDBG_FUNCOUT(x)
  37. #endif
  38. //========================================================================================================
  39. #include <assert.h>
  40. #if 1
  41. #define IS_ARRAY(arr) ((void*)&(arr) == &(arr)[0])
  42. #define STATIC_EXP(e) (0 * sizeof (struct { int ARRAY_SIZE_FAILED:(2 * (e) - 1);}))
  43. #define ARRAY_SIZE(arr) (sizeof(arr)+ STATIC_EXP(IS_ARRAY(arr)))
  44. #define SPRINTF(buf,args...) snprintf(buf,ARRAY_SIZE(buf), ## args)
  45. #define SNPRINTF_PP(buf,args...) snprintf(buf,## args)
  46. #else //like never change
  47. #define ARRAY_SIZE(arr) sizeof(arr)
  48. #define SPRINTF(buf,args...) sprintf(buf, ## args)
  49. #define SNPRINTF_PP(buf,size,args...) sprintf(buf,## args)
  50. #endif
  51. #endif