3 * Author: Christian Starkjohann
4 * Creation Date: 2005-01-16
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 $
11 #ifndef __oddebug_h_included__
12 #define __oddebug_h_included__
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.
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').
28 # define F_CPU 12000000 /* 12 MHz */
31 /* make sure we have the UART defines: */
32 #include "iarcompat.h"
33 #ifndef __IAR_SYSTEMS_ICC__
38 # define uchar unsigned char
41 #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
42 # warning "Debugging disabled because device has no UART"
47 # define DEBUG_LEVEL 0
50 /* ------------------------------------------------------------------------- */
53 # define DBG1(prefix, data, len) odDebug(prefix, data, len)
55 # define DBG1(prefix, data, len)
59 # define DBG2(prefix, data, len) odDebug(prefix, data, len)
61 # define DBG2(prefix, data, len)
64 /* ------------------------------------------------------------------------- */
67 extern void odDebug(uchar prefix
, uchar
*data
, uchar len
);
69 /* Try to find our control registers; ATMEL likes to rename these */
72 # define ODDBG_UBRR UBRR
74 # define ODDBG_UBRR UBRRL
76 # define ODDBG_UBRR UBRR0
78 # define ODDBG_UBRR UBRR0L
82 # define ODDBG_UCR UCR
84 # define ODDBG_UCR UCSRB
86 # define ODDBG_UCR UCSR0B
90 # define ODDBG_TXEN TXEN
92 # define ODDBG_TXEN TXEN0
96 # define ODDBG_USR USR
98 # define ODDBG_USR UCSRA
100 # define ODDBG_USR UCSR0A
104 # define ODDBG_UDRE UDRE
106 # define ODDBG_UDRE UDRE0
110 # define ODDBG_UDR UDR
112 # define ODDBG_UDR UDR0
115 static inline void odDebugInit(void)
117 ODDBG_UCR
|= (1<<ODDBG_TXEN
);
118 ODDBG_UBRR
= F_CPU
/ (19200 * 16L) - 1;
121 # define odDebugInit()
124 /* ------------------------------------------------------------------------- */
126 #endif /* __oddebug_h_included__ */