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