Нема описа
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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) or proprietary (CommercialLicense.txt)
  8. * This Revision: $Id: oddebug.h 275 2007-03-20 09:58:28Z 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 "iarcompat.h"
  27. #ifndef __IAR_SYSTEMS_ICC__
  28. # include <avr/io.h>
  29. #endif
  30. #ifndef uchar
  31. # define uchar unsigned char
  32. #endif
  33. #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
  34. # warning "Debugging disabled because device has no UART"
  35. # undef DEBUG_LEVEL
  36. #endif
  37. #ifndef DEBUG_LEVEL
  38. # define DEBUG_LEVEL 0
  39. #endif
  40. /* ------------------------------------------------------------------------- */
  41. #if DEBUG_LEVEL > 0
  42. # define DBG1(prefix, data, len) odDebug(prefix, data, len)
  43. #else
  44. # define DBG1(prefix, data, len)
  45. #endif
  46. #if DEBUG_LEVEL > 1
  47. # define DBG2(prefix, data, len) odDebug(prefix, data, len)
  48. #else
  49. # define DBG2(prefix, data, len)
  50. #endif
  51. /* ------------------------------------------------------------------------- */
  52. #if DEBUG_LEVEL > 0
  53. extern void odDebug(uchar prefix, uchar *data, uchar len);
  54. /* Try to find our control registers; ATMEL likes to rename these */
  55. #if defined UBRR
  56. # define ODDBG_UBRR UBRR
  57. #elif defined UBRRL
  58. # define ODDBG_UBRR UBRRL
  59. #elif defined UBRR0
  60. # define ODDBG_UBRR UBRR0
  61. #elif defined UBRR0L
  62. # define ODDBG_UBRR UBRR0L
  63. #endif
  64. #if defined UCR
  65. # define ODDBG_UCR UCR
  66. #elif defined UCSRB
  67. # define ODDBG_UCR UCSRB
  68. #elif defined UCSR0B
  69. # define ODDBG_UCR UCSR0B
  70. #endif
  71. #if defined TXEN
  72. # define ODDBG_TXEN TXEN
  73. #else
  74. # define ODDBG_TXEN TXEN0
  75. #endif
  76. #if defined USR
  77. # define ODDBG_USR USR
  78. #elif defined UCSRA
  79. # define ODDBG_USR UCSRA
  80. #elif defined UCSR0A
  81. # define ODDBG_USR UCSR0A
  82. #endif
  83. #if defined UDRE
  84. # define ODDBG_UDRE UDRE
  85. #else
  86. # define ODDBG_UDRE UDRE0
  87. #endif
  88. #if defined UDR
  89. # define ODDBG_UDR UDR
  90. #elif defined UDR0
  91. # define ODDBG_UDR UDR0
  92. #endif
  93. static inline void odDebugInit(void)
  94. {
  95. ODDBG_UCR |= (1<<ODDBG_TXEN);
  96. ODDBG_UBRR = F_CPU / (19200 * 16L) - 1;
  97. }
  98. #else
  99. # define odDebugInit()
  100. #endif
  101. /* ------------------------------------------------------------------------- */
  102. #endif /* __oddebug_h_included__ */