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

Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by  doxygen 1.4.2