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