Rev 3331 Rev 3332
1 /* Name: oddebug.h 1 /* Name: oddebug.h
2 * Project: AVR library 2 * Project: AVR library
3 * Author: Christian Starkjohann 3 * Author: Christian Starkjohann
4 * Creation Date: 2005-01-16 4 * Creation Date: 2005-01-16
5 * Tabsize: 4 5 * Tabsize: 4
6 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH 6 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt) 7 * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: oddebug.h,v 1.2 2007/05/19 12:30:11 harbaum Exp $ 8 * This Revision: $Id: oddebug.h,v 1.2 2007/05/19 12:30:11 harbaum Exp $
9 */ 9 */
10   10  
11 #ifndef __oddebug_h_included__ 11 #ifndef __oddebug_h_included__
12 #define __oddebug_h_included__ 12 #define __oddebug_h_included__
13   13  
14 /* 14 /*
15 General Description: 15 General Description:
16 This module implements a function for debug logs on the serial line of the 16 This module implements a function for debug logs on the serial line of the
17 AVR microcontroller. Debugging can be configured with the define 17 AVR microcontroller. Debugging can be configured with the define
18 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging 18 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
19 calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is 19 calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
20 2, DBG1 and DBG2 logs will be printed. 20 2, DBG1 and DBG2 logs will be printed.
21   21  
22 A debug log consists of a label ('prefix') to indicate which debug log created 22 A debug log consists of a label ('prefix') to indicate which debug log created
23 the output and a memory block to dump in hex ('data' and 'len'). 23 the output and a memory block to dump in hex ('data' and 'len').
24 */ 24 */
25   25  
26   26  
27 #ifndef F_CPU 27 #ifndef F_CPU
28 # define F_CPU 12000000 /* 12 MHz */ 28 # define F_CPU 12000000 /* 12 MHz */
29 #endif 29 #endif
30   30  
31 /* make sure we have the UART defines: */ 31 /* make sure we have the UART defines: */
32 #include "iarcompat.h" 32 #include "iarcompat.h"
33 #ifndef __IAR_SYSTEMS_ICC__ 33 #ifndef __IAR_SYSTEMS_ICC__
34 # include <avr/io.h> 34 # include <avr/io.h>
35 #endif 35 #endif
36   36  
37 #ifndef uchar 37 #ifndef uchar
38 # define uchar unsigned char 38 # define uchar unsigned char
39 #endif 39 #endif
40   40  
41 #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ 41 #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
42 # warning "Debugging disabled because device has no UART" 42 # warning "Debugging disabled because device has no UART"
43 # undef DEBUG_LEVEL 43 # undef DEBUG_LEVEL
44 #endif 44 #endif
45   45  
46 #ifndef DEBUG_LEVEL 46 #ifndef DEBUG_LEVEL
47 # define DEBUG_LEVEL 0 47 # define DEBUG_LEVEL 0
48 #endif 48 #endif
49   49  
50 /* ------------------------------------------------------------------------- */ 50 /* ------------------------------------------------------------------------- */
51   51  
52 #if DEBUG_LEVEL > 0 52 #if DEBUG_LEVEL > 0
53 # define DBG1(prefix, data, len) odDebug(prefix, data, len) 53 # define DBG1(prefix, data, len) odDebug(prefix, data, len)
54 #else 54 #else
55 # define DBG1(prefix, data, len) 55 # define DBG1(prefix, data, len)
56 #endif 56 #endif
57   57  
58 #if DEBUG_LEVEL > 1 58 #if DEBUG_LEVEL > 1
59 # define DBG2(prefix, data, len) odDebug(prefix, data, len) 59 # define DBG2(prefix, data, len) odDebug(prefix, data, len)
60 #else 60 #else
61 # define DBG2(prefix, data, len) 61 # define DBG2(prefix, data, len)
62 #endif 62 #endif
63   63  
64 /* ------------------------------------------------------------------------- */ 64 /* ------------------------------------------------------------------------- */
65   65  
66 #if DEBUG_LEVEL > 0 66 #if DEBUG_LEVEL > 0
67 extern void odDebug(uchar prefix, uchar *data, uchar len); 67 extern void odDebug(uchar prefix, uchar *data, uchar len);
68   68  
69 /* Try to find our control registers; ATMEL likes to rename these */ 69 /* Try to find our control registers; ATMEL likes to rename these */
70   70  
71 #if defined UBRR 71 #if defined UBRR
72 # define ODDBG_UBRR UBRR 72 # define ODDBG_UBRR UBRR
73 #elif defined UBRRL 73 #elif defined UBRRL
74 # define ODDBG_UBRR UBRRL 74 # define ODDBG_UBRR UBRRL
75 #elif defined UBRR0 75 #elif defined UBRR0
76 # define ODDBG_UBRR UBRR0 76 # define ODDBG_UBRR UBRR0
77 #elif defined UBRR0L 77 #elif defined UBRR0L
78 # define ODDBG_UBRR UBRR0L 78 # define ODDBG_UBRR UBRR0L
79 #endif 79 #endif
80   80  
81 #if defined UCR 81 #if defined UCR
82 # define ODDBG_UCR UCR 82 # define ODDBG_UCR UCR
83 #elif defined UCSRB 83 #elif defined UCSRB
84 # define ODDBG_UCR UCSRB 84 # define ODDBG_UCR UCSRB
85 #elif defined UCSR0B 85 #elif defined UCSR0B
86 # define ODDBG_UCR UCSR0B 86 # define ODDBG_UCR UCSR0B
87 #endif 87 #endif
88   88  
89 #if defined TXEN 89 #if defined TXEN
90 # define ODDBG_TXEN TXEN 90 # define ODDBG_TXEN TXEN
91 #else 91 #else
92 # define ODDBG_TXEN TXEN0 92 # define ODDBG_TXEN TXEN0
93 #endif 93 #endif
94   94  
95 #if defined USR 95 #if defined USR
96 # define ODDBG_USR USR 96 # define ODDBG_USR USR
97 #elif defined UCSRA 97 #elif defined UCSRA
98 # define ODDBG_USR UCSRA 98 # define ODDBG_USR UCSRA
99 #elif defined UCSR0A 99 #elif defined UCSR0A
100 # define ODDBG_USR UCSR0A 100 # define ODDBG_USR UCSR0A
101 #endif 101 #endif
102   102  
103 #if defined UDRE 103 #if defined UDRE
104 # define ODDBG_UDRE UDRE 104 # define ODDBG_UDRE UDRE
105 #else 105 #else
106 # define ODDBG_UDRE UDRE0 106 # define ODDBG_UDRE UDRE0
107 #endif 107 #endif
108   108  
109 #if defined UDR 109 #if defined UDR
110 # define ODDBG_UDR UDR 110 # define ODDBG_UDR UDR
111 #elif defined UDR0 111 #elif defined UDR0
112 # define ODDBG_UDR UDR0 112 # define ODDBG_UDR UDR0
113 #endif 113 #endif
114   114  
115 static inline void odDebugInit(void) 115 static inline void odDebugInit(void)
116 { 116 {
117 ODDBG_UCR |= (1<<ODDBG_TXEN); 117 ODDBG_UCR |= (1<<ODDBG_TXEN);
118 ODDBG_UBRR = F_CPU / (19200 * 16L) - 1; 118 ODDBG_UBRR = F_CPU / (19200 * 16L) - 1;
119 } 119 }
120 #else 120 #else
121 # define odDebugInit() 121 # define odDebugInit()
122 #endif 122 #endif
123   123  
124 /* ------------------------------------------------------------------------- */ 124 /* ------------------------------------------------------------------------- */
125   125  
126 #endif /* __oddebug_h_included__ */ 126 #endif /* __oddebug_h_included__ */