oddebug.c 973 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. */
  9. #include "oddebug.h"
  10. #if DEBUG_LEVEL > 0
  11. #warning "Never compile production devices with debugging enabled"
  12. static void uartPutc(char c)
  13. {
  14. while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
  15. ODDBG_UDR = c;
  16. }
  17. static uchar hexAscii(uchar h)
  18. {
  19. h &= 0xf;
  20. if(h >= 10)
  21. h += 'a' - (uchar)10 - '0';
  22. h += '0';
  23. return h;
  24. }
  25. static void printHex(uchar c)
  26. {
  27. uartPutc(hexAscii(c >> 4));
  28. uartPutc(hexAscii(c));
  29. }
  30. void odDebug(uchar prefix, uchar *data, uchar len)
  31. {
  32. printHex(prefix);
  33. uartPutc(':');
  34. while(len--){
  35. uartPutc(' ');
  36. printHex(*data++);
  37. }
  38. uartPutc('\r');
  39. uartPutc('\n');
  40. }
  41. #endif