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

📄 flash.c

📁 优龙YLP270的NORFLASH裸机测试程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:       Flash.c
**
**  PURPOSE:        This module contains the platform independent test code
**                  for all Flash devices.
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include "systypes.h"
#include "dm_errors.h"
#include "stdinout.h"
#include "platform.h"
#include "XsOst.h"
#include "boardControl.h"
#include "intelFlashAPI.h"
#include "intelFlash.h"
#include "DM_Debug.h"
#include "mallocx.h"
#include "timedelays.h"
#include "stubs.h"
/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/
// We have two 16 bit devices accessed in parallel. Use a macro to replicate
// the expected result into both halfwords.
#define DoubleHalf(a) (((unsigned)(a) << 16) | (a))
#define min(a,b) ((a) < (b) ? (a) : (b))

#define LOGICAL_TEST_BLOCK 256//8192	//hzh

static Intel_Flash_ContextT * flashCtxP = NULL;
static OSTContextT *ostCtxP = &Ost;
static CHAR buf[1024];
static CHAR rbuf[1024];
static INT testFailed = 0;

/*
*******************************************************************************
*   EXTERNAL DEFINITIONS
*******************************************************************************
*/
extern int atoi(const char * /*nptr*/);
extern BOOL RunOnce;

/*
*******************************************************************************
*
* FUNCTION:
*    GetFlashParameters
*
* DESCRIPTION:
*    This routine parses the input string to determine the Flash test
*    configuration.
*
* INPUT PARAMETERS:
*    PCHAR arg - Pointer to the input string.
*    UINT test - Test type.
*
* RETURNS:
*    PVOID - Pointer to the Flash DCS.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    sscanf, printf, LOGERROR, DM_DbgPrintf
*
* CALLED BY:
*    Memory test routines.
*
* PROTOTYPE:
*    PVOID GetFlashParameters(PCHAR arg);
*
*******************************************************************************
*/
PVOID GetFlashParameters(PCHAR arg, UINT test)
{
    UINT loggedError = 0;
    CHAR type[80];
    Intel_Flash_ContextT *ctxP;

    PostDisplayProgress(ERR_L_FLASH, ERR_TS_GETPARAM, 1);

    // Check for parameters
    if (sscanf(arg, "%s", &type) != 1)
    {
        // Invalid parameter
        LOGERROR(loggedError, ERR_L_FLASH, ERR_TS_GETPARAM, ERR_T_ILLPARAM,
                 0, 0, 0);
        XllpUtilityOutputError(loggedError);
        testFailed = TRUE;
        return(NULL);
    }

    // Now check for the DEFAULT FLASH parameter.
    if (!strcmp("DEFAULT", type))
    {
        PostDisplayProgress(ERR_L_FLASH, ERR_TS_GETPARAM, 2);
        ctxP = &contexts[Flash_Default_Index];

        switch (test)
        {
            case ERR_TS_READ:
                printf(" Testing DEFAULT Flash Read\r\n");
                break;

            case ERR_TS_WRITE:
                printf(" Testing DEFAULT Flash Write\r\n");
                break;

            case ERR_TS_LOCK:
                printf(" Testing DEFAULT Flash Lock\r\n");
                break;
        }
    }
    
    // Now check for the ALTERNATE FLASH parameter.
    else if (!strcmp("ALTERNATE", type))
    {
        PostDisplayProgress(ERR_L_FLASH, ERR_TS_GETPARAM, 3);
        ctxP = &contexts[Flash_Alternate_Index];

        switch (test)
        {
            case ERR_TS_READ:
                printf(" Testing ALTERNATE Flash Read\r\n");
                break;

            case ERR_TS_WRITE:
                printf(" Testing ALTERNATE Flash Write\r\n");
                break;

            case ERR_TS_LOCK:
                printf(" Testing ALTERNATE Flash Lock\r\n");
                break;
        }
    }
    else
    {
        // Invalid parameter
        LOGERROR(loggedError, ERR_L_FLASH, ERR_TS_GETPARAM, ERR_T_ILLPARAM, 
                    0, 0, 0);
        XllpUtilityOutputError(loggedError);
        testFailed = TRUE;
        return(NULL);
    }

    return(ctxP);
}

/*
*******************************************************************************
*
* FUNCTION:
*    Flash_Trace
*
* DESCRIPTION:
*    Enable/Disable the flash debug messages
*
* INPUT PARAMETERS:
*    PVOID param - Pointer the parameter (not used).
*    PCHAR flag - 1 - enable, 0 - disable
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    Debug messages are enabled/disabled for flash devices.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY:
*    User.
*
* PROTOTYPE:
*    VOID Flash_Trace(PVOID ctxP, PCHAR flag);
*
*******************************************************************************
*/
VOID Flash_Trace(PVOID param, PCHAR flag)
{
    DM_ControlWordsDebugPrintPutBit(DM_CW_FLASH_0, atoi(flag));
}

/*
*******************************************************************************
*
* FUNCTION:
*    Flash_ShowStatus
*
* DESCRIPTION:
*    Display the flash device characteristics.
*
* INPUT PARAMETERS:
*    PVOID param - Pointer the parameter (not used).
*    PVOID arg - Extra parameter (not used).
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    Restarts the Flash device and shuts it down on exit.
*
* ASSUMPTIONS:
*    The Flash driver's software initialized routine has been called
*    by the platform initialization code.
*
* CALLS:
*    DM framework services.
*    Flash driver.
*
* CALLED BY:
*    Menu system.
*
* PROTOTYPE:
*    VOID Flash_ShowStatus(PVOID param, PVOID arg);
*
*******************************************************************************
*/
VOID Flash_ShowStatus(PVOID param, PVOID arg)
{
    UINT status;

    PostDisplayProgress(ERR_L_FLASH, ERR_TS_STATUS, 1);

    // Get pointer to the Flash drivers DCS.
    if (NULL == (flashCtxP = GetFlashParameters(arg, ERR_TS_STATUS)))
    {
        // Invalid parameter
        LOGERROR(status, ERR_L_FLASH, 0, ERR_T_ILLPARAM,
                 0, 0, 0);
        XllpUtilityOutputError(status);
        testFailed = TRUE;
        return;
    }

    // Call Flash hardware setup to initializae the device.
    status = flashCtxP->FlashHWSetupFnP(flashCtxP);
    if (status)
    {
        XllpUtilityOutputError(status);
        testFailed = TRUE;
        return;
    }

    // Enable the debug output below.
    DM_ControlWordsDebugPrintPutBit(DM_CW_FLASH_0, 1);

    // Display the flash device type.
    switch(flashCtxP->flashType)
    {
        case Intel_28F128J3A:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F128J3A");
            break;
        case Intel_28F128K18:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F128K18");
            break;
        case Intel_28F128K3:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F128K3");
            break;
        case Intel_28F160S3:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F160S3");
            break;
		case Intel_28F640L18T:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F640L18T");
            break;
		case Intel_28F128L18T:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F128L18T");
            break;
		case Intel_28F256L18T:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F256L18T");
            break;
		case Intel_28F640L18B:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F640L18B");
            break;
		case Intel_28F128L18B:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F128L18B");
            break;
		case Intel_28F256L18B:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Found 28F256L18B");
            break;
        default:
            DM_CwDbgPrintf(DM_CW_FLASH_0, " Unknown flash type");
            break;
    }

    // Display the flash characteristics.
    DM_CwDbgPrintf(DM_CW_FLASH_0, " MaxWriteTime: %d us", flashCtxP->writeTime);
    DM_CwDbgPrintf(DM_CW_FLASH_0, " MaxEraseTime: %d ms", flashCtxP->eraseTime);
    DM_CwDbgPrintf(DM_CW_FLASH_0, " MaxLockTime: %d us", flashCtxP->lockTime);
    DM_CwDbgPrintf(DM_CW_FLASH_0, " MaxUnlockTime: %d us", flashCtxP->unlockTime);
    DM_CwDbgPrintf(DM_CW_FLASH_0, " DeviceSize: %d bytes", (flashCtxP->maxBlock / 2) * 512);
    DM_CwDbgPrintf(DM_CW_FLASH_0, " WriteSize: %d byte internal buffer", flashCtxP->writeSize);
    DM_CwDbgPrintf(DM_CW_FLASH_0, " MaxBuffers: %d (512 byte) buffers to fill flash memory", flashCtxP->maxBlock);

    if((flashCtxP->flashType == Intel_28F128K18) || (flashCtxP->flashType == Intel_28F128K3) ||
       (flashCtxP->flashType == Intel_28F128J3A))
	{
        DM_CwDbgPrintf(DM_CW_FLASH_0, " EraseSize: %d total bytes per block", flashCtxP->eraseSize);
        DM_CwDbgPrintf(DM_CW_FLASH_0, " Buffers/Block: %d (512 byte) buffers per block", flashCtxP->blocksPerSector);
	}

    if((flashCtxP->flashType == Intel_28F640L18T) || (flashCtxP->flashType == Intel_28F128L18T) ||
       (flashCtxP->flashType == Intel_28F256L18T))
	{
        DM_CwDbgPrintf(DM_CW_FLASH_0, "             TOP PARAMETER MEMORY MAP");
        DM_CwDbgPrintf(DM_CW_FLASH_0, "                REGION_1  REGION_2");
        DM_CwDbgPrintf(DM_CW_FLASH_0, " No. of Blocks: %8d  %8d", flashCtxP->blocksRegion1, flashCtxP->blocksRegion2);
        DM_CwDbgPrintf(DM_CW_FLASH_0, "     EraseSize: %8d  %8d total bytes per block", flashCtxP->eraseSize,
                       flashCtxP->eraseSize2);
        DM_CwDbgPrintf(DM_CW_FLASH_0, " Buffers/Block: %8d  %8d (512 byte) buffers per block", flashCtxP->blocksPerSector,
                       flashCtxP->blocksPerSector2);
	}

    if((flashCtxP->flashType == Intel_28F640L18B) || (flashCtxP->flashType == Intel_28F128L18B) ||
       (flashCtxP->flashType == Intel_28F256L18B))
	{
        DM_CwDbgPrintf(DM_CW_FLASH_0, "            BOTTOM PARAMETER MEMORY MAP");
        DM_CwDbgPrintf(DM_CW_FLASH_0, "                REGION_1  REGION_2");
        DM_CwDbgPrintf(DM_CW_FLASH_0, " No. of Blocks: %8d  %8d", flashCtxP->blocksRegion1, flashCtxP->blocksRegion2);
        DM_CwDbgPrintf(DM_CW_FLASH_0, "     EraseSize: %8d  %8d total bytes per block", flashCtxP->eraseSize,
                       flashCtxP->eraseSize2);
        DM_CwDbgPrintf(DM_CW_FLASH_0, " Buffers/Block: %8d  %8d (512 byte) buffers per block", flashCtxP->blocksPerSector,
                       flashCtxP->blocksPerSector2);
	}

    // Disable the debug output below.
    DM_ControlWordsDebugPrintPutBit(DM_CW_FLASH_0, 0);
}

/*
*******************************************************************************
*
* FUNCTION:
*    Flash_ReadTest
*
* DESCRIPTION:
*    Read 2 blocks from flash memory 100 times.
*
* INPUT PARAMETERS:
*    PVOID param - Pointer the parameter (not used).
*    PVOID arg - Extra parameter (not used).
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    Restarts the Flash device and shuts it down on exit.
*
* ASSUMPTIONS:
*    The Flash driver's software initialized routine has been called
*    by the platform initialization code.
*
* CALLS:
*    DM framework services.
*    Flash driver.
*
* CALLED BY:
*    Menu system.
*
* PROTOTYPE:
*    VOID Flash_ReadTest(PVOID param, PVOID arg)
*
*******************************************************************************
*/
VOID Flash_ReadTest(PVOID param, PVOID arg)
{
    UINT status;
    UINT start, ticks;
    INT i;
    UINT loggedError = 0;

    PostDisplayProgress(ERR_L_FLASH, ERR_TS_READ, 1);

    // Get pointer to the Flash drivers DCS.
    if (NULL == (flashCtxP = GetFlashParameters(arg, ERR_TS_READ)))
    {
        // Invalid parameter
        LOGERROR(status, ERR_L_FLASH, ERR_TS_READ, ERR_T_ILLPARAM,
                 0, 0, 0);
        XllpUtilityOutputError(status);
        testFailed = TRUE;
        return;
    }


    PostDisplayProgress(ERR_L_FLASH, ERR_TS_READ, 2);

    // Call Flash hardware setup to initializae the device.
    status = flashCtxP->FlashHWSetupFnP(flashCtxP);
    if (status)
    {
        // Flash Setup failed
        loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_READ, ERR_FLASH_INVALID_DEV);
        XllpUtilityOutputError(loggedError);
        testFailed = TRUE;
        return;
    }

    PostDisplayProgress(ERR_L_FLASH, ERR_TS_READ, 3);

    do
    {
        // Start the timer.
        start = ostCtxP->getTimer_fnp(ostCtxP);

        DM_CwDbgPrintf(DM_CW_FLASH_0, " Reading %d bytes from flash 100 times", sizeof(buf));

        // Read 2 blocks from the flash 100 times.
        for (i=0; i < 100; i++)
        {
            status = flashCtxP->FlashReadFnP(flashCtxP, 0, buf, sizeof(buf)/512);
            if (status != sizeof(buf))
            {
                // Flash Read failed
                loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_READ, ERR_T_WRONG_VALUE);
                XllpUtilityOutputError(status);
                testFailed = TRUE;
                return;
            }
        }

        // Take the timestamp.
        ticks = ostCtxP->getDelta_fnp(ostCtxP, start);

        if (RunOnce)
        {
            // Run only a single pass.
            break;
        }
    }
    while (! DM_StopTest (NULL));

    PostDisplayProgress(ERR_L_FLASH, ERR_TS_READ, 4);

    // Call Flash hardware to initializae the device.
    flashCtxP->FlashHWShutdownFnP(flashCtxP);

    PostDisplayProgress(ERR_L_FLASH, ERR_TS_READ, 5);

    printf (" Success!\r\n");
}

/*
*******************************************************************************
*
* FUNCTION:
*    Flash_WriteTest
*
* DESCRIPTION:
*    Write/Read a rotating bit pattern to 2 blocks 10 times
*

⌨️ 快捷键说明

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