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