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), GNU GPL v3 or proprietary (CommercialLicense.txt)
10 #ifndef __oddebug_h_included__
11 #define __oddebug_h_included__
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.
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').
27 # define F_CPU 12000000 /* 12 MHz */
30 /* make sure we have the UART defines: */
31 #include "usbportability.h"
34 # define uchar unsigned char
37 #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
38 # warning "Debugging disabled because device has no UART"
43 # define DEBUG_LEVEL 0
46 /* ------------------------------------------------------------------------- */
49 # define DBG1(prefix, data, len) odDebug(prefix, data, len)
51 # define DBG1(prefix, data, len)
55 # define DBG2(prefix, data, len) odDebug(prefix, data, len)
57 # define DBG2(prefix, data, len)
60 /* ------------------------------------------------------------------------- */
63 extern void odDebug(uchar prefix
, uchar
*data
, uchar len
);
65 /* Try to find our control registers; ATMEL likes to rename these */
68 # define ODDBG_UBRR UBRR
70 # define ODDBG_UBRR UBRRL
72 # define ODDBG_UBRR UBRR0
74 # define ODDBG_UBRR UBRR0L
78 # define ODDBG_UCR UCR
80 # define ODDBG_UCR UCSRB
82 # define ODDBG_UCR UCSR0B
86 # define ODDBG_TXEN TXEN
88 # define ODDBG_TXEN TXEN0
92 # define ODDBG_USR USR
94 # define ODDBG_USR UCSRA
96 # define ODDBG_USR UCSR0A
100 # define ODDBG_UDRE UDRE
102 # define ODDBG_UDRE UDRE0
106 # define ODDBG_UDR UDR
108 # define ODDBG_UDR UDR0
111 static inline void odDebugInit(void)
113 ODDBG_UCR
|= (1<<ODDBG_TXEN
);
114 ODDBG_UBRR
= F_CPU
/ (19200 * 16L) - 1;
117 # define odDebugInit()
120 /* ------------------------------------------------------------------------- */
122 #endif /* __oddebug_h_included__ */