📄 testmgr.c
字号:
*s++ = 0; // put in a terminator, if necessary
}
}
if(acL->dc.argc == 0)
return;
for (i = 1; i < acL->dc.argc; i++) makeNumber(i);
// Search for the command in our command table
cmd = findCmd(pntr,index);
if(cmd != 0)
{
acL->dc.numArgs = cmd->numArg; /* load up the arguments */
(*(cmd->routine))();
}
else
eprintf("***Error***: Command not found\n");
}
/*--------------------------------------------------------------------------*/
/* */
/* function: makeNumber() */
/* */
/* purpose: to convert the ascii string in the argv[i] array to an actual */
/* binary digit. */
/* */
/* calls: isDigit(), tolower() */
/* */
/* abstract: the ascii number will be parsed from start to finish. When */
/* done, the decarg array will contain valid values */
/* */
/* returns: void */
/* */
/*--------------------------------------------------------------------------*/
void makeNumber(int i)
{
register eduCommon *acL = (eduCommon *) ACADDRESS;
char *s, c;
int v = 0;
s = acL->dc.argv[i]; /* initialize all the arrays */
acL->dc.hexArg[i] = 0;
acL->dc.decArg[i] = 0;
acL->dc.decArgOk[i] = TRUE;
acL->dc.hexArgOk[i] = TRUE;
while (*s) {
c = *s++;
if (isdigit(c)) /* check if argument is a number */
v = c - '0'; /* if so, then make it binary */
else {
acL->dc.decArgOk[i] = FALSE; /* if hex, then we may have failed IsDigit */
c = tolower(c); /* lower it */
if (((c >= 'a') && (c <= 'f'))) {
v = c - 'a' + 10; /* see if its hex, if so, make it binary */
}
else acL->dc.hexArgOk[i] = FALSE;
}
if (acL->dc.decArgOk[i]) /* fill in the decimal argument array */
acL->dc.decArg[i] = (acL->dc.decArg[i] * 10) + v;
if (acL->dc.hexArgOk[i]) /* fill in the hex argument array */
acL->dc.hexArg[i] = (acL->dc.hexArg[i] * 16) + v;
}
}
//
// Function: findCmd
//
// Description: Looks for a command in an array. If not found,
// displays "unknown command"
//
DiagCmd *findCmd(unsigned int pntr, int idx)
{
register eduCommon *acL = (eduCommon *) ACADDRESS;
DiagCmd *p;
int wantargs, matchOk, i;
char syn_curr;
p = (DiagCmd*) pntr; /* point to the command/test array */
while (p->cmdw) /* search til there aren't any more commands in the table*/
{
if (strcmp(acL->dc.argv[idx], p->cmdw) == 0)
{
matchOk = TRUE; /* we found a match, now check syntax */
wantargs = strlen(p->syntax);
//if(wantargs == (acL->dc.argc - 1)) // cannot be done since "test" has variable args
for (i = 1; i <= wantargs; i++)
{
syn_curr = p->syntax[i-1];
if ((syn_curr=='X') && !acL->dc.hexArgOk[i+idx])
matchOk = FALSE;
if (syn_curr=='x' && (i+idx) < acL->dc.argc && !acL->dc.hexArgOk[i+idx])
matchOk = FALSE;
if ((syn_curr =='D') && !acL->dc.decArgOk[i+idx])
matchOk = FALSE;
if (syn_curr=='d' && (i+idx) < acL->dc.argc && !acL->dc.decArgOk[i+idx])
matchOk = FALSE;
if (syn_curr=='S' && i >= acL->dc.argc)
matchOk = FALSE;
}
if (matchOk)
return(p); /* checks out, return pointer */
else
eprintf("Syntax is incorrect, type 'h' to get help\n");
if (idx)
eprintf("syntax error... type 't %s %s'\n",acL->dc.argv[1],p->helpstr);
else
eprintf("syntax error... type 'h %s'\n",acL->dc.argv[0]);
return(0); /* syntax is wrong, return fail status */
}
p++; /* bump to next command in array */
}
eprintf("unknown command\n");
return(0);
}
//
// Function: cmd_help
//
// Description: Displays all commands available to the user at the highest level
//
void cmd_help(void)
{
/*
This function is invoked when the user types the help command at the Diag prompt.
This function will display a help message on all the commands available in diagnostics.
*/
register eduCommon* acL = (eduCommon *) ACADDRESS;
DiagCmd *p;
char *s, syncmd;
p = (DiagCmd *) &bdwcmdarray[0];
if (acL->dc.argc == 1)
{
eprintf("\n****************************************************************************\n");
eprintf("\t\t\tBATTERY DREW/WALLACE HELP MENU\n");
eprintf("Access Commands:\n");
eprintf("p[bwd].......print memory contents c[bwd].......change memory contents\n");
eprintf("i2cread......Read an I2C device i2cwrite.....Write an I2C device\n");
eprintf("viewlog.......view entries in log clearlog.....clears the system log\n");
eprintf("setverbose.......Set verbose level\n");
eprintf("\n");
eprintf("Utility Commands:\n");
eprintf("?.............display this help screen banner.......Print banner\n");
eprintf("exit..........Exit Diagnostics h(elp).......display this help screen\n");
eprintf("t(est)........Run DIAG test\n");
eprintf("\n");
eprintf("Note: additional help is available on the above commands,\n");
eprintf("for help on each command type 'h command<cr>'.\n\n");
}
else
{
while (p->cmdw)
{ /* print expected syntax for each command */
if (strcmp(p->cmdw, acL->dc.argv[1]) == 0)
{
eprintf("%s: %s\n", p->cmdw, p->helpstr);
s = p->syntax;
eprintf("arguments: ");
while(*s)
{
syncmd = *s++;
switch (syncmd)
{
case 'X': eprintf("<hex> ");
break;
case 'x': eprintf("<opt hex> ");
break;
case 'D': eprintf("<dec> ");
break;
case 'd': eprintf("<opt dec> ");
break;
case 'S': eprintf("<str> ");
break;
case 's': eprintf("<opt str> ");
break;
case ' ': eprintf("<none> ");
break;
}
}
eprintf("\n");
}
p++;
}
}
}
// *Note: only use for bring up
// Function: cmd_i2crd
//
// Description: allows the user to read any location of
// any I2C PROM
//
void cmd_i2crd(void)
{
register eduCommon* acL = (eduCommon *) ACADDRESS;
unsigned char slave_addr = acL->dc.hexArg[1];
unsigned char offset_addr = acL->dc.hexArg[2];
unsigned char count = acL->dc.decArg[3];
unsigned char buffer[56] = "";
unsigned char i = 0;
if(acL->dc.HostType == SLAVE)
{
eprintf("This command can only be run on master NPU\n");
return;
}
if( (offset_addr + count) > 255)
{
eprintf("The address and count used exceeds the address of 255\n");
}
else
{
i2c_seq_read(slave_addr, offset_addr, buffer, count);
for(i = 0; i < count; i++)
eprintf("%x ", buffer[i]);
eprintf("\n");
}
}
// *Note: only use for bring up
// Function: cmd_i2cwr
//
// Description: allows the user to write any location of
// any I2C PROM
//
void cmd_i2cwr(void)
{
register eduCommon* acL = (eduCommon *) ACADDRESS;
unsigned char buffer[56] = "", count, c;
unsigned int i;
if(acL->dc.HostType == SLAVE)
{
eprintf("This command can only be run on master NPU\n");
return;
}
count = strlen(acL->dc.argv[3])/2;
for(i = 0; i < count; i++)
{
c = tolower (acL->dc.argv[3][i*2]);
if (isdigit (c) || ((c >= 'a') && (c <= 'f')))
{
if(c <= '9')
buffer[i] = ((unsigned char)(c - '0'))<<4;
else
buffer[i] = ((unsigned char)(c - 'a' + 10))<<4;
}
c = tolower (acL->dc.argv[3][i*2 + 1]);
if (isdigit (c) || ((c >= 'a') && (c <= 'f')))
{
if(c <= '9')
buffer[i] += (unsigned char)(c - '0');
else
buffer[i] += (unsigned char)(c - 'a' + 10);
}
}
i2c_page_write(acL->dc.hexArg[1], acL->dc.hexArg[2], buffer, count);
}
void install_other_isr(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -