embARC_debug.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* ------------------------------------------
  2. * Copyright (c) 2017, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2017.03
  25. * \date 2014-12-26
  26. * \author Wayne Ren(Wei.Ren@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \file
  30. * \ingroup EMBARC_DEBUG
  31. * \brief necessary definitions of debug
  32. */
  33. #ifndef _EMBARC_DEBUG_H_
  34. #define _EMBARC_DEBUG_H_
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. #ifndef EMBARC_PRINTF
  39. #include "common/xprintf.h"
  40. #define EMBARC_PRINTF xprintf
  41. #endif
  42. /*
  43. * if you want to use DBG or dbg_printf,
  44. * please define DEBUG or DBG_LESS or DBG_MORE before include embARC_debug.h
  45. * DEBUG: enable debug print
  46. * DBG_LESS: enable less debug msg
  47. * DBG_MORE: enable more debug msg
  48. **/
  49. #if defined(DEBUG)
  50. #if defined(DEBUG_HOSTLINK)
  51. #include <stdio.h>
  52. #define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
  53. #else
  54. #define DBG(fmt, ...) EMBARC_PRINTF(fmt, ##__VA_ARGS__)
  55. #endif
  56. #else
  57. #define DBG(fmt, ...)
  58. #endif
  59. #define DBG_LESS_INFO 0x01 /* less debug messages */
  60. #define DBG_MORE_INFO 0x02 /* more debug messages */
  61. #if defined (DBG_LESS)
  62. #define DBG_TYPE (DBG_LESS_INFO)
  63. #elif defined (DBG_MORE)
  64. #define DBG_TYPE ((DBG_LESS_INFO) | (DBG_MORE_INFO))
  65. #else
  66. #define DBG_TYPE 0
  67. #endif
  68. #if DBG_TYPE > 0
  69. #define dbg_printf(type, fmt, ...) \
  70. if (((type) & DBG_TYPE)) { EMBARC_PRINTF(fmt, ##__VA_ARGS__); }
  71. #else
  72. #define dbg_printf(type, fmt, ...)
  73. #endif
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* DEBUG_H_ */