您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

oddebug.c 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. {
  15. while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
  16. ODDBG_UDR = c;
  17. }
  18. static uchar hexAscii(uchar h)
  19. {
  20. h &= 0xf;
  21. if(h >= 10)
  22. h += 'a' - (uchar)10 - '0';
  23. h += '0';
  24. return h;
  25. }
  26. static void printHex(uchar c)
  27. {
  28. uartPutc(hexAscii(c >> 4));
  29. uartPutc(hexAscii(c));
  30. }
  31. void odDebug(uchar prefix, uchar *data, uchar len)
  32. {
  33. printHex(prefix);
  34. uartPutc(':');
  35. while(len--){
  36. uartPutc(' ');
  37. printHex(*data++);
  38. }
  39. uartPutc('\r');
  40. uartPutc('\n');
  41. }
  42. #endif