mbed_debug.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /** \addtogroup platform */
  2. /** @{*/
  3. /**
  4. * \defgroup platform_debug Debug functions
  5. * @{
  6. */
  7. /* mbed Microcontroller Library
  8. * Copyright (c) 2006-2013 ARM Limited
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. #ifndef MBED_DEBUG_H
  23. #define MBED_DEBUG_H
  24. #if DEVICE_STDIO_MESSAGES
  25. #include <stdio.h>
  26. #include <stdarg.h>
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /** Output a debug message
  32. *
  33. * @param format printf-style format string, followed by variables
  34. */
  35. static inline void debug(const char *format, ...)
  36. {
  37. #if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
  38. va_list args;
  39. va_start(args, format);
  40. vfprintf(stderr, format, args);
  41. va_end(args);
  42. #endif
  43. }
  44. /** Conditionally output a debug message
  45. *
  46. * NOTE: If the condition is constant false (== 0) and the compiler optimization
  47. * level is greater than 0, then the whole function will be compiled away.
  48. *
  49. * @param condition output only if condition is true (!= 0)
  50. * @param format printf-style format string, followed by variables
  51. */
  52. static inline void debug_if(int condition, const char *format, ...)
  53. {
  54. #if DEVICE_STDIO_MESSAGES && !defined(NDEBUG)
  55. if (condition) {
  56. va_list args;
  57. va_start(args, format);
  58. vfprintf(stderr, format, args);
  59. va_end(args);
  60. }
  61. #endif
  62. }
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif
  67. /**@}*/
  68. /**@}*/