📄 testmgr.c
字号:
/*
*---------------------------------------------------------------------------
*
* I N T E L P R O P R I E T A R Y
*
* COPYRIGHT (c) 2001 BY INTEL CORPORATION. ALL RIGHTS
* RESERVED. NO PART OF THIS PROGRAM OR PUBLICATION MAY
* BE REPRODUCED, TRANSMITTED, TRANSCRIBED, STORED IN A
* RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER
* LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,
* MAGNETIC, OPTICAL, CHEMICAL, MANUAL, OR OTHERWISE, WITHOUT
* THE PRIOR WRITTEN PERMISSION OF :
*
* INTEL CORPORATION
*
* 2200 MISSION COLLEGE BLVD
*
* SANTA CLARA, CALIFORNIA 95052-8119
*
*---------------------------------------------------------------------------
*/
#include "memory.h"
#include "common.h"
#include "diagstruct.h"
#include "common_types.h"
#include "common_def.h"
#include "uart.h"
#include "hal_ixdp2400.h"
#include "console_monitor.h"
#include "diag_utils.h"
#include "misc_func.h"
#include "diag.h"
#include "mac_diag.h"
// function prototypes
extern char* Get_CPU(void);
extern int Get_CPU_Speed(void);
extern int Get_CPU_Rev(void);
extern int Get_SRAM_Size(void);
extern int Get_SDRAM_Size(void);
extern int Get_Host_Type(void);
extern void I2C_Test(void);
extern void mac_test(void);
void DiagTests(void);
void PrintBanner(void);
extern void cmd_reset(void);
void parseCmd(char *string, UINT pntr, int index);
extern void makeNumber(int i);
DiagCmd *findCmd(unsigned int pntr, int idx);
void cmd_help(void);
extern UINT32 sram_size[2];
/* Main Command Table */
DiagCmd ptlonecmdarray[] = {
{ "help", "s", 5, cmd_help, 0, "print this message" },
{ "?", "s", 5, cmd_help, 0, "print this message" },
{ "h", "s", 5, cmd_help, 0, "print this message" },
{ "test", "s", 3, DiagTests, 0, "test, type t <cr> for help"},
{ "t", "s", 3, DiagTests, 0, "test, type t <cr> for help"},
{ "banner", "", 0, PrintBanner, 1, "Print Banner "},
{ "exit", "", 0, cmd_reset, 1, "Exit Diagnostics"},
{ "p", "xx", 0,cmd_print, 0, "<low> <high> print memory (32 bit)" },
{ "pb", "xx", 0,cmd_print, 2, "<low> <high> print memory (8 bit)" },
{ "pw", "xx", 0,cmd_print, 1,"<low> <high> print memory (16 bit)" },
{ "pd", "xx", 0,cmd_print, 0, "<low> <high> print memory (32 bit)" },
{ "c", "x", 0,cmd_change, 0, "change memory (32 bits)" },
{ "cb", "x", 0,cmd_change, 2, "change memory (8 bits)" },
{ "cw", "x", 0,cmd_change, 1, "change memory (16 bits)" },
{ "cd", "x", 0,cmd_change, 0, "change memory (32 bits)" },
{ "viewlog", "D", 0, cmd_viewlog, 1, "View the entries in the log"},
{ "clearlog", "", 0, syslog_clear, 0, "Clear all entries in the log"},
{ "setverbose", "d", 0, cmd_set_verbose, 1, "Set verbose level <verbose_level>"},
{ 0, 0, 0, 0,0,0}
};
/* Diagnostic Command Table */
DiagCmd ptlonetestarray [] = {
{ "mac", "sssddd", 0, mac_test, 0, "<test_option><test_param><channel_opt><speed><port>[loop_count]"},
{0,0,0,0,0,0}
};
void DiagTests(void)
{
register PDiagCommon acL = (PDiagCommon) ACADDRESS;
DiagCmd *findCmd(UINT, int), *cmd;
if (acL->argc == 1)
{
eprintf("\nusage: t mac <name> <args>\n");
return;
}
cmd = findCmd((UINT)ptlonetestarray,1); /* find the command in our table */
if (cmd != 0)
{
acL->numArgs = cmd->numArg; /* load up the arguments */
(*(cmd->routine))(); /* call the requested routine now... */
}
else
eprintf("unknown test command\n");
}
void PrintBanner(void)
{
register PDiagCommon acL = (PDiagCommon) ACADDRESS;
//int i;
//unsigned short regVal;
//char *resultStr;
eprintf("\n%s Board Diagnostics Build %s, %s\n", acL->targetName, __TIME__, __DATE__);
eprintf("DRAM:%d Mb,\n", acL->SDRAMSize/1024/1024);
eprintf("SRAM:%d Mb; Ch0: %d Mb, Ch1: %d Mb,\n",
acL->SRAMSize/1024/1024,
sram_size[0]/1024/1024,
sram_size[1]/1024/1024);
}
/* getCommands
Function:
*/
void getCommands(void)
{
register PDiagCommon acL = (PDiagCommon) ACADDRESS;
if(acL->HostType == MASTER)
//parseCmd("MSTR_PTLONE_DIAG> ",(UINT)ptlonecmdarray,(int)0); // the prompt of course
parseCmd("MASTER_DIAG> ",(UINT)ptlonecmdarray,(int)0); // the prompt of course
else
//parseCmd("SLV_PTLONE_DIAG> ",(UINT)ptlonecmdarray,(int)0); // the prompt of course
parseCmd("SLAVE_DIAG> ",(UINT)ptlonecmdarray,(int)0); // the prompt of course
}
//
// Function: parseCmd
//
// Decription: Displays the prompt, then gets users input.
// Separates user arguments to their respective
// arrays. Calls findCmd and calls the routine
// if the command matches a routine
//
void parseCmd(char *string, UINT pntr, int index)
{
register PDiagCommon acL = (PDiagCommon) ACADDRESS;
DiagCmd *findCmd(UINT, int), *cmd;
char* s;
int i = 0;
bzero(acL->cmdLine, 128); /* initialize the command buffer */
eprintf("%s",string);
getCmdLine(acL->cmdLine); // read user input from command line
s = acL->cmdLine; // point to the cmdLine buffer
// Clear arg count, and all the arguments
acL->argc = 0;
for(i = 0; i < 10; i++)
{
acL->hexArgOk[i] = FALSE;
acL->decArgOk[i] = FALSE;
acL->hexArg[i] = 0;
acL->decArg[i] = 0;
acL->argv[i] = 0;
}
while(1)
{
while(*s == ' ') // skip spaces
s++;
if (*s == 0) // if end of string, exit scanner
break;
acL->argv[acL->argc++] = s; // store beginning of string
if (*s == '"')
{
acL->argv[acL->argc - 1]++;
while ((*s != '"') && (*s != 0))
s++; // skip argument
if(*s == '"')
*s++ = 0;
}
else
{
while((*s != ' ') && (*s != 0))
s++; // skip argument
if(*s == ' ')
*s++ = 0; // put in a terminator, if necessary
}
}
if(acL->argc == 0)
return;
for (i = 1; i < acL->argc; i++) makeNumber(i);
// Search for the command in our command table
cmd = findCmd(pntr,index);
if(cmd != 0)
{
acL->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 PDiagCommon acL = (PDiagCommon) ACADDRESS;
char *s, c;
int v = 0;
s = acL->argv[i]; /* initialize all the arrays */
acL->hexArg[i] = 0;
acL->decArg[i] = 0;
acL->decArgOk[i] = TRUE;
acL->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->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->hexArgOk[i] = FALSE;
}
if (acL->decArgOk[i]) /* fill in the decimal argument array */
acL->decArg[i] = (acL->decArg[i] * 10) + v;
if (acL->hexArgOk[i]) /* fill in the hex argument array */
acL->hexArg[i] = (acL->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 PDiagCommon acL = (PDiagCommon) 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->argv[idx], p->cmdw) == 0)
{
matchOk = TRUE; /* we found a match, now check syntax */
wantargs = strlen(p->syntax);
//if(wantargs == (acL->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->hexArgOk[i+idx])
matchOk = FALSE;
if (syn_curr=='x' && (i+idx) < acL->argc && !acL->hexArgOk[i+idx])
matchOk = FALSE;
if ((syn_curr =='D') && !acL->decArgOk[i+idx])
matchOk = FALSE;
if (syn_curr=='d' && (i+idx) < acL->argc && !acL->decArgOk[i+idx])
matchOk = FALSE;
if (syn_curr=='S' && i >= acL->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->argv[1],p->helpstr);
else
eprintf("syntax error... type 'h %s'\n",acL->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 PDiagCommon acL = (PDiagCommon) ACADDRESS;
DiagCmd *p;
char *s, syncmd;
p = (DiagCmd *) &ptlonecmdarray[0];
if (acL->argc == 1)
{
eprintf("\n****************************************************************************\n");
eprintf("\t\t\tPoint Lone Command HELP MENU\n");
eprintf("Access Commands:\n");
eprintf("p[bwd].......print memory contents c[bwd].......change memory contents\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->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++;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -