You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.3 KiB
100 lines
2.3 KiB
/*! \file debug.c \brief Debugging function library. */
|
|
//*****************************************************************************
|
|
//
|
|
// File Name : 'debug.c'
|
|
// Title : Helpful debugging functions
|
|
// Author : Pascal Stang - Copyright (C) 2003
|
|
// Created : 2003-03-13
|
|
// Revised : 2003-03-13
|
|
// Version : 0.1
|
|
// Target MCU : Atmel AVR series
|
|
// Editor Tabs : 4
|
|
//
|
|
// Description : This file contains a set of functions which may be useful
|
|
// for general debugging.
|
|
//
|
|
// This code is distributed under the GNU Public License
|
|
// which can be found at http://www.gnu.org/licenses/gpl.txt
|
|
//
|
|
//*****************************************************************************
|
|
|
|
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
#include "debug.h"
|
|
#include "HardwareSerial.h"
|
|
|
|
#include <avr/pgmspace.h>
|
|
#include "programStrings.h"
|
|
|
|
// global variables
|
|
|
|
// functions
|
|
|
|
// Print a part of memory as a formatted hex table with ascii translation
|
|
void debugPrintHexTable(u16 length, u08 *buffer)
|
|
{
|
|
u08 i;
|
|
u16 j;
|
|
u08 *buf;
|
|
u08 s;
|
|
|
|
buf = buffer;
|
|
|
|
// print the low order address indicies and ASCII header
|
|
SPrint_P(PSTR(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\r\n"));
|
|
SPrint_P(PSTR(" ----------------------------------------------- ---- ASCII -----\r\n"));
|
|
|
|
// print the data
|
|
for(j=0; j<((length+15)>>4); j++)
|
|
{
|
|
// print the high order address index for this line
|
|
Serial.print(j<<4);
|
|
Serial.print(' ');
|
|
|
|
// print the hex data
|
|
for(i=0; i<0x10; i++)
|
|
{
|
|
// be nice and print only up to the exact end of the data
|
|
if( ((j<<4)+i) < length)
|
|
{
|
|
// print hex byte
|
|
Serial.print(buf[(j<<4)+i], HEX);
|
|
Serial.print(' ');
|
|
}
|
|
else
|
|
{
|
|
// we're past the end of the data's length
|
|
// print spaces
|
|
SPrint_P(PSTR(" "));
|
|
}
|
|
}
|
|
|
|
// leave some space
|
|
Serial.print(' ');
|
|
|
|
// print the ascii data
|
|
for(i=0; i<0x10; i++)
|
|
{
|
|
// be nice and print only up to the exact end of the data
|
|
if( ((j<<4)+i) < length)
|
|
{
|
|
// get the character
|
|
s = buf[(j<<4)+i];
|
|
// make sure character is printable
|
|
if(s >= 0x20)
|
|
Serial.print(s, HEX);
|
|
else
|
|
Serial.print('.');
|
|
}
|
|
else
|
|
{
|
|
// we're past the end of the data's length
|
|
// print a space
|
|
Serial.print(' ');
|
|
}
|
|
}
|
|
Serial.println();
|
|
}
|
|
}
|