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

📄 sdram_test.c

📁 COLDFIRE 5282SC的文件
💻 C
字号:
/*
 * File:		sdram_test.c
 * Purpose:		Test the SDRAM on the M5282EVB
 *
 * Notes:		The Ethernet test requires SDRAM for the buffers and
 *				buffer descriptors.  Therefore, sdram_test() must be
 *				called before ethernet_test().  If sdram_test() fails,
 *				the processor must be halted.  
 */
 
#include "src/init/m5282evb.h"
#include "src/fat/fat.h"
 
/********************************************************************/
void
sdram_test(void)
{
	static uint32 addr,testbit;
	static unsigned long addressmask = 0x1000000;
    static unsigned long offset;
    static unsigned long testoffset;
    static uint32 pattern = 0xAAAAAAAA;
    static uint32 antipattern = 0x55555555;

	RESULTS |= SDRAM_TEST;

	/* Verify DQM signals */
	{
		*((uint32 *)(0x00001200)) = 0x12345678;
		
		if (*((uint32 *)(0x00001200)) != 0x12345678)
		{	
			RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
		}
		if (*((uint8 *)(0x00001200)) != 0x12)
		{	
			RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
		}
		if (*((uint16 *)(0x00001201)) != 0x3456)
		{	
			RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
		}
	}
	/*****************************************/
	/* Perform a walking 1s test on data bus */
	/*****************************************/
	
	for (testbit = 1; testbit != 0; testbit <<= 1)
    {
        /*
         * Write the test pattern.
         */
        *((uint32 *)(0x00002000)) = testbit;

        /*
         * Read it back (immediately is okay for this test).
         */
        if (*((uint32 *)(0x00002000)) != testbit) 
        {
            RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
        }
    }

	/*********************************************/
	/* Test integrity of address signals         */
	/*********************************************/
	
	/*
     * Write the default pattern at each of the power-of-two offsets.
     */
     
    for (offset = 1; !(offset & addressmask); offset <<= 1)
    {
       *((uint32 *)(SDRAM_ADDRESS + offset)) = pattern;
    }

    /* 
     * Check for address bits stuck high.
     */
    testoffset = 0;
    *((uint16 *)(SDRAM_ADDRESS + testoffset)) = antipattern;

    for (offset = 1; (offset & addressmask) != 0; offset <<= 1)
    {
        if ((*(uint32 *)(SDRAM_ADDRESS + offset))  != pattern)
        {
            RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
        }
    }

	(*(uint32 *)(SDRAM_ADDRESS + testoffset)) = pattern;
    

    /*
     * Check for address bits stuck low or shorted.
     */
    for (testoffset = 1; (testoffset & addressmask) != 0; testoffset <<= 1)
    {
        (*(uint32 *)(SDRAM_ADDRESS + testoffset)) = antipattern;

		if (*(uint32 *)(SDRAM_ADDRESS) != pattern)
		{
			RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
		}

        for (offset = 1; (offset & addressmask) != 0; offset <<= 1)
        {
            if ((*(uint32 *)(SDRAM_ADDRESS + offset)) && (offset != testoffset))
            {
            RESULTS |= SDRAM_FAIL;
			#ifndef __MWERKS__
				asm(" halt");
			#else
				asm( halt);
			#endif
            }
        }

        (*(uint32 *)(SDRAM_ADDRESS + testoffset)) = pattern;
        
    }

	/*********************************************/
	/*        Test Memory                        */
	/*********************************************/
	
	/*
     * Fill memory with a known pattern.
     * nWords = nBytes/(datum); nBytes = size of SDRAM */
     
     for (offset = 0; offset < 0xFFFFFF; offset+=4)
    {
        (*(uint32 *)(SDRAM_ADDRESS + offset)) = 0x00000000;
    }
     
    for (pattern = 1, offset = 0; offset < 0xFFFFFF; pattern++, offset+=4)
    {
        (*(uint32 *)(SDRAM_ADDRESS + offset)) = pattern;

    }

    /*
     * Check each location and invert it for the second pass.
     */
    for (pattern = 1, offset = 0; offset < 0xFFFFFF; pattern++, offset+=4)
    {
        if (!((*(uint32 *)(SDRAM_ADDRESS + offset)) == pattern))
        {
            
            RESULTS |= SDRAM_FAIL;
			//#ifndef __MWERKS__
				//asm(" halt");
			//#else
				//asm( halt);
			//#endif
        }

        antipattern = ~pattern;
       (*(uint32 *)(SDRAM_ADDRESS + offset)) = antipattern;
    }

    /*
     * Check each location for the inverted pattern and zero it.
     */
    for (pattern = 1, offset = 0; offset < 0xFFFFFF; pattern++, offset+=4)
    {
        antipattern = ~pattern;
        if (!((*(uint32 *)(SDRAM_ADDRESS + offset)) == antipattern))
        {
            RESULTS |= SDRAM_FAIL;
			//#ifndef __MWERKS__
				//asm(" halt");
			//#else
				//asm( halt);
			//#endif
        }
    }

	
}
/********************************************************************/







⌨️ 快捷键说明

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