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.
72 lines
1.4 KiB
72 lines
1.4 KiB
/*
|
|
* util.c
|
|
*
|
|
* Created on: Aug 12, 2009
|
|
* Author: johan
|
|
*/
|
|
|
|
// adapted from libgomspace
|
|
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "common_utils/hexdump.h"
|
|
|
|
|
|
//! Dump memory to debugging output
|
|
/**
|
|
* Dumps a chunk of memory to the screen
|
|
*/
|
|
void hex_dump(FILE * fp, void *src, int len) {
|
|
int i, j=0, k;
|
|
char text[17];
|
|
|
|
text[16] = '\0';
|
|
//printf("Hex dump:\r\n");
|
|
fprintf(fp, "%p : ", src);
|
|
for(i=0; i<len; i++) {
|
|
j++;
|
|
fprintf(fp, "%02X ", ((volatile unsigned char *)src)[i]);
|
|
if(j == 8)
|
|
fputc(' ', fp);
|
|
if(j == 16) {
|
|
j = 0;
|
|
memcpy(text, &((char *)src)[i-15], 16);
|
|
for(k=0; k<16; k++) {
|
|
if((text[k] < 32) || (text[k] > 126)) {
|
|
text[k] = '.';
|
|
}
|
|
}
|
|
fprintf(fp, " |%s|\n\r", text);
|
|
if(i<len-1) {
|
|
fprintf(fp, "%p : ", src+i+1);
|
|
}
|
|
}
|
|
}
|
|
if (i % 16)
|
|
fprintf(fp, "\r\n");
|
|
}
|
|
|
|
void hex_dump_buff_line(FILE *fp, int addr_size, unsigned pos, char *line, unsigned len)
|
|
{
|
|
unsigned i;
|
|
|
|
fprintf(fp, "%0*x", addr_size, pos);
|
|
for (i = 0; i < HEX_DUMP_LINE_BUFF_SIZ; i++)
|
|
{
|
|
if (!(i % 8))
|
|
fputc(' ', fp);
|
|
if (i < len)
|
|
fprintf(fp, " %02x", (unsigned char)line[i]);
|
|
else
|
|
fputs(" ", fp);
|
|
}
|
|
fputs(" |", fp);
|
|
for (i = 0; i < HEX_DUMP_LINE_BUFF_SIZ && i < len; i++)
|
|
{
|
|
if (line[i] >= 32 && line[i] <= 126)
|
|
fprintf(fp, "%c", (unsigned char)line[i]);
|
|
else
|
|
fputc('.', fp);
|
|
}
|
|
fputs("|\r\n", fp);
|
|
}
|
|
|