📄 debug.c
字号:
/**
* debug.c
* 僔儕傾儖捠怣僨僶僢僌儖乕僠儞
* 僴僀僷乕僞乕儈僫儖懳墳偺偨傔丄俠俼偱夵峴丄儖乕僾僶僢僋偁傝
* Copyright (c)2002 Junichi Tomaru
*/
#include "h8hst.h"
#define DEBUGPORT 1 /* 捠怣僨僶僢僌偺億乕僩(SCI1) */
const char hexcode[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char debbuf[64];
int pos;
/**
* 俉價僢僩悢抣傪俀恑悢暥帤楍偵偡傞
*/
char *bin8binstr( unsigned char dat, char *buf )
{
*( buf + 8 ) = '\0';
if(( dat & 0x1 ) == 1 ){ *( buf + 7 ) = '1'; }
else{ *( buf + 7 ) = '0'; }
if(( dat & 0x2 ) == 2 ){ *( buf + 6 ) = '1'; }
else{ *( buf + 6 ) = '0'; }
if(( dat & 0x4 ) == 4 ){ *( buf + 5 ) = '1'; }
else{ *( buf + 5 ) = '0'; }
if(( dat & 0x8 ) == 8 ){ *( buf + 4 ) = '1'; }
else{ *( buf + 4 ) = '0'; }
if(( dat & 0x10 ) == 0x10 ){ *( buf + 3 ) = '1'; }
else{ *( buf + 3 ) = '0'; }
if(( dat & 0x20 ) == 0x20 ){ *( buf + 2 ) = '1'; }
else{ *( buf + 2 ) = '0'; }
if(( dat & 0x40 ) == 0x40 ){ *( buf + 1 ) = '1'; }
else{ *( buf + 1 ) = '0'; }
if(( dat & 0x80 ) == 0x80 ){ *( buf + 0 ) = '1'; }
else{ *( buf + 0 ) = '0'; }
return buf;
}
/**
* 俉價僢僩悢抣傪侾俇恑暥帤楍偵偡傞
*/
char *bin8tohex( unsigned char bin, char *buf )
{
*( buf + 0 ) = hexcode[bin/0x10];
*( buf + 1 ) = hexcode[bin%0x10];
*( buf + 2 ) = '\0';
return buf;
}
/**
* 侾俇價僢僩悢抣傪侾俇恑暥帤楍偵
*/
char *bin16tohex( unsigned bin, char *buf )
{
*( buf + 0 ) = hexcode[bin/0x1000];
bin %= 0x1000;
*( buf + 1 ) = hexcode[bin/0x100];
bin %= 0x100;
*( buf + 2 ) = hexcode[bin/0x10];
*( buf + 3 ) = hexcode[bin%0x10];
*( buf + 4 ) = '\0';
return buf;
}
/**
* 俁俀價僢僩悢抣傪侾俇恑暥帤楍偵
*/
char *bin32tohex( unsigned long bin, char *buf )
{
*( buf + 0 ) = hexcode[bin/0x10000000];
bin %= 0x10000000;
*( buf + 1 ) = hexcode[bin/0x1000000];
bin %= 0x1000000;
*( buf + 2 ) = hexcode[bin/0x100000];
bin %= 0x100000;
*( buf + 3 ) = hexcode[bin/0x10000];
bin %= 0x10000;
*( buf + 4 ) = hexcode[bin/0x1000];
bin %= 0x1000;
*( buf + 5 ) = hexcode[bin/0x100];
bin %= 0x100;
*( buf + 6 ) = hexcode[bin/0x10];
*( buf + 7 ) = hexcode[bin%0x10];
*( buf + 8 ) = '\0';
return buf;
}
/**
* 僐儅儞僪擖椡
*/
bool getdebcom( void )
{
char c;
if( getrxcount( DEBUGPORT ) != 0 ){ /* 庴怣偁偭偨傜 */
c = getsio1( DEBUGPORT );
if( c == '\r' ){ /* CR */
setsio1w( DEBUGPORT, '\r' );
setsio1w( DEBUGPORT, '\n' );
debbuf[pos] = '\0';
pos = 0;
return TRUE;
}
else if( c == '\b' ){ /* BS */
if( pos > 0 ){
pos--;
setsio1w( DEBUGPORT, '\b' );
setsio1w( DEBUGPORT, ' ' );
setsio1w( DEBUGPORT, '\b' );
}
else{
pos = 0;
}
return FALSE;
}
else{
setsio1w( DEBUGPORT, c ); /* 儖乕僾僶僢僋 */
debbuf[pos] = c;
pos++;
return FALSE;
}
}
return FALSE;
}
/**
* 僟儞僾僒僽儖乕僠儞
*/
void dump( char *p )
{
int j, k;
char buf[16];
setsiostr( DEBUGPORT, "LOW8BITS : 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F \r\n" );
setsiostr( DEBUGPORT, " ----------------------------------------------- \r\n" );
for( j = 0; j < 16; j++ ){
setsiostr( DEBUGPORT, bin32tohex(( long )p + j * 16, buf ));
setsiostr( DEBUGPORT, " : " );
for( k = 0; k < 16; k ++ ){
setsiostr( DEBUGPORT, bin8tohex( *( p + j * 16 + k ), buf ));
setsiostr( DEBUGPORT, " " );
}
setsiostr( DEBUGPORT, "\r\n" );
}
}
/**
* 儊儌儕僟儞僾
*/
void memdump( char *p )
{
long l;
l = strtol( p, NULL, 16 );
dump(( char * )l );
}
/**
* 儊儌儕僙僢僩
*/
void setmemory( char *p )
{
byte *n;
long ofs;
int j;
char buf[8];
char **ep;
n = NULL;
ep = &p;
ofs = strtol( p, ep, 16 );
p = *ep + 1;
j = ( int )strtol( p, ep, 16 );
*( n + ofs ) = ( byte )j;
setsiostr( DEBUGPORT, bin8tohex( *( n + ofs ), buf ));
setsiostr( DEBUGPORT, "\r\n" );
}
/**
* 億乕僩擖椡
*/
void portin( char *p )
{
long a;
char i, buf[16];
a = strtol( p, NULL, 16 );
i = *(( unsigned char * )a );
setsiostr( DEBUGPORT, "IN:" );
setsiostr( DEBUGPORT, bin8tohex( i, buf ));
setsiostr( DEBUGPORT, "\r\n" );
}
/**
* 億乕僩弌椡
*/
void portout( char *p )
{
long addr;
char data, buf[8];
char **ep;
ep = &p;
addr = strtol( p, ep, 16 );
p = *ep + 1;
data = (char)strtol( p, ep, 16 );
*(( unsigned char * )addr ) = data;
setsiostr( DEBUGPORT, bin8tohex( *(( unsigned char * )addr ), buf ));
setsiostr( DEBUGPORT, "\r\n" );
}
/**
* 僿儖僾
*/
void help( void )
{
setsiostr( DEBUGPORT, "\r\n" );
setsiostr( DEBUGPORT, " ---- H8-USB Host Board Command Help ----\r\n" );
setsiostr( DEBUGPORT, "DUMP <addr(Hex)> Memory Dump\r\n" );
setsiostr( DEBUGPORT, "FILMEM <start(Hex)> <length(Hex)> <data(Hex)> Memory Fill\r\n" );
setsiostr( DEBUGPORT, "HELP Help\r\n" );
setsiostr( DEBUGPORT, "INPUT <addr(Hex)> Byte Input\r\n" );
setsiostr( DEBUGPORT, "OUTPUT <addr(Hex)> <data(Hex)> Byte Output\r\n" );
setsiostr( DEBUGPORT, "REBOOT Restart\r\n" );
setsiostr( DEBUGPORT, "SETMEM <addr(Hex)> <data(Hex)> Enter Memory\r\n" );
setsiostr( DEBUGPORT, "USBRD <addr(Hex)> SL811HS REGISTER READ\r\n" );
setsiostr( DEBUGPORT, "USBWR <addr(Hex)> <data(Hex)> SL811HS REGISTER WRITE\r\n" );
setsiostr( DEBUGPORT, "VERSION Version\r\n" );
}
/**
* 儊儌儕僼傿儖
*/
void fillmem( char *p )
{
long s;
int j, k;
char *n, **ep;
n = NULL;
ep = &p;
s = strtol( p, ep, 16 );
p = *ep + 1;
j = ( int )strtol( p, ep, 16 );
p = *ep + 1;
k = ( int )strtol( p, ep, 16 );
memset( n + s, k, j );
dump( n + s );
}
/**
* 俽俴俉侾侾俫俽偺儗僕僗僞傪撉傓
*/
void usbread( char *p )
{
byte addr;
char i, buf[16];
addr = (byte)strtol( p, NULL, 16 );
i = sl_read( addr );
setsiostr( DEBUGPORT, "IN:" );
setsiostr( DEBUGPORT, bin8tohex( i, buf ));
setsiostr( DEBUGPORT, "\r\n" );
}
/**
* 俽俴俉侾侾俫俽偺儗僕僗僞偵彂偔
*/
void usbwrite( char *p )
{
byte addr;
char data, buf[8];
char **ep;
ep = &p;
addr = (byte)strtol( p, ep, 16 );
p = *ep + 1;
data = (char)strtol( p, ep, 16 );
sl_write( addr, data );
setsiostr( DEBUGPORT, bin8tohex( data, buf ));
setsiostr( DEBUGPORT, "\r\n" );
}
/**
* 僶乕僕儑儞
*/
void version( void )
{
setsiostr( DEBUGPORT, "\r\n" );
setsiostr( DEBUGPORT, " --- H8 USB HOST" );
setsiostr( DEBUGPORT, vers );
setsiostr( DEBUGPORT, " ---\r\n" );
setsiostr( DEBUGPORT, revs );
setsiostr( DEBUGPORT, " Copyright Junichi Tomaru 2004\r\n" );
}
/**
* 僾儘儞僾僩
*/
void prompt( void )
{
pos = 0;
debbuf[0] = '\0';
setsiostr( DEBUGPORT, "\r\n*>" );
}
/**
* 僨僶僢僌儌乕僪弶婜壔
*/
void debuginit( void )
{
pos = 0;
debbuf[0] = '\0';
setsiostr( DEBUGPORT, "\r\n" );
setsiostr( DEBUGPORT, "Welcome to H8-USB HOST BOARD.\r\n" );
prompt( );
}
/**
* 僨僶僢僌
*/
void debugmain( void )
{
char i, *p, *q, buf[16];
if( getdebcom( ) == TRUE ){
p = strchr( debbuf, ' ' );
if( p == NULL ){
p = strchr( debbuf, '\0' );
}
for( q = debbuf, i = 0; p != q; q++, i++ ){/* 斾妑偺偨傔戝暥帤偵偡傞 */
buf[i] = ( char )toupper( *q );
}
buf[i] = '\0';
while( *p == ' ' ){ /* 僗儁乕僗旘偽偡 */
p++;
}
if( strcmp( buf, "DUMP" ) == 0 ){
memdump( p ); /* 僟儞僾 */
}
else if( strcmp( buf, "FILLMEM" ) == 0 ){
fillmem( p ); /* 儊儌儕僼傿儖 */
}
else if( strcmp( buf, "HELP" ) == 0 ){
help( ); /* 僿儖僾 */
}
else if( strcmp( buf, "INPUT" ) == 0 ){
portin( p ); /* 擖椡 */
}
else if( strcmp( buf, "OUTPUT" ) == 0 ){
portout( p ); /* 弌椡 */
}
else if( strcmp( buf, "REBOOT" ) == 0 ){
while( gettxcount( 1 ) != 0 ){ /* 憲怣姰椆懸偪 */
}
start( ); /* 儕僙僢僩 */
}
else if( strcmp( buf, "SETMEM" ) == 0 ){
setmemory( p ); /* 儊儌儕僙僢僩 */
}
else if( strcmp( buf, "USBRD" ) == 0 ){
usbread( p ); /* USB811HS儗僕僗僞撉傒崬傒 */
}
else if( strcmp( buf, "USBWR" ) == 0 ){
usbwrite( p ); /* USB811HS儗僕僗僞彂偒崬傒 */
}
else if( strcmp( buf, "VERSION" ) == 0 ){
version( ); /* 僶乕僕儑儞 */
}
else if( debbuf[0] != '\0' ){ /* 僐儅儞僪偍偐偟偄 */
setsiostr( DEBUGPORT, "ILLEGAL COMMAND.\r\n" );
}
prompt( );
}
}
/* end of debug.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -