⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drive42.cpp

📁 The Lite Evaluation/Demonstration Kit is intended to illustrate use of the AN3042. The AN3042 is c
💻 CPP
📖 第 1 页 / 共 3 页
字号:

// Returns chip type of DUT (Device Under Test).
int chipType (void)
{
	return (CHIP3042);
}

// A wrapper so we do the error checking, but don't have to code it every time we call the VxD.
DWORD callGetPCIInfo (PCI_CONFIG_HEADER_0 *pciCfg, DWORD comemID)
{
	DWORD returnCode;

    returnCode = comemGetPCIInfoL(pciCfg, comemID);
    if (returnCode != NO_ERROR)
    {
        reportErrorCode(returnCode, "while reading PCI configuration.");
    }
    return returnCode;
}


/*
DWORD testConfigRegs (DWORD comemID)
{
    DWORD returnCode;
    PCI_CONFIG_HEADER_0  temp, orig;

	// Get original reg set.
    returnCode = callGetPCIInfo(&temp, comemID);
 	printf ("Original: Command=%04x Status=%04x LatencyTimer=%04x BAR0=%08x\n", 
	           temp.Command, temp.Status, temp.LatencyTimer, temp.BaseAddresses[0]);
	_flushall();
	// Save entire reg set for checking below.
	orig = temp;

	// Complement elements, then write back.
	temp.Command          = ~temp.Command;
	temp.Status           = ~temp.Status;
	temp.LatencyTimer     = ~temp.LatencyTimer;
	temp.BaseAddresses[0] = ~temp.BaseAddresses[0];
 	printf ("CmplmntW: Command=%04x Status=%04x LatencyTimer=%04x BAR0=%08x\n", 
		       temp.Command, temp.Status, temp.LatencyTimer, temp.BaseAddresses[0]);
	_flushall();
    comemSetPCIInfo(&temp, comemID);

    // Get complement from actual Config Regs.
	returnCode = callGetPCIInfo(&temp, comemID);
 	printf ("CmplmntR: Command=%04x Status=%04x LatencyTimer=%04x BAR0=%08x\n", 
		       temp.Command, temp.Status, temp.LatencyTimer, temp.BaseAddresses[0]);
	_flushall();

	// Complement the complement (to restore the original).  Write them back.
	temp.Command          = ~temp.Command;
	temp.Status           = ~temp.Status;
	temp.LatencyTimer     = ~temp.LatencyTimer;
	temp.BaseAddresses[0] = ~temp.BaseAddresses[0];
    comemSetPCIInfo(&temp, comemID);

	// Read them to confirm that they are restored.
    returnCode = callGetPCIInfo(&temp, comemID);
 	printf ("Restored: Command=%04x Status=%04x LatencyTimer=%04x BAR0=%08x\n",
		       temp.Command, temp.Status, temp.LatencyTimer, temp.BaseAddresses[0]);
	_flushall();

	// Check Config Regs.
	if (temp.VendorID != 0x12be)
	{
		printf ("Bad config.VendorID. Was %04x. Should be 0x12be.\n",               temp.VendorID);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if ((temp.DeviceID != 0x3041) && (temp.DeviceID != 0x3042))
	{
		printf ("Bad config.DeviceID. Was %04x. Should be 0x3041 or 0x3042.\n",     temp.DeviceID);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if ((temp.SubsystemVendorID != 0) && (temp.SubsystemVendorID != 0x12be))
	{
		printf ("Bad config.SubsystemVendorID. Was %04x. Should be 0 or 0x12be.\n", temp.DeviceID);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if (temp.SubsystemID != 0)
	{
		printf ("Bad config.SubsystemID. Was %04x. Should be 0.\n",                 temp.SubsystemID);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if (temp.Command != orig.Command)
	{
		printf ("Bad config.Command read/write/read. Was %04x. Should be %04x\n",
						temp.Command, orig.Command);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if (temp.Status != orig.Status)   // Since config.Status is Read-only, damn well better be correct.
	{
		printf ("Bad config.Status read/write/read. Was %04x. Should be %04x\n",
						temp.Status, orig.Status);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if (temp.LatencyTimer != orig.LatencyTimer)
	{
		printf ("Bad config.LatencyTimer read/write/read. Was %04x. Should be %04x\n",
						temp.LatencyTimer, orig.LatencyTimer);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	if (temp.BaseAddresses[0] != orig.BaseAddresses[0])
	{
		printf ("Bad config.BaseAddresses[0] read/write/read. Was %08x. Should be %08x\n",
						temp.BaseAddresses[0], orig.BaseAddresses[0]);			
		_flushall();
		returnCode = ERROR_CONFIG_REG_TEST;
	}

	return (returnCode);
}

*/


void errorHandler(DWORD addr, DWORD read1, DWORD read2, DWORD wrote)
{
	struct _timeb tstruct;
	char tbuf[128];

	_strtime( tbuf );		// Get hh:mm:ss
	_ftime( &tstruct );		// Get milliseconds

	// print to stdout (the console)
	printf (
			"\nE%3d  A%08x  R1 %08x  R2 %08x  W%08x  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         addr,  read1,   read2,   wrote, passNum, tbuf, tstruct.millitm );


	logFilePtr = fopen (logFileName, "a+");
	if (!logFilePtr)
		printf ( "\nError: log file was not opened for append." );

	// print to the log file
	fprintf (logFilePtr,
			"\nE%3d  A%08x  R1 %08x  R2 %08x  W%08x  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         addr,  read1,   read2,   wrote, passNum, tbuf, tstruct.millitm );

	if (fclose (logFilePtr))
		printf( "\nError: log file was not closed after an append." );
}  // end errorHandler ()


// Only diff functionally (!) between errorHandler and errorHandler2:
//     errorHandler2 takes a parameter expectErrors.
void errorHandler2(DWORD addr, DWORD read1, DWORD read2, DWORD wrote, enum ExpectErrs expect )
{
	struct _timeb tstruct;
	char tbuf[128];

	_strtime( tbuf );		// Get hh:mm:ss
	_ftime( &tstruct );		// Get milliseconds

	logFilePtr = fopen (logFileName, "a+");
	if (!logFilePtr)
		printf ( "\nError: log file was not opened for append." );

	if (expect == MUSTpass)  // Clearly mark the console and log with asterisks if the error is not expected.
	{
		// print to stdout (the console)
		printf (
			"\n********E%3d  A%08x  R1 %08x  R2 %08x  W%08x  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         addr,  read1,   read2,   wrote, passNum, tbuf, tstruct.millitm );

		// print to the log file
		fprintf (logFilePtr,
			"\n********E%3d  A%08x  R1 %08x  R2 %08x  W%08x  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         addr,  read1,   read2,   wrote, passNum, tbuf, tstruct.millitm );
	}
	else
	{
		// print to stdout (the console)
		printf (
			"\nE%3d  A%08x  R1 %08x  R2 %08x  W%08x  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         addr,  read1,   read2,   wrote, passNum, tbuf, tstruct.millitm );

		// print to the log file
		fprintf (logFilePtr,
			"\nE%3d  A%08x  R1 %08x  R2 %08x  W%08x  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         addr,  read1,   read2,   wrote, passNum, tbuf, tstruct.millitm );
	}

	if (fclose (logFilePtr))
		printf( "\nError: log file was not closed after an append." );
}  // end errorHandler2 ()


void errorHandler3(char * errstring, enum ExpectErrs expect)
{
	struct _timeb tstruct;
	char tbuf[128];

	_strtime( tbuf );		// Get hh:mm:ss
	_ftime( &tstruct );		// Get milliseconds

	logFilePtr = fopen (logFileName, "a+");
	if (!logFilePtr)
		printf ( "\nError: log file was not opened for append." );

	if (expect == MUSTpass)  // Clearly mark the console and log with asterisks if the error is not expected.
	{
		// print to stdout (the console)
		printf (
			"\n********E%3d  %s  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         errstring, passNum, tbuf, tstruct.millitm );

		// print to the log file
		fprintf (logFilePtr,
			"\n********E%3d  %s  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         errstring, passNum, tbuf, tstruct.millitm );
	}
	else
	{
		// print to stdout (the console)
		printf (
			"\nE%3d  %s  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         errstring, passNum, tbuf, tstruct.millitm );

		// print to the log file
		fprintf (logFilePtr,
			"\nE%3d  %s  P%9d  T%s.%3d", 
		       globalErrorCnt,
			         errstring, passNum, tbuf, tstruct.millitm );
	}

	if (fclose (logFilePtr))
		printf( "\nError: log file was not closed after an append." );
}  // end errorHandler3 ()


/*

//
// getlinBAR0
//
DWORD getlinBAR0(DWORD comemID)
{
    // Get a pointer to the Shared Memory area (BAR 0)
    DWORD linBAR[COMEM_MAX_BARS];
	DWORD dummy1, dummy2;

    DWORD returnCode = comemCopyBarPtr(linBAR, &dummy1, &dummy2, comemID);
    if (returnCode != NO_ERROR)
        {
        reportErrorCode(returnCode, "creating BAR pointers.");
        }

	return (linBAR[0]);
}

*/




//////////////////////////////////////////////////////////////////////
// In order for the co-mem device to operate properly, it must be 
// configured correctly by the system BIOS.  If it is not configured
// correctly, this routine attempts to reconfigure it.
//////////////////////////////////////////////////////////////////////
/*
DWORD verifyComemConfig(DWORD comemID)
{
    DWORD returnCode;
    PCI_CONFIG_HEADER_0 pciCfg;

    returnCode = comemGetPCIInfo(&pciCfg, comemID);
    if (returnCode != NO_ERROR)
    {
        reportErrorCode(returnCode, "while reading PCI configuration.");
        return returnCode;
    }

    if (pciCfg.LatencyTimer < 0x10)
        report_error("Warning:  Latency Timer is less than 16!");

    // If the PCI host has disabled our memory, we cannot perform any functions.
    // This is not a recoverable error, since we have no idea where to locate
    // ourselves in memory space if the BIOS doesn't do it for us.
    if (!(pciCfg.Command & 0x2))
        {
        report_error("Memory is disabled!!  Co-mem will not work.!");
        exit(1);
        }

    if (!(pciCfg.Command & 0x8))
        {
        report_error("Bus mastering not enabled by BIOS. COMEM requires bus master capability, so is about to be enabled by driver.");
        pciCfg.Command |= 0x8;
        comemSetPCIInfo(&(pciCfg), comemID);
        }


    // The SERR bit controls the reporting of parity errors by our device during 
    // other device's address cycles.  Since we have seen some PCI devices generate
    // incorrect parity, we disable this bit to prevent the co-mem from stopping
    // the system on an address parity error.
    while (pciCfg.Command & 0x100)
        {
        int old = pciCfg.Command;
        pciCfg.Command &= ~0x100;
        pciCfg.Status = 0;
        comemSetPCIInfo(&(pciCfg), comemID);

        // Use the dialog box to ensure that we wait a while before reading the regs
        comemGetPCIInfo(&(pciCfg), comemID);
        report_error("SERR was enabled.  It has been disabled. (Command reg %04x, ==>%04x)", old, pciCfg.Command);
        }

    return NO_ERROR;
}
*/

/*
void initLogFile(void)
{
	char dbuf[128];
	char tbuf[128];
	char cwdbuf[_MAX_PATH];

    _strdate( dbuf );		// Get date.
    _strtime( tbuf );		// Get hh:mm:ss

   if( _getcwd( cwdbuf, _MAX_PATH ) == NULL )    // Get the current working directory
      printf( "\n_getcwd error\n" );

	logFilePtr = fopen (logFileName, "a+");
	if (!logFilePtr)
		printf ( "\nError: could not open log file for append." );

	// print to the log file
	fprintf (logFilePtr,
			"%s   Date %s  Time %s\n", 
		     cwdbuf, dbuf, tbuf);

	if (fclose (logFilePtr))
		printf( "\nError: could not close log file after an append." );

	printf ("\nLog file header written.\n");
}  // end initLogfile ()


void finishLogFile(void)
{
	char dbuf[128];
	char tbuf[128];
	char cwdbuf[_MAX_PATH];

    _strdate( dbuf );		// Get date.
    _strtime( tbuf );		// Get hh:mm:ss

   if( _getcwd( cwdbuf, _MAX_PATH ) == NULL )    // Get the current working directory
      printf( "\n_getcwd error\n" );

	logFilePtr = fopen (logFileName, "a+");
	if (!logFilePtr)
		printf ( "\nError: could not open log file for append." );

	// print to the log file
	fprintf (logFilePtr,
			"\nSummary when quit: Errors %d  Passes %9d  Date %s  Time %s\n", 
		     globalErrorCnt,   passNum, dbuf, tbuf);

	if (fclose (logFilePtr))
		printf( "\nError: could not close log file after an append." );

	printf ("\nLog file trailer written.\n");
}  // end finishLogFile ()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -