hpidebug.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*****************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Debug macros.
  15. *****************************************************************************/
  16. #ifndef _HPIDEBUG_H
  17. #define _HPIDEBUG_H
  18. #include "hpi_internal.h"
  19. /* Define debugging levels. */
  20. enum { HPI_DEBUG_LEVEL_ERROR = 0, /* always log errors */
  21. HPI_DEBUG_LEVEL_WARNING = 1,
  22. HPI_DEBUG_LEVEL_NOTICE = 2,
  23. HPI_DEBUG_LEVEL_INFO = 3,
  24. HPI_DEBUG_LEVEL_DEBUG = 4,
  25. HPI_DEBUG_LEVEL_VERBOSE = 5 /* same printk level as DEBUG */
  26. };
  27. #define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE
  28. /* an OS can define an extra flag string that is appended to
  29. the start of each message, eg see linux kernel hpios.h */
  30. #ifdef SOURCEFILE_NAME
  31. #define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " "
  32. #else
  33. #define FILE_LINE __FILE__ ":" __stringify(__LINE__) " "
  34. #endif
  35. #define HPI_DEBUG_ASSERT(expression) \
  36. do { \
  37. if (!(expression)) { \
  38. printk(KERN_ERR FILE_LINE \
  39. "ASSERT " __stringify(expression)); \
  40. } \
  41. } while (0)
  42. #define HPI_DEBUG_LOG(level, ...) \
  43. do { \
  44. if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
  45. printk(HPI_DEBUG_FLAG_##level \
  46. FILE_LINE __VA_ARGS__); \
  47. } \
  48. } while (0)
  49. void hpi_debug_init(void);
  50. int hpi_debug_level_set(int level);
  51. int hpi_debug_level_get(void);
  52. /* needed by Linux driver for dynamic debug level changes */
  53. extern int hpi_debug_level;
  54. void hpi_debug_message(struct hpi_message *phm, char *sz_fileline);
  55. void hpi_debug_data(u16 *pdata, u32 len);
  56. #define HPI_DEBUG_DATA(pdata, len) \
  57. do { \
  58. if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \
  59. hpi_debug_data(pdata, len); \
  60. } while (0)
  61. #define HPI_DEBUG_MESSAGE(level, phm) \
  62. do { \
  63. if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
  64. hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \
  65. FILE_LINE __stringify(level)); \
  66. } \
  67. } while (0)
  68. #define HPI_DEBUG_RESPONSE(phr) \
  69. do { \
  70. if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \
  71. (phr->error)) ||\
  72. (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \
  73. printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \
  74. phr->version, phr->error, phr->specific_error); \
  75. } while (0)
  76. #ifndef compile_time_assert
  77. #define compile_time_assert(cond, msg) \
  78. typedef char msg[(cond) ? 1 : -1]
  79. #endif
  80. #endif /* _HPIDEBUG_H_ */