Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

debug.c

Go to the documentation of this file.
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   : Atmel AVR series
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 <avr/io.h>
00022 #include <avr/signal.h>
00023 #include <avr/interrupt.h>
00024 
00025 #include "global.h"
00026 #include "debug.h"
00027 
00028 #include "rprintf.h"        // include printf support
00029 
00030 // global variables
00031 
00032 // functions
00033 
00034 // Print a part of memory as a formatted hex table with ascii translation
00035 void debugPrintHexTable(u16 length, u08 *buffer)
00036 {
00037     u08 i;
00038     u16 j;
00039     u08 *buf;
00040     u08 s;
00041 
00042     buf = buffer;
00043     
00044     // print the low order address indicies and ASCII header
00045     rprintfProgStrM("     00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F  0123456789ABCDEF\r\n");
00046     rprintfProgStrM("     -----------------------------------------------  ---- ASCII -----\r\n");
00047     
00048     // print the data
00049     for(j=0; j<((length+15)>>4); j++)
00050     {
00051         // print the high order address index for this line
00052         rprintfu16(j<<4);
00053         rprintfChar(' ');
00054 
00055         // print the hex data
00056         for(i=0; i<0x10; i++)
00057         {
00058             // be nice and print only up to the exact end of the data
00059             if( ((j<<4)+i) < length)
00060             {
00061                 // print hex byte
00062                 rprintfu08(buf[(j<<4)+i]);
00063                 rprintfChar(' ');
00064             }
00065             else
00066             {
00067                 // we're past the end of the data's length
00068                 // print spaces
00069                 rprintfProgStrM("   ");
00070             }
00071         }
00072         
00073         // leave some space
00074         rprintfChar(' ');
00075 
00076         // print the ascii data
00077         for(i=0; i<0x10; i++)
00078         {
00079             // be nice and print only up to the exact end of the data
00080             if( ((j<<4)+i) < length)
00081             {
00082                 // get the character
00083                 s = buf[(j<<4)+i]; 
00084                 // make sure character is printable
00085                 if(s >= 0x20)
00086                     rprintfChar(s);
00087                 else
00088                     rprintfChar('.');
00089             }
00090             else
00091             {
00092                 // we're past the end of the data's length
00093                 // print a space
00094                 rprintfChar(' ');
00095             }
00096         }
00097         rprintfCRLF();
00098     }
00099 }

Generated on Tue Sep 20 03:11:42 2005 for Procyon AVRlib by  doxygen 1.4.2