USBasp 2005.11.14.
[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 52 2005-04-12 16:57:29Z cs $
9 */
10
11 #include <avr/io.h>
12 #include "oddebug.h"
13
14 #if DEBUG_LEVEL > 0
15
16 static void uartPutc(char c)
17 {
18 while(!(ODDBG_USR & (1 << UDRE))); /* wait for data register empty */
19 ODDBG_UDR = c;
20 }
21
22 static uchar hexAscii(uchar h)
23 {
24 h &= 0xf;
25 if(h < 10){
26 h += '0';
27 }else{
28 h += 'a' - (uchar)10;
29 }
30 return h;
31 }
32
33 static void printHex(uchar c)
34 {
35 uartPutc(hexAscii(c >> 4));
36 uartPutc(hexAscii(c));
37 }
38
39 void odDebug(uchar prefix, uchar *data, uchar len)
40 {
41 printHex(prefix);
42 uartPutc(':');
43 while(len--){
44 uartPutc(' ');
45 printHex(*data++);
46 }
47 uartPutc('\r');
48 uartPutc('\n');
49 }
50
51 #endif