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

📄 flshnand.c

📁 cirrus的ep7312的各个测试程序
💻 C
字号:
//****************************************************************************
//
// FLSHNAND.C - Performs a non-destructive test of the on-board NAND FLASH.
//
// Copyright (c) 1999 - 2001 Cirrus Logic, Inc.
//
//****************************************************************************
#include "lib7312.h"

//****************************************************************************
//
// ucBuffer is used to save the contents of a block of the on-board NAND FLASH
// during the test.  This buffer is the maximum size of a block of NAND FLASH.
//
//****************************************************************************
unsigned char ucBuffer[528 * 32];

//****************************************************************************
//
// PrintLong prints the value of a variable on the LCD in hexadecimal.
//
//****************************************************************************
void
PrintLong(unsigned long ulValue, long lX, long lY, CPixel sColor)
{
    char cMap[17] = "0123456789ABCDEF";
    
    //
    // Print out the value the way "%04X" would in C.
    //
    LCDColorPrintChar(cMap[(ulValue & 0xF000) >> 12], lX, lY, sColor);
    LCDColorPrintChar(cMap[(ulValue & 0x0F00) >> 8], lX + 8, lY, sColor);
    LCDColorPrintChar(cMap[(ulValue & 0x00F0) >> 4], lX + 16, lY, sColor);
    LCDColorPrintChar(cMap[ulValue & 0x000F], lX + 24, lY, sColor);
}

//****************************************************************************
//
// This program performs a non-destructive memory test of the on-board NAND
// FLASH.  The memory is tested a block at a time, with the original contents
// of the block being restored after the block is tested.  This is not to be
// construed as an effective test of the NAND FLASH, but more as a means of
// showing how to read and write data to the on-board NAND FLASH.
//
//****************************************************************************
void
entry(void)
{
    unsigned long ulSize, ulPageSize, ulPagesPerBlock, ulNumBlocks;
    unsigned long ulBlock, ulPattern, ulIdx, ulLoop, ulErrors = 0, ulBadBlock;
    unsigned char ucData[2048 + 64];
    unsigned char ucPatterns[] = { 0x00, 0x55, 0xaa, 0xff };
    unsigned char cTemp;
    CPixel sWrite, sErase;

    //
    // Enable the LCD controller, clear the frame buffer, and turn on the LCD
    // panel.
    //
    LCDColorEnable();
    LCDColorCls();
    LCDColorOn();
    LCDColorContrastEnable();
    LCDColorBacklightOn();

    //
    // Set the pixel write color to white.
    //
    sWrite.r = 15;
    sWrite.g = 15;
    sWrite.b = 15;

    //
    // Set the pixel erase color to black.
    //
    sErase.r = 0;
    sErase.g = 0;
    sErase.b = 0;
    
    //
    // Get the device geometry of the on-board NAND FLASH.
    //
    NANDGetSize(&ulSize, &ulPageSize, &ulPagesPerBlock, &ulNumBlocks);

    //
    // The page size returned is just the main storage area.  We want to save
    // and restore (and therefore test) the save area as well.
    //
    ulPageSize += ulPageSize / 32;

    //
    // Display the basic progress information.
    //
    LCDColorPrintString("Block:", 100, 70, sWrite);
    LCDColorPrintString("Failures:", 100, 80, sWrite);
    LCDColorPrintString("0000", 175, 80, sWrite);

    //
    // Test each block of the on-board NAND FLASH a block at a time.
    //
    for(ulBlock = 0; ulBlock < ulNumBlocks; ulBlock++)
    {
        //
        // If we're not on the first block, erase the block 
        // number from the LCD.
        //
        if (ulBlock != 0)
           PrintLong(ulBlock - 1, 175, 70, sErase);

        //
        // Display this sector number on the LCD screen.
        //
        PrintLong(ulBlock, 175, 70, sWrite);

        //
        // Initially, this block is not bad.
        //
        ulBadBlock = 0;

        //
        // Read the contents of each page in this block.
        //
        for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
        {
            NANDReadPage((ulBlock * ulPagesPerBlock) + ulIdx, 1,
                         ucBuffer + (ulIdx * ulPageSize));
        }

        // 
        // Test this block with our four bit patterns (all zeros, all ones, and
        // the two different checkboards).
        //
        for(ulPattern = 0; ulPattern < 4; ulPattern++)
        {
            //
            // Erase this block.
            //
            NANDEraseBlock(ulBlock);

            //
            // Fill the data buffer with the current pattern.
            //
            for(ulIdx = 0; ulIdx < ulPageSize; ulIdx++)
            {
                ucData[ulIdx] = ucPatterns[ulPattern];
            }

            //
            // Write the data buffer to each page in this block.
            //
            for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
            {
                NANDWritePage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);
            }

            //
            // Read back each page of this block.
            //
            for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
            {
                //
                // Read the page.
                //
                NANDReadPage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);

                //
                // Check to see that each byte of the read back data matches
                // the pattern that we wrote.
                //
                for(ulLoop = 0; ulLoop < ulPageSize; ulLoop++)
                {
                    //
                    // Does this byte match?
                    //
                    if(ucData[ulLoop] != ucPatterns[ulPattern])
                    {
                        //
                        // One byte in this block is bad.
                        //
                        ulBadBlock = 1;
                    }
                }
            }
        }

        //
        // Erase this block.
        //
        NANDEraseBlock(ulBlock);

        //
        // Now write a different pattern in each page of the block.
        //
        for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
        {
            //
            // Create the data pattern in the buffer.
            //
            for(ulLoop = 0; ulLoop < ulPageSize; ulLoop = ulLoop + 4)
            {
                cTemp = (0x80 + ulIdx + ulLoop) & 0xff;
                ucData[ulLoop] =  cTemp;
                ucData[ulLoop + 1] =  cTemp;
                ucData[ulLoop + 2] =  cTemp;
                ucData[ulLoop + 3] =  cTemp;
            }

            //
            // Write the data pattern to this page.
            //
            NANDWritePage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);
        }

        //
        // Read back the data for verification.
        //
        for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
        {
            //
            // Read this page.
            //
            NANDReadPage((ulBlock * ulPagesPerBlock) + ulIdx, 1, ucData);

            //
            // Verify that the data matches the pattern written.
            //
            for(ulLoop = 0; ulLoop < ulPageSize; ulLoop = ulLoop + 4)
            {
                //
                // Does this byte match?
                //
                cTemp = (0x80 + ulIdx + ulLoop) & 0xff;
                if(cTemp != (ucData[ulLoop] | ucData[ulLoop + 1] |
                             ucData[ulLoop + 2] | ucData[ulLoop + 3]))
                {
                    //
                    // One byte in this block is bad.
                    //
                    ulBadBlock = 1;
                }
            }
        }

        //
        // Erase this block.
        //
        NANDEraseBlock(ulBlock);

        //
        // Restore the original contents of this block.
        //
        for(ulIdx = 0; ulIdx < ulPagesPerBlock; ulIdx++)
        {
            NANDWritePage((ulBlock * ulPagesPerBlock) + ulIdx, 1,
                          ucBuffer + (ulIdx * ulPageSize));
        }

        //
        // If we found an error in this block, the increment the count of bad
        // blocks.  And print that number to the LCD
        //
        if(ulBadBlock)
        {
            ulErrors++;
            
            //
            // Print out the number of errors.
            //
            PrintLong(ulErrors - 1, 175, 80, sErase); 
            PrintLong(ulErrors, 175, 80, sWrite);
        }
    }

    //
    // Ask the user to press a keyboard button.
    //
    LCDColorPrintString("The NAND Flash test is completed.", 40, 100, sWrite);
    LCDColorPrintString("Press one of the User keys on the", 40, 115, sWrite);
    LCDColorPrintString("keypad to exit.", 40, 125, sWrite);

    //
    // Wait until a user button is pressed.
    //
    KPGetUserButton();

    //
    // Turn off the LCD panel.
    //
    LCDColorContrastDisable();
    LCDColorBacklightOff();
    LCDColorOff();
}

⌨️ 快捷键说明

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