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