oddebug.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Name: oddebug.c
  2. * Project: AVR library
  3. * Author: Christian Starkjohann
  4. * Creation Date: 2005-01-16
  5. * Tabsize: 4
  6. * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
  7. * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  8. * This Revision: $Id: oddebug.c 692 2008-11-07 15:07:40Z cs $
  9. */
  10. #include "oddebug.h"
  11. #if DEBUG_LEVEL > 0
  12. # warning "Never compile production devices with debugging enabled"
  13. static void uartPutc(char c) {
  14. while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
  15. ; /* wait for data register empty */
  16. ODDBG_UDR = c;
  17. }
  18. static uchar hexAscii(uchar h) {
  19. h &= 0xf;
  20. if (h >= 10) h += 'a' - (uchar)10 - '0';
  21. h += '0';
  22. return h;
  23. }
  24. static void printHex(uchar c) {
  25. uartPutc(hexAscii(c >> 4));
  26. uartPutc(hexAscii(c));
  27. }
  28. void odDebug(uchar prefix, uchar *data, uchar len) {
  29. printHex(prefix);
  30. uartPutc(':');
  31. while (len--) {
  32. uartPutc(' ');
  33. printHex(*data++);
  34. }
  35. uartPutc('\r');
  36. uartPutc('\n');
  37. }
  38. #endif