Rev 3331 Rev 3332
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) or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: oddebug.c,v 1.2 2007/05/19 12:30:11 harbaum Exp $ 8 * This Revision: $Id: oddebug.c,v 1.2 2007/05/19 12:30:11 harbaum Exp $
9 */ 9 */
10   10  
11 #include "oddebug.h" 11 #include "oddebug.h"
12   12  
13 #if DEBUG_LEVEL > 0 13 #if DEBUG_LEVEL > 0
14   14  
15 #warning "Never compile production devices with debugging enabled" 15 #warning "Never compile production devices with debugging enabled"
16   16  
17 static void uartPutc(char c) 17 static void uartPutc(char c)
18 { 18 {
19 while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ 19 while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
20 ODDBG_UDR = c; 20 ODDBG_UDR = c;
21 } 21 }
22   22  
23 static uchar hexAscii(uchar h) 23 static uchar hexAscii(uchar h)
24 { 24 {
25 h &= 0xf; 25 h &= 0xf;
26 if(h >= 10) 26 if(h >= 10)
27 h += 'a' - (uchar)10 - '0'; 27 h += 'a' - (uchar)10 - '0';
28 h += '0'; 28 h += '0';
29 return h; 29 return h;
30 } 30 }
31   31  
32 static void printHex(uchar c) 32 static void printHex(uchar c)
33 { 33 {
34 uartPutc(hexAscii(c >> 4)); 34 uartPutc(hexAscii(c >> 4));
35 uartPutc(hexAscii(c)); 35 uartPutc(hexAscii(c));
36 } 36 }
37   37  
38 void odDebug(uchar prefix, uchar *data, uchar len) 38 void odDebug(uchar prefix, uchar *data, uchar len)
39 { 39 {
40 printHex(prefix); 40 printHex(prefix);
41 uartPutc(':'); 41 uartPutc(':');
42 while(len--){ 42 while(len--){
43 uartPutc(' '); 43 uartPutc(' ');
44 printHex(*data++); 44 printHex(*data++);
45 } 45 }
46 uartPutc('\r'); 46 uartPutc('\r');
47 uartPutc('\n'); 47 uartPutc('\n');
48 } 48 }
49   49  
50 #endif 50 #endif