📄 memtest.c
字号:
//=============================================================================//// memtest.c - Cyclone Diagnostics////=============================================================================//####COPYRIGHTBEGIN####// // ------------------------------------------- // The contents of this file are subject to the Red Hat eCos Public License // Version 1.1 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.redhat.com/ // // Software distributed under the License is distributed on an "AS IS" // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the // License for the specific language governing rights and limitations under // the License. // // The Original Code is eCos - Embedded Configurable Operating System, // released September 30, 1998. // // The Initial Developer of the Original Code is Red Hat. // Portions created by Red Hat are // Copyright (C) 2001 Red Hat, Inc. // All Rights Reserved. // ------------------------------------------- // //####COPYRIGHTEND####//=============================================================================//#####DESCRIPTIONBEGIN####//// Author(s): Scott Coulter, Jeff Frazier, Eric Breeden// Contributors:// Date: 2001-01-25// Purpose: // Description: ////####DESCRIPTIONEND####////===========================================================================*//************************************************************************** Memtest.c - this file performs an address/address bar memory test.** Modification History* --------------------* 01sep00 ejb Ported to StrongARM2* 18dec00 snc* 02feb01 jwf for snc*/#include "7_segment_displays.h"#if 0extern void store_double (unsigned long, unsigned long, unsigned long);extern void read_double (unsigned long, unsigned long Data[]);extern int quadtest(long startaddr);#endifextern void hex32out (unsigned int num);extern int printf(char*,...);extern load_runtime_reg();extern store_runtime_reg();/* 02/02/01 jwf */#ifndef TRUE#define TRUE 1#endif#ifndef FALSE#define FALSE 0#endif#define FAILED 1#define PASSED 0/* Do walking one's test */static intonesTest( long testAddr /* address to test */ ){ long testData = 1; /* Current pattern being used */ long dataRead; int fail = 0; /* Test hasn't failed yet */ int loopCount = 0; /* To keep track of when to print CR */ printf("\n"); while(testData && !fail) { /* Loop until bit shifted out */ *((long *) testAddr) = testData; /* Write test data */ *((long *) (testAddr + 4)) = 0xFFFFFFFF; /* Drive d0-d31 hi */ dataRead = *((long *) testAddr); /* Read back data */ hex32out(dataRead); if (!(++loopCount % 8) && (loopCount != 32)) printf("\n"); else printf(" "); if (dataRead != testData) /* Verify data */ return FAILED; /* Signal failure */ else testData <<= 1; /* Shift data over one bit */ } return PASSED;}#if 0/*************************************************************************** onesTest - perform a 64 bit walking one's test on a specified address*** RETURNS: PASSED if the test passes or FAILED otherwise**/static int onesTest(long testAddr){ /* need to be arrays of sequential words in order to be able to test a 64bit wide memory bus */ unsigned long testData[2]; /* Current pattern being used */ unsigned long dataRead[2]; /* Data read back from memory */ int bitsTested = 0; /* To keep track of when to print CR and when to switch words */ printf("\n"); /* test variable initialization */ testData[0] = 0x00000001; /* lower 32 bit word */ testData[1] = 0x00000000; /* upper 32 bit word */ bitsTested = 0; /* Loop until all 64 data bits are tested */ while (bitsTested < 64) { /* perform a double word write to cause a 64bit memory access */ store_double (testAddr, testData[0], testData[1]); /* drive 64 bit data bus high and flush bus unit */ store_double (testAddr + 8, 0xffffffff, 0xffffffff); /* perform a double word read to cause a 64bit memory access */ read_double (testAddr, dataRead); hex32out((long)dataRead[1]); /* print out MS word */ hex32out((long)dataRead[0]); /* print out LS word */ if (!(++bitsTested % 4) && (bitsTested != 64)) printf("\n"); else printf(" "); /* verify the data */ if ((dataRead[0] != testData[0]) || (dataRead[1] != testData[1])) return (FAILED); /* Signal failure */ else { if (bitsTested < 32) /* data bits 0 - 31 */ { testData[0] <<= 1; /* shift data through LS word */ } else if (bitsTested == 32) /* start testing MS word */ { testData[0] = 0x00000000; /* clear LS word */ testData[1] = 0x00000001; /* shift into MS word */ } else /* data bits 32 - 63 */ { testData[1] <<= 1; /* shift data through MS word */ } } } return (PASSED);}#endif/* Do long word address test */static int LWAddr ( long start, /* Starting address of test */ long end, /* Ending address */ long *badAddr /* Failure address */ ){ register long currentAddr; /* Current address being tested */ register long data; char fail = 0; /* Test hasn't failed yet */ for(currentAddr = start; currentAddr < end; currentAddr += 4) *((long *) currentAddr) = currentAddr; for (currentAddr = start; (currentAddr < end); currentAddr += 4) { data = *(long *) currentAddr; if (data != currentAddr) { fail = 1; printf ("\n\nLWAddr Bad Read, Address = 0x%08x, Data Read = 0x%08x\n\n", currentAddr, data); break; } } if (fail) { *badAddr = currentAddr; return FAILED; } else return PASSED;}/* Do inverse long word address test */static int LWBar (long start, /* Starting address of test */ long end, /* Ending address */ long *badAddr /* Failure address */ ){ register long currentAddr; /* Current address being tested */ register long data; int fail = 0; /* Test hasn't failed yet */ for(currentAddr = start; currentAddr < end; currentAddr += 4) *((long *) currentAddr) = ~currentAddr; for (currentAddr = start; (currentAddr < end); currentAddr += 4) { data = *(long *) currentAddr; if (data != ~currentAddr) { fail = 1; printf ("\n\nLWBar Bad Read, Address = 0x%08x, Data Read = 0x%08x\n\n", currentAddr, data); break; } } if (fail) { *badAddr = currentAddr; return FAILED; } else return PASSED;}/* Do byte address test */static intByteAddr ( long start, /* Starting address of test */ long end, /* Ending address */ long *badAddr /* Failure address */ ){ long currentAddr; /* Current address being tested */ int fail = 0; /* Test hasn't failed yet */ for(currentAddr = start; currentAddr < end; currentAddr++) *((char *) currentAddr) = (char) currentAddr; for(currentAddr = start; (currentAddr < end) && (!fail); currentAddr++) if (*((char *) currentAddr) != (char) currentAddr) fail = 1; if (fail) { *badAddr = currentAddr - 1; return FAILED; } else return PASSED;}/* Do inverse byte address test */static int ByteBar ( long start, /* Starting address of test */ long end, /* Ending address */ long *badAddr /* Failure address */ ){ long currentAddr; /* Current address being tested */ int fail = 0; /* Test hasn't failed yet */ for(currentAddr = start; currentAddr < end; currentAddr++) *((char *) currentAddr) = (char) ~currentAddr; for(currentAddr = start; (currentAddr < end) && (!fail); currentAddr++) if (*((char *) currentAddr) != (char) ~currentAddr) fail = 1; if (fail) { *badAddr = currentAddr - 1; return FAILED; } else return PASSED;}/* * This routine is called if one of the memory tests fails. It dumps * the 8 32-bit words before and the 8 after the failure address */void dumpMem ( long badAddr /* Failure address */ ){ unsigned long *addr; unsigned short *saddr; printf("\n"); /* Print out first line of mem dump */ hex32out(badAddr - 32); /* Starting address */ printf(": "); hex32out(*((long *) (badAddr - 32))); /* First longword */ printf(" "); hex32out(*((long *) (badAddr - 28))); printf(" "); hex32out(*((long *) (badAddr - 24))); printf(" "); hex32out(*((long *) (badAddr - 20))); printf("\n"); hex32out(badAddr - 16); printf(": "); hex32out(*((long *) (badAddr - 16))); printf(" "); hex32out(*((long *) (badAddr - 12))); printf(" "); hex32out(*((long *) (badAddr - 8))); printf(" "); hex32out(*((long *) (badAddr - 4))); printf("\n"); /* Print out contents of fault addr */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -