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

📄 testmem.cpp

📁 The Lite Evaluation/Demonstration Kit is intended to illustrate use of the AN3042. The AN3042 is c
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////
//
// File: TestMem.cpp
//
// Purpose: Memory Tests.
//
// $Header: /ComemL/Host/Test3042/TestMem.cpp 44    11/25/98 11:54a Tpm $
// Copyright (c) 1998-2000 Anchor Chips, Inc. May not be reproduced without permission.
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Test3042.h"
#define printf theApp.Out

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>		// For report_error()
#include <conio.h>		// for getch()
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/locking.h>
#include <io.h>
#include <fcntl.h>
#include <share.h>

typedef unsigned long DWORD;
#include "comemLdv.h"
#include "comemdrv.h"

#define DWORD DWORD

// prototypes
void report_error(const char *fmt, ...);
void reportErrorCode(DWORD status, char * whereAmI);
DWORD verifyComemConfig(DWORD comemID);

DWORD memcmp(unsigned char *a, unsigned char *b, DWORD len);
void write9710CRAM(unsigned char *a, unsigned char *b, DWORD len);
void read9710CRAM(unsigned char *a, unsigned char *b, DWORD len);
unsigned char * checkerboardTest(unsigned char *start, DWORD len);
unsigned char * walk0Test(unsigned char *start, DWORD len);
unsigned char * walk1Test(unsigned char *start, DWORD len);

////////////////////////////////////////////////////////////
//
// Function:  hw_tests
//
// Purpose:  Perform the entire suite of hardware tests
//
// Parameters:  none
//
// Return value:  returns 0 for good, error code for 
//						failure 
//
////////////////////////////////////////////////////////////
DWORD hw_tests()
{
	DWORD retval = 0;
/*
	// walk a bit across the 9710 register space
	{
	DWORD i, j;
	for (i = 0; i < 0x8; i++)
		for (j = 1; j; j <<= 1)
			write9710reg(i, j);
	}
*/
	// Debug code -- Run the RAM test a tiny area
	if ((retval = (DWORD)checkerboardTest(0, 0x40)) != 0)
		return retval;

	if ((retval = (DWORD)walk0Test(0, 0x40)) != 0)
		return retval;

	// 
	if ((retval = (DWORD)walk1Test(0, 0x40)) != 0)
		return retval;

	// Run the RAM test on the compression RAM
	if ((retval = (DWORD)checkerboardTest(0, 0x4000)) != 0)
		return retval;

	if ((retval = (DWORD)walk0Test(0, 0x4000)) != 0)
		return retval;

	// 
	if ((retval = (DWORD)walk1Test(0, 0x4000)) != 0)
		return retval;

	return retval;
}

////////////////////////////////////////////////////////////
//
// Function:  read_loop, write_loop
//
// Purpose:  Scope loops.  Must be manually called from the debugger.
//
// Parameters:  none
//
// Return value:  These functions do not return.  They sit forever.
//
////////////////////////////////////////////////////////////
void read_loop(long *ptr)
{
	volatile long *vptr = ptr;
	volatile long i;

	// scope loop to read a location forever
//	while (1)
		i = *vptr;
}

void write_loop(long *ptr, long value)
{
	volatile long *vptr = ptr;

	// scope loop to write a location forever
//	while (1)
		*vptr = value;
}

///////////////////////////////////////////////////////////////////////
//
// Function: walkBitTest
//
// Purpose:
// 	Generic routine used to implement all of the RAM tests.
//		Walk a bit across the memory space specified.  Check that the data is
// 	still there afterwards.  
//
// Parameters:
// 	startVal -- Specifies the first value to write.  Use 0 for walking 0 test,
//		   use ((long)-2) for walking 1 test.
// 	endVal -- Specifies the value that tells that we are done.  Use 0 for
//    	walking 1 test, -1 for walking 0 test.
// 	shiftIn -- Specifies the value to shift in.  Use 0 for walking 1 test, 
//    	1 for walking 0 test.
//
// 	You can do a checkerboard test too.  Use startVal = 0x5555 5555,
// 	endVal = 0xaaaa aaaa, and shiftIn = 0;
//
//		patternLenLong -- Length of pattern in DWORD's.
//		patternBuf -- Pointer to buffer of len (patternLenLong*2) in RAM
//		memcopy	-- pointer to function to use as memcopy
//		memcmp -- pointer to fn to use as memcmp
//
// Returns:
//		NULL -- No errors
//		!NULL -- Location of error
//
///////////////////////////////////////////////////////////////////////
unsigned char *
	walkBitTest(unsigned char *start,
						DWORD lenChar,
						DWORD startVal,
						DWORD endVal,
						DWORD shiftIn,
						DWORD patternLenLong,
						DWORD *patternBuf,
						void memmoveTo(  unsigned char *, unsigned char*, DWORD len),
						void memmoveFrom(unsigned char *, unsigned char*, DWORD len),
						DWORD memcmp(     unsigned char *, unsigned char*, DWORD len)
						)
{
	DWORD i;
	DWORD pattern;
	DWORD patternLenChar = patternLenLong * sizeof(DWORD);

	////////////////////////////////////////////////////////////
	// First, fill the buffer with the pattern and check it.
	pattern = startVal;
	for (i = 0; i < patternLenLong * 2; i++)
		{
		patternBuf[i] = pattern;

		////////////////////////////////////////////////////////////
		// Move the bit over.  If it's zero, we want to write the zero, then
		// update pattern to startVal.  This makes the pattern 33 bits long, not 32.
		#define UPDATE_PATTERN			\
			{if (pattern == endVal)		\
				pattern = startVal;		\
			else								\
				{								\
				pattern <<= 1;				\
				pattern |= shiftIn;		\
				}}
		// Macro end
		////////////////////////////////////////////////////////////

		UPDATE_PATTERN;
		}

	// Check the memory for the pattern.
	pattern = startVal;
	for (i = 0; i < patternLenLong; i++)
		{
		if (patternBuf[i] != pattern)
			return (unsigned char *) (patternBuf+i);

		UPDATE_PATTERN;
		}
	//
	//	Done filling memory w/ pattern
	////////////////////////////////////////////////////////////



	////////////////////////////////////////////////////////////
	// Outermost loop -- Loop through all starting points within
	// the pattern buffer.  This should give is the walking bit
	// effect within each memory cell.
	//
	// Innermost loop -- Copy to entire memory.  This gives us the
	// walking bit effect from cell to cell.
	////////////////////////////////////////////////////////////
	{
		DWORD pat_start;
		DWORD compareBuf[0x100];

		for (pat_start = 0; pat_start < patternLenLong; pat_start++)
			{
			for (i = 0; i < lenChar; i+=patternLenChar)
				{
				memmoveTo(start+i, (unsigned char *) (patternBuf + pat_start), patternLenChar);
				}

			for (i = 0; i < lenChar; i+=patternLenChar)
				{
				memmoveFrom((unsigned char*) compareBuf, (start+i), patternLenChar);
				if (memcmp((unsigned char*)compareBuf, (unsigned char*) (patternBuf + pat_start), patternLenChar))
					return(start+i);
				}

			}
	}

	return(0);
}

///////////////////////////////////////////////////////////////////////
//
// Function: walk1Test
//
// Purpose:  Implement walking 1's test using the walkBitTest fn
//
// Returns:  0 or pointer to bad cell.
//
///////////////////////////////////////////////////////////////////////
unsigned char * walk1Test(unsigned char *start, DWORD len)
{
	DWORD patternBuf[33 * 2];

	return(walkBitTest(start, len, 1UL, 0UL, 0UL, 33*2, patternBuf, &write9710CRAM, &read9710CRAM, &memcmp));

}

///////////////////////////////////////////////////////////////////////
//
// Function: walk0Test
//
// Purpose:  Implement walking 0's test using the walkBitTest fn
//
// Returns:  0 or pointer to bad cell.
//
///////////////////////////////////////////////////////////////////////
unsigned char * walk0Test(unsigned char *start, DWORD len)
{
	DWORD patternBuf[33 * 2];

	return(walkBitTest(start, len, (long) -2, (long) -1, 1UL, 33*2L, patternBuf, write9710CRAM, read9710CRAM, memcmp));
}

///////////////////////////////////////////////////////////////////////
//
// Function: checkerboardTest
//
// Purpose:  Implement checkerboard using the walkBitTest fn
//
// Returns:  0 or pointer to bad cell.
//
///////////////////////////////////////////////////////////////////////
unsigned char * checkerboardTest(unsigned char *start, DWORD len)
{
	DWORD patternBuf[2 * 2];
	return(walkBitTest(start, len, 0x55555555L, 0xaaaaaaaaL, 0L, 2*2L, patternBuf, write9710CRAM, read9710CRAM, memcmp));
}



///////////////////////////////////////////////////////////////////////
//
// Function: memcmp
//
// Purpose:  Replace the library call to memcmp.
//
// Returns:  0, -1, +1
//
///////////////////////////////////////////////////////////////////////
DWORD memcmp(unsigned char *a, unsigned char *b, DWORD len)
{
	for (; len; len--, a++, b++)
		if (*a != *b)
			return (*a-*b);

	return 0;
}

///////////////////////////////////////////////////////////////////////
//
// Function: write9710CRAM
//
///////////////////////////////////////////////////////////////////////
void write9710CRAM(unsigned char *a, unsigned char *b, DWORD len)
{
}

///////////////////////////////////////////////////////////////////////
//
// Function: read9710CRAM
//
///////////////////////////////////////////////////////////////////////
void read9710CRAM(unsigned char *a, unsigned char *b, DWORD len)
{
}

⌨️ 快捷键说明

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