test_ram.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 125 行

C
125
字号
/****************************************************************************
 * File: test_ram.c
 * Purpose: RAM TESTS.
 ***************************************************************************/

#ifdef SDBTESTS
#include "standalone.h"
#include "platform.h"
#else SDBTESTS
// #include "main.h"
#endif SDBTESTS
#include "ram.h"

int (*printFunc)();
extern char *errorText;

#define BUS_WIDTH 32

extern DWORD
	user_ram, user_ram_end;

#ifdef SDBTESTS
extern unsigned ulRamBufStart, ulRamBufEnd;
memorySpace_t memorySpace[] = 
{
	{ 0, 0 },	 // Memory addresses would be filled in later.
	{ (unsigned long *)(0xffffffff) },
};
#else SDBTESTS
const memorySpace_t memorySpace[] = 
{
	{ &user_ram, &user_ram_end },
	{ (unsigned long *)(0xffffffff) },
};
#endif SDBTESTS

short testMemorySpace(memorySpace_t * pMemorySpace)
{
	WORD
		result = 0;

	register DWORD
		i,
		busTestData,
		*pStart,
		*pEnd;

	pStart = pMemorySpace->baseAddress;
	pEnd = pMemorySpace->endAddress;
	(*printFunc)("\r\nTesting RAM from %X to %X", pStart, pEnd);

	(*printFunc)("\r\nWriting address-as-data         ");
	while (pStart < pEnd)
	{
		if ( !((DWORD)pStart & 0xffffL) )
			(*printFunc)("\b\b\b\b\b\b\b\b%x", pStart);
		*pStart = (DWORD)pStart;
		pStart++;
	}

	(*printFunc)("\r\nComparing data         ");

	pStart = pMemorySpace->baseAddress;
	while (pStart < pEnd)
	{
		if ( !((DWORD)pStart & 0xffffL) )
			(*printFunc)("\b\b\b\b\b\b\b\b%X", pStart);
		if (*pStart != (DWORD)pStart)
		{
			(*printFunc)("\n\tError at %X. Data: %X", pStart, *pStart);
			errorText = "Address-as-data memory test";
			result = 1;
			//break;
		}
		pStart++;
	}

	(*printFunc)("\r\nWalking '1' across the data bus                 ");
	pStart = pMemorySpace->baseAddress;
	for (i = 0; i < BUS_WIDTH; i++)
	{
		busTestData = 1 << i;
		(*printFunc)("\b\b\b\b\b\b\b\b%X", busTestData);
		*pStart++ = busTestData;
	}

	(*printFunc)("\r\nComparing data         ");
	pStart = pMemorySpace->baseAddress;
	for (i = 0; i < BUS_WIDTH; i++)
	{
		busTestData = 1 << i;
		if (*pStart != busTestData)
		{
			(*printFunc)("\r\n\tError at %X. Data: %X", pStart, *pStart);
			errorText = "Walking 1 memory test";
			result = 2;
		}
		*pStart++;
	}
	return(result);
}

short TestRAM(short mode)
{
	WORD
		space = 0,
		result = 0;

#ifdef SDBTESTS
		memorySpace[0].baseAddress = (unsigned long *)ulRamBufStart;
		memorySpace[0].endAddress = (unsigned long *)ulRamBufEnd;
#endif SDBTESTS

	while ( memorySpace[space].baseAddress != (unsigned long *)(0xffffffff) )
	{
		result = testMemorySpace( (memorySpace_t *)&memorySpace[space] );
		if (result)
			break;
		space++;
	}

	return(result);
}

⌨️ 快捷键说明

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