2015-04-09 18:32:04 +02:00
|
|
|
/* Name: oddebug.c
|
|
|
|
* Project: AVR library
|
|
|
|
* Author: Christian Starkjohann
|
|
|
|
* Creation Date: 2005-01-16
|
|
|
|
* Tabsize: 4
|
|
|
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
|
* This Revision: $Id: oddebug.c 692 2008-11-07 15:07:40Z cs $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "oddebug.h"
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 0
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
# warning "Never compile production devices with debugging enabled"
|
2015-04-09 18:32:04 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
static void uartPutc(char c) {
|
|
|
|
while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
|
|
|
|
; /* wait for data register empty */
|
2015-04-09 18:32:04 +02:00
|
|
|
ODDBG_UDR = c;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
static uchar hexAscii(uchar h) {
|
2015-04-09 18:32:04 +02:00
|
|
|
h &= 0xf;
|
2019-08-30 20:19:03 +02:00
|
|
|
if (h >= 10) h += 'a' - (uchar)10 - '0';
|
2015-04-09 18:32:04 +02:00
|
|
|
h += '0';
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
static void printHex(uchar c) {
|
2015-04-09 18:32:04 +02:00
|
|
|
uartPutc(hexAscii(c >> 4));
|
|
|
|
uartPutc(hexAscii(c));
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void odDebug(uchar prefix, uchar *data, uchar len) {
|
2015-04-09 18:32:04 +02:00
|
|
|
printHex(prefix);
|
|
|
|
uartPutc(':');
|
2019-08-30 20:19:03 +02:00
|
|
|
while (len--) {
|
2015-04-09 18:32:04 +02:00
|
|
|
uartPutc(' ');
|
|
|
|
printHex(*data++);
|
|
|
|
}
|
|
|
|
uartPutc('\r');
|
|
|
|
uartPutc('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|