edd44ee9f03c0f95caf904361043724ba5fadfdf
[pub/USBasp.git] / firmware / usbdrv / oddebug.c
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: Proprietary, free under certain conditions. See Documentation.
8 * This Revision: $Id: oddebug.c 215 2006-07-10 21:54:51Z cs $
9 */
10
11 #include "oddebug.h"
12
13 #if DEBUG_LEVEL > 0
14
15 static uchar Warning__Never_compile_production_devices_with_debugging;
16 /* The "#warning" preprocessor directive is non-standard. The unused static
17 * variable above should give a compiler warning on all compilers.
18 */
19
20 static void uartPutc(char c)
21 {
22 while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
23 ODDBG_UDR = c;
24 }
25
26 static uchar hexAscii(uchar h)
27 {
28 h &= 0xf;
29 if(h >= 10)
30 h += 'a' - (uchar)10 - '0';
31 h += '0';
32 return h;
33 }
34
35 static void printHex(uchar c)
36 {
37 uartPutc(hexAscii(c >> 4));
38 uartPutc(hexAscii(c));
39 }
40
41 void odDebug(uchar prefix, uchar *data, uchar len)
42 {
43 printHex(prefix);
44 uartPutc(':');
45 while(len--){
46 uartPutc(' ');
47 printHex(*data++);
48 }
49 uartPutc('\r');
50 uartPutc('\n');
51 }
52
53 #endif