debug.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "debug.h"
  23. #include "uart.h"
  24. extern FILE uart_stdout;
  25. extern int debug_level; /* the higher, the more messages... */
  26. #if defined(NO_DEBUG) && defined(__GNUC__)
  27. /* Nothing. debug has been "defined away" in debug.h already. */
  28. #else
  29. void debug(int level, char* format, ...) {
  30. #ifdef NO_DEBUG
  31. /* Empty body, so a good compiler will optimise calls
  32. to pmesg away */
  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 /* NDEBUG */
  41. #endif /* NDEBUG && __GNUC__ */
  42. }