You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

oddebug.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Name: oddebug.h
  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.h 692 2008-11-07 15:07:40Z cs $
  9. */
  10. #ifndef __oddebug_h_included__
  11. #define __oddebug_h_included__
  12. /*
  13. General Description:
  14. This module implements a function for debug logs on the serial line of the
  15. AVR microcontroller. Debugging can be configured with the define
  16. 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
  17. calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
  18. 2, DBG1 and DBG2 logs will be printed.
  19. A debug log consists of a label ('prefix') to indicate which debug log created
  20. the output and a memory block to dump in hex ('data' and 'len').
  21. */
  22. #ifndef F_CPU
  23. # define F_CPU 12000000 /* 12 MHz */
  24. #endif
  25. /* make sure we have the UART defines: */
  26. #include "usbportability.h"
  27. #ifndef uchar
  28. # define uchar unsigned char
  29. #endif
  30. #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
  31. # warning "Debugging disabled because device has no UART"
  32. # undef DEBUG_LEVEL
  33. #endif
  34. #ifndef DEBUG_LEVEL
  35. # define DEBUG_LEVEL 0
  36. #endif
  37. /* ------------------------------------------------------------------------- */
  38. #if DEBUG_LEVEL > 0
  39. # define DBG1(prefix, data, len) odDebug(prefix, data, len)
  40. #else
  41. # define DBG1(prefix, data, len)
  42. #endif
  43. #if DEBUG_LEVEL > 1
  44. # define DBG2(prefix, data, len) odDebug(prefix, data, len)
  45. #else
  46. # define DBG2(prefix, data, len)
  47. #endif
  48. /* ------------------------------------------------------------------------- */
  49. #if DEBUG_LEVEL > 0
  50. extern void odDebug(uchar prefix, uchar *data, uchar len);
  51. /* Try to find our control registers; ATMEL likes to rename these */
  52. #if defined UBRR
  53. # define ODDBG_UBRR UBRR
  54. #elif defined UBRRL
  55. # define ODDBG_UBRR UBRRL
  56. #elif defined UBRR0
  57. # define ODDBG_UBRR UBRR0
  58. #elif defined UBRR0L
  59. # define ODDBG_UBRR UBRR0L
  60. #endif
  61. #if defined UCR
  62. # define ODDBG_UCR UCR
  63. #elif defined UCSRB
  64. # define ODDBG_UCR UCSRB
  65. #elif defined UCSR0B
  66. # define ODDBG_UCR UCSR0B
  67. #endif
  68. #if defined TXEN
  69. # define ODDBG_TXEN TXEN
  70. #else
  71. # define ODDBG_TXEN TXEN0
  72. #endif
  73. #if defined USR
  74. # define ODDBG_USR USR
  75. #elif defined UCSRA
  76. # define ODDBG_USR UCSRA
  77. #elif defined UCSR0A
  78. # define ODDBG_USR UCSR0A
  79. #endif
  80. #if defined UDRE
  81. # define ODDBG_UDRE UDRE
  82. #else
  83. # define ODDBG_UDRE UDRE0
  84. #endif
  85. #if defined UDR
  86. # define ODDBG_UDR UDR
  87. #elif defined UDR0
  88. # define ODDBG_UDR UDR0
  89. #endif
  90. static inline void odDebugInit(void)
  91. {
  92. ODDBG_UCR |= (1<<ODDBG_TXEN);
  93. ODDBG_UBRR = F_CPU / (19200 * 16L) - 1;
  94. }
  95. #else
  96. # define odDebugInit()
  97. #endif
  98. /* ------------------------------------------------------------------------- */
  99. #endif /* __oddebug_h_included__ */