/**     diag_mon.h
 **
 ** Author: Ted Schmitz
 ** Date of original creation December 4, 2008
 **
 **/
#if 0 /* moved to the end of this file */
#include "diag_mon_platform_dep.h" /* include appropriate platform dependent
                                      monitor definitions. */
#endif

#define DIAG_MON_VERSION "1.0.0 " /* Current BIST code version number */

#define MAXARGS 20              /* maximum arguments on diagnostic monitor
				   command line including the command. */
#define BELL 0x07		/* ASCII/hex bell character */
#define MAX_INPUT_LINE_SIZE 100 /* maximum number of characters allowed on
                                   any input line */
#define MAX_EC_LINE_SIZE 10     /* max chars entered for new execution count */
#define MAX_DISP_LINES 30       /* max lines to display at one time */

#ifdef STANDALONE /* debugging monitor with standard GCC tools */
/**	The following symbols define all the possible subtest types used in the
 ** "test_type" field of the test table.  This field defines what the subtest
 ** varifies.  The subtest can be part of the board test, the fabric tests,
 ** the I2C tests, etc.
 **/
#define TT_CA  00		/* this is a board or card test */
#define TT_FA  01		/* this is a fabric test */
#define TT_I2C 02		/* this is an I2C bus test */
#define TT_EN  03		/* this is an ethernet test */
/*
 * end "test_type" definitions
 */

/**	The following symbols define all the possible subtest modes used in the
 ** "Test Mode" field of the test table.  This field defines if the subtest
 ** effects or requires other hardware duting execution.  The subtest can be 
 ** a non-intrusive test, and intrusive test, or perhaps a port processor
 ** test, etc.
 **/
#define TM_NI 00		/* this is a non_intrusive test */
#define TM_IN 01		/* this is an intrusive test */
#define TM_PR 02		/* this is a port test */
#define TM_LB 03		/* this is a loop back test */
#define TM_NA 04        /* this test is currently not available */
/*
 * end "test_mode" definitions
 */

#else /* normal code for default platform */

/**	The following symbols define all the possible subtest types used in the
 ** "test_type" field of the test table.  This field defines what the subtest
 ** verifies.  The subtest can be part of the board test, the fabric tests,
 ** the I2C tests, etc.
 **/
#define TT_P1  00		/* this is an asembly language Phase 1 test */
#define TT_P2  01		/* this is a "C" phase two test */

/*
 * end "test_type" definitions
 */

/**	The following symbols define all the possible subtest modes used in the
 ** "Test Mode" field of the test table (if used).  This field defines if the 
 ** subtest effects or requires other hardware duting execution.  The subtest 
 ** can be a non-intrusive test, and intrusive test, or a port test, etc.
 **
 ** NOTE: These test modes are tenative.
 **/
#define TM_NI 00		/* this is a non_intrusive test */
#define TM_IN 01		/* this is an intrusive test */
#define TM_PR 02		/* this is a port test */
#define TM_LB 03		/* this is a loop back test */
#define TM_NA 04        /* this test is currently not available */
/*
 * end "test_mode" definitions
 */
#endif

#define ST_CMD_FROM_MONITOR 0   /* start command was invoked from monitor */
#define ST_CMD_FROM_EXT_SRC 1   /* start command was invoked from an external
                                   source */

#define DISABLE 0		/* disable subtests flag */
#define ENABLE 1		/* enable subtests flag */

extern char in_line[];          /* input line buffer (with a little cushion) */
extern int cur_loop;            /* current test execution loop */
extern int passes_completed;    /* number of times the test program has
                                   executed all tests selected. */
extern int test_failures;       /* number of tests that have failed */
extern int cur_test;            /* current test number */
extern int exec_count;          /* current test execution pass */
extern int param_count;         /* total paramters on command line including
                                   command itself. */
extern char *  args[];		/* pointer to arguments */
extern unsigned short test_modes;/* testing modes applied to all tests */
extern unsigned char ext_test_modes;/* extended testing modes */
extern int start_cmd_flag;      /* flag to indicate how "s" command was 
                                   invoked */

extern char comp_info[];	/* compile time, date, & number string */
extern unsigned long nv_test_sel_bits; /* test select bits retrieved from 
                                          non-volatile storage. */

extern int read_diag_data_from_nvram(unsigned char * buffer, 
                                     unsigned int offset,int length);

/*  Common command test table defines */
extern void clear_all_test_stats(void);
extern void clear_ram_stats(void);
extern void clear_nv_stats(void);
extern void setup_subtest_groups(void);
extern void disp_tests(void);
extern void sel_des_subtest(void);
extern void disp_stats(void);
extern void set_exec_count(void);
extern void set_error_mode(void);
extern void test_help(void);
extern void quit_test_menu(void);
extern void set_defaults(void);
extern void set_def_run(void);
extern void start_testing(void);
extern void set_test_modes(void);
extern char * gen_fgets(char * buffer, int max_chars);
extern int get_exec_count(int * count, unsigned long error_code);
extern int get_total_fails_count(int * count, unsigned long error_code);
extern int save_total_fails_count(int count, unsigned long error_code);

/* All the test command ASCII descriptions are defined here. 
* NOTE: Placing a capital "H" at the end of the command description string will
*       hide the command from being displayed but will still execute correctly. 
*/
#define CLEAR_MAINT \
  "CTlog                           Clear test log and all test stats\n"
#define DBLOCK_DES \
  "DBlock <b b b, all>             Deselect subtest block(s)\n"
#define DGROUP_DES \
  "DGroup <g g g, all>             Deselect subtest group(s)\n"
#define DISTESTS_DES \
  "Display [(test number)]         Display subtests and related information\n"
#define DSUBTEST_DES \
  "DSubtest <n n n, all>           Deselect subtest(s)\n"
#define DMAINT_DES \
  "DTlog                           Display test log & all test stats\n"
#define ECOUNT_DES \
  "ECount [n, 0=forever]           Display/set test program execution count\n"
#define EMODE_DES \
  "Emode [S, C, R, G, SK]          Display/select error mode\n"
#define HELP_DES \
  "Help                            Display this help menu\n"
#define MFG_SETUP_DISP \
  "MSetup                          Invoke Manufacturing Setup utility\n"
#define QUIT_DES \
  "Quit                            Quit this menu\n"
#define SBLOCK_DES \
  "SBlock <b b b, all>             Select subtest block(s)\n"
#define SDEFAULT_DES \
  "SDefaults                       Set all default parameters\n"
#define SDRUN_DES \
  "SDRun                           Set all default parameters and run tests\n"
#define SGROUP_DES \
  "SGroup <g g g, all>             Select subtest group(s)\n"
#define SMARGIN_DES \
  "SMargin [l] [n] [h], [c]        Select voltage margin(s) for test\n"
#define SPORT_DES \
  "SPort <p p p, all>              Select/display slave proc for testing\n"
#define STCOUNT_DES \
  "SSCount <sn count>              Set execution count for single subtest\n"
#define SSUBTEST_DES \
  "SSubtest <n n n, all>           Select subtest(s)\n"
#define STARTTEST_DES \
  "Start [c]                       Start executing all enabled subtests\n"
#ifdef INCL_AUTO_DISABLE_TM
#define SET_TEST_MOD_DES \
  "TMode [D DB E I Q L B CT EX AD, C] Display/select/clear test mode(s)\n"
#else
#define SET_TEST_MOD_DES \
  "TMode [D DB E I Q L B CT EX, C] Display/select/clear test mode(s)\n"
#endif
#define TEST_DES \
  "TEST                            Execute code currently under test\n"
  
#ifndef TRUE
#define TRUE 01                 /* non-zero is true */
#endif
#ifndef FALSE
#define FALSE 00                /* zero is always false */
#endif


/**     The following structure defines the elements in the test table used
 ** to select, execute, and display all the built-in tests.
 **/
struct tests
  {
  unsigned char test_number;    /* Unique test number reserved for this test */
  unsigned char block_number;   /* Block of test groups this test belongs to */
  unsigned char group_number;   /* Test group this tests belongs to */
  unsigned char enabled;        /* Enable flag for this test. 0=disabled */
  int test_type;		/* type of subtest: card, fabric, etc. */
  int test_mode;		/* mode of subtest: intrusive, non-intrusive, 
                                   etc. */
  unsigned int total_passes;    /* Num of times this test has been executed */
  unsigned int total_failures;  /* Number of times this test has failed */
    //void (*test)(void);           /* Pointer to the test routine */
  void * test;                  /* Pointer to the test routine */
  char * sign_on_message;       /* ASCII Test sign-on message */
  };

/**     The following structure defines the elements in the test commands table
 **  used to select, execute, and display all the subtests.
 **/
struct test_cmds
  {
  char * cmd_desc;              /* ASCII command description message */
  void (*cmd)(void);            /* pointer to the command routine */
  };

#include "diag_mon_platform_dep.h" /* include appropriate platform dependent
                                      monitor definitions. */
