debug.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. *
  11. * www.optixx.org
  12. *
  13. *
  14. * Version: 1.0
  15. * Created: 07/21/2009 03:32:16 PM
  16. * Author: david@optixx.org
  17. *
  18. * =====================================================================================
  19. */
  20. #include <stdlib.h>
  21. #include <stdint.h>
  22. #include <avr/pgmspace.h>
  23. #include "debug.h"
  24. #include "uart.h"
  25. #include "config.h"
  26. extern FILE uart_stdout;
  27. extern int debug_level; /* the higher, the more messages... */
  28. #if defined(NO_DEBUG) && defined(__GNUC__)
  29. #else
  30. void debug(int level, char *format, ...)
  31. {
  32. #ifdef NO_DEBUG
  33. #else
  34. va_list args;
  35. if (!(debug_level & level))
  36. return;
  37. va_start(args, format);
  38. vprintf(format, args);
  39. va_end(args);
  40. #endif
  41. }
  42. #endif
  43. #ifndef NO_INFO
  44. uint8_t buffer_debug[FORMAT_BUFFER_LEN];
  45. #endif
  46. #if defined(NO_DEBUG) && defined(__GNUC__)
  47. #else
  48. void debug_P(int level, PGM_P format, ...)
  49. {
  50. #ifdef NO_DEBUG
  51. #else
  52. va_list args;
  53. if (!(debug_level & level))
  54. return;
  55. strlcpy_P((char *) buffer_debug, format, FORMAT_BUFFER_LEN);
  56. va_start(args, format);
  57. vprintf((char *) buffer_debug, args);
  58. va_end(args);
  59. #endif
  60. }
  61. #endif