drv_test.c 3.71 KB
/*************************************************************************
 *
 *  File: drv_test.c
 * 
 *  This file is used to test USB driver by calling sim.ipc
 *  
 *  To test USB driver, we need four part of codes
 *  (1) rom file build with libultra(with UI manager + expection handler)
 *  (2) start_rom (you need to specify ROM_ADDR for your rom file)
 *      It used to do initializaton and jump to your rom in ddr
 *  (3) sim.cpu.ipc (ipc based cpu simulator)
 *  (4) This file, to write data into ddr via backdoor at beginning
 *      
 */
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>

#include "iomap.h"
#include "iotest.h"
#include "sim.h"
#include "simipc.h"
#include "trace.h"
#include "drv_test.h"

/***********************************************************************
 * Extern definitions
 */
extern  TstCmd  TstCmdTbl[];

/***********************************************************************
 * Macro definitions
 */
#define TEST_CMD_FILE   "all.tst"
#define OPTARG      "d:l:r:kh"


/***********************************************************************
 * Global definitions
 */
int     IpcFd = -1;
unsigned long   Dflags;
char        *CmdFile = TEST_CMD_FILE;
FILE        *LogFp, *CmdFp;
int     ConfigRdramV = 0;
int             NumberStallCycles = 0;


/***********************************************************************
 * Local static definitions
 */
static FILE     *dumpFp = NULL;

static void     usage(void);
static void     convertTst2C(char *);

int main(int argc, char **argv)
{

    int c, testId, killsim=0, gateLevel=0;
    char    *file, rom_file[1024];
    FILE    *fp = NULL;

    extern char *optarg;
    extern int optind, opterr, optopt;

    optind = 1;
    Dflags = 0;
    LogFp  = stdout;
	rom_file[0] ='\0'; 		

    while ((c = getopt(argc, argv, OPTARG)) != EOF) {
        switch (c) {
            case 'd': { /* Debug flag */
                Dflags = strtoul(optarg, NULL, 16);
                printf("Debug flag=0x%08x\n", Dflags);
                break;
            }
            case 'l': { /* Log file */
                file = optarg;
                printf("Log file = %s\n", file);
                if ((fp = fopen(file, "w+")) == NULL) {
                    printf("Unable to open log: %s\n",
                        file);
                }
                else
                    LogFp = fp;
                break;
            }
            case 'r': { /* rom file to be loaded */
                strcpy(rom_file,optarg);
                break;
            }
            case 'k': { /* kill simulator on exit */
                killsim=1;
                break;
            }
            case 'h': { /* Help */
                usage();
                exit(0);
            }
            default:
                break;
        }
    }  /* while */

    ExceptionHandlerInit();
    IpcInit(NULL);
    FindServer();

	if (strlen(rom_file))  {
		if (load_rom_into_ddr(rom_file)) { /* load  rom file succeed */
			stimulate_usb(0);
		} else {
			_TRACE(DLOG, fprintf(LogFp, "loading rom file failed"));	
		}
	}

    if (fp)
        fclose(fp);

    if (IpcFd != -1)
        IpcClose(IpcFd);

    /* exit simulator */
    if(killsim)
        IoCmd(REQ_QUIT, 0);

    exit(0);

}

static void
usage(void)
{
    printf("Usage: drv_test \n");
    printf("   -l <log_file>\n");
    printf("   -r <rom file>\n");
    printf("   -d <debug_flags in hex>\n");
    printf("         NOTE: DLOG | DSTATUS | DERROR always on\n");
    printf("   -k\n");
    printf("         Use this option to kill the simulator on exit\n");
    printf("   -g\n");
    printf("         Use this option to only run gate-level testing\n");

	return; 
}