USBasp 2005.04.21.
[pub/USBasp.git] / firmware / usbdrv / oddebug.h
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: Proprietary, free under certain conditions. See Documentation.
8 * This Revision: $Id: oddebug.h 52 2005-04-12 16:57:29Z cs $
9 */
10
11 #ifndef __oddebug_h_included__
12 #define __oddebug_h_included__
13
14 #include <avr/io.h>
15
16 /*
17 General Description:
18 This module implements a function for debug logs on the serial line of the
19 AVR microcontroller. Debugging can be configured with the define
20 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
21 calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
22 2, DBG1 and DBG2 logs will be printed.
23
24 A debug log consists of a label ('prefix') to indicate which debug log created
25 the output and a memory block to dump in hex ('data' and 'len').
26 */
27
28
29 #ifndef F_CPU
30 # define F_CPU 12000000 /* 12 MHz */
31 #endif
32
33 #ifndef uchar
34 # define uchar unsigned char
35 #endif
36
37 #if DEBUG_LEVEL > 0 && !defined TXEN /* 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 UBRR1
72 # define ODDBG_UBRR UBRR1
73 #elif defined UBRR1L
74 # define ODDBG_UBRR UBRR1L
75 #endif
76
77 #if defined UCR
78 # define ODDBG_UCR UCR
79 #elif defined UCSRB
80 # define ODDBG_UCR UCSRB
81 #elif defined UCSR1B
82 # define ODDBG_UCR UCSR1B
83 #endif
84
85 #if defined USR
86 # define ODDBG_USR USR
87 #elif defined UCSRA
88 # define ODDBG_USR UCSRA
89 #elif defined UCSR1A
90 # define ODDBG_USR UCSR1A
91 #endif
92
93 #if defined UDR
94 # define ODDBG_UDR UDR
95 #elif defined UDR1
96 # define ODDBG_UDR UDR1
97 #endif
98
99 static inline void odDebugInit(void)
100 {
101 ODDBG_UCR |= (1<<TXEN);
102 ODDBG_UBRR = F_CPU / (19200 * 16L) - 1;
103 }
104 #else
105 # define odDebugInit()
106 #endif
107
108 /* ------------------------------------------------------------------------- */
109
110 #endif /* __oddebug_h_included__ */