我都是这么打印内存数据的
#define tst_select(f,v1,v2) ((f) ? (v1) : (v2))
#define hex2ascii(val) tst_select((val) < 10, (val) + '0',(val) + ('A' - 10))
/* 调试内存数据打印 */
int __ddump(const char *fix,int len,i_void *pdat)
{
int i;
int ch;
int dump_len;
uint8 *sp;
extern int lpc22xx_uart_putchar(lpc24xx_uart_t *port,int ch,int timo);
# define dump_putchar(ch) lpc22xx_uart_putchar(LPC22XX_UART0,ch,0)
os_enter_critical();
if(NULL != fix){
printf("%s[%u]:\r\n", fix,len);
}
for(sp = (uint8*)pdat; len > 0; len -= dump_len,sp += dump_len){
dump_len = (len >= 16) ? 16: len;
ch = sp - (uint8*)pdat;
dump_putchar(hex2ascii(((uint32)ch >>12) & 0xF));
dump_putchar(hex2ascii(((uint32)ch >> 8) & 0xF));
dump_putchar(hex2ascii(((uint32)ch >> 4) & 0xF));
dump_putchar(hex2ascii(((uint32)ch >> 0) & 0xF));
dump_putchar(':');
dump_putchar(' ');
for(i = 0; i < dump_len; i++){
ch = sp[i];
dump_putchar(hex2ascii(((uint32)ch >> 4) & 0xF));
dump_putchar(hex2ascii(((uint32)ch >> 0) & 0xF));
dump_putchar(' ');
}
for(; i < 16; i++){
dump_putchar(' ');
dump_putchar(' ');
dump_putchar(' ');
}
dump_putchar('|');
dump_putchar(' ');
for(i = 0; i < dump_len; i++){
ch = sp[i];
dump_putchar((ch >= 0x20) ? ch : '.');
}
dump_putchar('\r');
dump_putchar('\n');
}
os_exit_critical();
return(0);
}
|