00001 /*! \file debug.c \brief Debugging function library. */ 00002 //***************************************************************************** 00003 // 00004 // File Name : 'debug.c' 00005 // Title : Helpful debugging functions 00006 // Author : Pascal Stang - Copyright (C) 2003 00007 // Created : 2003-03-13 00008 // Revised : 2003-03-13 00009 // Version : 0.1 00010 // Target MCU : any 00011 // Editor Tabs : 4 00012 // 00013 // Description : This file contains a set of functions which may be useful 00014 // for general debugging. 00015 // 00016 // This code is distributed under the GNU Public License 00017 // which can be found at http://www.gnu.org/licenses/gpl.txt 00018 // 00019 //***************************************************************************** 00020 00021 #include "global.h" 00022 #include "debug.h" 00023 00024 #include "rprintf.h" // include printf support 00025 00026 // global variables 00027 00028 // functions 00029 00030 // Print a part of memory as a formatted hex table with ascii translation 00031 void debugPrintHexTable(u16 length, u08 *buffer) 00032 { 00033 u08 i; 00034 u16 j; 00035 u08 *buf; 00036 u08 s; 00037 00038 buf = buffer; 00039 00040 // print the low order address indicies and ASCII header 00041 rprintfStr(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"); 00042 rprintfStr(" ----------------------------------------------- ---- ASCII -----\r\n"); 00043 00044 // print the data 00045 for(j=0; j<((length+15)>>4); j++) 00046 { 00047 // print the high order address index for this line 00048 rprintfu16(j<<4); 00049 rprintfChar(' '); 00050 00051 // print the hex data 00052 for(i=0; i<0x10; i++) 00053 { 00054 // be nice and print only up to the exact end of the data 00055 if( ((j<<4)+i) < length) 00056 { 00057 // print hex byte 00058 rprintfu08(buf[(j<<4)+i]); 00059 rprintfChar(' '); 00060 } 00061 else 00062 { 00063 // we're past the end of the data's length 00064 // print spaces 00065 rprintfStr(" "); 00066 } 00067 } 00068 00069 // leave some space 00070 rprintfChar(' '); 00071 00072 // print the ascii data 00073 for(i=0; i<0x10; i++) 00074 { 00075 // be nice and print only up to the exact end of the data 00076 if( ((j<<4)+i) < length) 00077 { 00078 // get the character 00079 s = buf[(j<<4)+i]; 00080 // make sure character is printable 00081 if(s >= 0x20) 00082 rprintfChar(s); 00083 else 00084 rprintfChar('.'); 00085 } 00086 else 00087 { 00088 // we're past the end of the data's length 00089 // print a space 00090 rprintfChar(' '); 00091 } 00092 } 00093 rprintfCRLF(); 00094 } 00095 }