debug.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. * ___.
  11. * __ __ _____\_ |__
  12. * | | \/ ___/| __ \
  13. * | | /\___ \ | \_\ \
  14. * |____//____ >|___ /
  15. * \/ \/
  16. *
  17. * www.optixx.org
  18. *
  19. *
  20. * Version: 1.0
  21. * Created: 07/21/2009 03:32:16 PM
  22. * Author: david@optixx.org
  23. *
  24. * =====================================================================================
  25. */
  26. #include <stdlib.h>
  27. #include <stdint.h>
  28. #include "debug.h"
  29. #include "uart.h"
  30. extern FILE uart_stdout;
  31. extern int debug_level; /* the higher, the more messages... */
  32. #if defined(NO_DEBUG) && defined(__GNUC__)
  33. /* Nothing. debug has been "defined away" in debug.h already. */
  34. #else
  35. void debug(int level, char* format, ...) {
  36. #ifdef NO_DEBUG
  37. /* Empty body, so a good compiler will optimise calls
  38. to pmesg away */
  39. #else
  40. va_list args;
  41. if (!(debug_level & level))
  42. return;
  43. va_start(args, format);
  44. vprintf(format, args);
  45. va_end(args);
  46. #endif /* NDEBUG */
  47. #endif /* NDEBUG && __GNUC__ */
  48. }