1 |
/* Name: oddebug.c |
1 |
/* Name: oddebug.c |
2 |
* Project: AVR library |
2 |
* Project: AVR library |
3 |
* Author: Christian Starkjohann |
3 |
* Author: Christian Starkjohann |
4 |
* Creation Date: 2005-01-16 |
4 |
* Creation Date: 2005-01-16 |
5 |
* Tabsize: 4 |
5 |
* Tabsize: 4 |
6 |
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH |
6 |
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH |
7 |
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt) |
7 |
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) |
8 |
* This Revision: $Id: oddebug.c,v 1.2 2007/05/19 12:30:11 harbaum Exp $ |
- |
|
9 |
*/ |
8 |
*/ |
10 |
|
9 |
|
11 |
#include "oddebug.h" |
10 |
#include "oddebug.h" |
12 |
|
11 |
|
13 |
#if DEBUG_LEVEL > 0 |
12 |
#if DEBUG_LEVEL > 0 |
14 |
|
13 |
|
15 |
#warning "Never compile production devices with debugging enabled" |
14 |
#warning "Never compile production devices with debugging enabled" |
16 |
|
15 |
|
17 |
static void uartPutc(char c) |
16 |
static void uartPutc(char c) |
18 |
{ |
17 |
{ |
19 |
while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ |
18 |
while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ |
20 |
ODDBG_UDR = c; |
19 |
ODDBG_UDR = c; |
21 |
} |
20 |
} |
22 |
|
21 |
|
23 |
static uchar hexAscii(uchar h) |
22 |
static uchar hexAscii(uchar h) |
24 |
{ |
23 |
{ |
25 |
h &= 0xf; |
24 |
h &= 0xf; |
26 |
if(h >= 10) |
25 |
if(h >= 10) |
27 |
h += 'a' - (uchar)10 - '0'; |
26 |
h += 'a' - (uchar)10 - '0'; |
28 |
h += '0'; |
27 |
h += '0'; |
29 |
return h; |
28 |
return h; |
30 |
} |
29 |
} |
31 |
|
30 |
|
32 |
static void printHex(uchar c) |
31 |
static void printHex(uchar c) |
33 |
{ |
32 |
{ |
34 |
uartPutc(hexAscii(c >> 4)); |
33 |
uartPutc(hexAscii(c >> 4)); |
35 |
uartPutc(hexAscii(c)); |
34 |
uartPutc(hexAscii(c)); |
36 |
} |
35 |
} |
37 |
|
36 |
|
38 |
void odDebug(uchar prefix, uchar *data, uchar len) |
37 |
void odDebug(uchar prefix, uchar *data, uchar len) |
39 |
{ |
38 |
{ |
40 |
printHex(prefix); |
39 |
printHex(prefix); |
41 |
uartPutc(':'); |
40 |
uartPutc(':'); |
42 |
while(len--){ |
41 |
while(len--){ |
43 |
uartPutc(' '); |
42 |
uartPutc(' '); |
44 |
printHex(*data++); |
43 |
printHex(*data++); |
45 |
} |
44 |
} |
46 |
uartPutc('\r'); |
45 |
uartPutc('\r'); |
47 |
uartPutc('\n'); |
46 |
uartPutc('\n'); |
48 |
} |
47 |
} |
49 |
|
48 |
|
50 |
#endif |
49 |
#endif |