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

📄 device.c

📁 intel p33 driver file
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************
 *** Intel Confidential
 *** Copyright (C) Intel Corporation 2003-2005
 *** All Rights Reserved.
 *** --------------------------------------------------------------------
 ***
 *** Project Name: Flash Templates
 ***
 *** Module Name: Device
 ***
 *** File: Device.C - P33 device specific template source file
 ***
 *** File Revision: $Revision: 2 $, $JustDate:  10/11/06 $, $Author: smangrul $
 ***
 *** Purpose:
 ***
 ***    The purpose of this file is to implement the P33 device specific
 ***    functionality for the P33 template package.  This module
 ***    implements only those functions which have P33 device specific
 ***    implementations.  The remaining functions which complete
 ***    the template application programmers interface are implemented
 ***    by the template.c source module.
 ***
 *** $NoKeywords: $
 *************************************************************************/


/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS.  YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/

/* Include Files */

#include "template.h"


/****************************************************************************
 *
 * TMPL_EraseAllBlocks
 *
 * Description:
 *
 *    This procedure is called to erase all data blocks on the flash
 *    device.  See the flash device datasheet for specific details on
 *    the block erase command.
 *
 * Parameters:
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_EraseAllBlocks ( UINT8 returnSR )
{

    TMPL_Status stat;
    UINT16 block;


    for ( block=0; block < TMPL_TOTAL_NUMBLOCKS; block++ )
    {
    	stat = TMPL_UnlockBlock ( block, 1 );
		if ( stat.Result != StatCompleted )
        {
            return( stat );
        }

        stat = TMPL_EraseBlock( block, 1 );

        if ( stat.Result != StatCompleted )
        {
            return( stat );
        }

		stat = TMPL_LockBlock ( block, 1 );

        if ( stat.Result != StatCompleted )
        {
            return( stat );
        }
    }

    /* return device to read array mode */
    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}


/****************************************************************************
 *
 * TMPL_EraseSuspend
 *
 * Description:
 *
 *    This procedure is called to issue the erase suspend command to
 *    the flash device.  See the flash device datasheet for specific details
 *    on this command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    When this function is called the device is currently in the erase
 *    mode for the block identified.
 *
 ***************************************************************************/
TMPL_Status TMPL_EraseSuspend ( UINT8  returnSR )
{

    TMPL_Status stat;

    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_BLOCK_SUSPEND );

    if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
    {
        stat.Result = StatTimeout;
    } else
    {
        stat.Result = StatCompleted;
    }

    if ( returnSR )
    {
        stat.SR = TMPL_ReadStatus();
    }

    /* return device to read array mode */
    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}


#if X_16
/****************************************************************************
 *
 * TMPL_ExtendedQuery
 *
 * Description:
 *
 *    This procedure is called to retrieve the extended query
 *    data from the flash device.  See the flash device datasheet for
 *    specific details on this command.
 *
 * Parameters:
 *
 *    OUT      *extquery - pointer to extended query structure
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat
 *
 * Assumptions:
 *
 *    NONE
 ***************************************************************************/
TMPL_Status TMPL_ExtendedQuery ( struct TMPL_ExtQueryData *extquery )
{


    TMPL_Status           stat;
    struct TMPL_QueryData query;
    TMPL_FDATA            item;
    UINT32                addr;
    UINT32                longitem;
    UINT32                i;
    UINT32                offset;

    stat = TMPL_Query( &query );

    if ( stat.Result != StatCompleted )
    {
        return( stat );
    }

    offset = query.ExtTablePtr;


    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_READ_QUERY );

    /* read extended query string */
    for ( i=0; i < 3; i++ )
    {
        stat = TMPL_GetQueryAddress( offset, &addr );

        if ( stat.Result != StatCompleted )
        {
            return( stat );
        }

        TMPL_ReadF(addr, &item);

        item &= 0xff;
        extquery->ExtQueryStr[i] = (char)item;
        offset++;
    }
    extquery->ExtQueryStr[3] = '\0'; /* null terminate string */

    /* read major version number */
    stat = TMPL_GetQueryAddress( offset, &addr );

    if ( stat.Result != StatCompleted )
    {
        return( stat );
    }

    TMPL_ReadF(addr, &item);
    item &= 0xff;
    extquery->MajorVersionNum = (UINT8)item;
    offset++;

    /* read minor version number */
    stat = TMPL_GetQueryAddress( offset, &addr );

    if ( stat.Result != StatCompleted )
    {
        return( stat );
    }

    TMPL_ReadF(addr, &item);
    item &= 0xff;
    extquery->MinorVersionNum = (UINT8)item;
    offset++;

    extquery->OptionalFeature = 0;
    for ( i=0; i < 4; i++ )
    {
        stat = TMPL_GetQueryAddress( offset, &addr );

        if ( stat.Result != StatCompleted )
        {
            return( stat );
        }

        TMPL_ReadF(addr, &item);
        item &= 0xff;
        longitem = (UINT32)((UINT32)item << (8*i));
        extquery->OptionalFeature = (UINT32)( extquery->OptionalFeature | longitem );
        offset++;
    }

    /* read after suspend functions */
    stat = TMPL_GetQueryAddress( offset, &addr );

    if ( stat.Result != StatCompleted )
    {
        return( stat );
    }

    TMPL_ReadF(addr, &item);

    item &= 0xff;
    extquery->AfterSuspendFunctions = (UINT8)item;
    offset++;

    /* read vendor id */
    extquery->BlockLockStatus = 0;
    for ( i=0; i < 2; i++ )
    {
        stat = TMPL_GetQueryAddress( offset, &addr );

        if ( stat.Result != StatCompleted )
        {
            return( stat );
        }

        TMPL_ReadF(addr, &item);

        item &= 0xff;
        item = item << (8*i);
        extquery->BlockLockStatus = (UINT16)( extquery->BlockLockStatus | item );
        offset++;
    }

    /* read vcc optimum */
    stat = TMPL_GetQueryAddress( offset, &addr );

    if ( stat.Result != StatCompleted )
    {
        return( stat );
    }

    TMPL_ReadF(addr, &item);

    item &= 0xff;
    extquery->VccOptimum = (UINT8)item;
    offset++;

    /* read vpp optimum */
    stat = TMPL_GetQueryAddress( offset, &addr );

    if ( stat.Result != StatCompleted )
    {
        return( stat );
    }

    TMPL_ReadF(addr, &item);

    item &= 0xff;
    extquery->VppOptimum = (UINT8)item;
    offset++;

    stat.Result = StatCompleted;

    /* return device to read array mode */
    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

    return( stat );

}
#endif /* X_16 */



/****************************************************************************
 *
 * TMPL_GetBlockAddress
 *
 * Description:
 *
 *    This procedure is called to get the flash starting address for the
 *    specified block number in bottom boot device.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    OUT     address  - the starting flash address for the specified
 *                       block.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_GetBlockAddress ( UINT16 blocknum,
                                   UINT32 *address )
{

    TMPL_Status stat;


    if (P33_BOTTOM)
    { /* Bottom Boot Device */
        if ( (blocknum >= TMPL_BOTTOM_BLOCK_LOWER && blocknum <= TMPL_BOTTOM_BLOCK_UPPER) )
        {

            *address = TMPL_BASE_FLASH_ADDRESS + ( blocknum * TMPL_PARM_BLOCK_NUMBYTES );

            stat.Result = StatCompleted;

        }

        else if

             (  (blocknum >= 4 && blocknum <= TMPL_TOTAL_NUMBLOCKS) )
        {
        	*address = TMPL_BASE_FLASH_ADDRESS + ( (blocknum-TMPL_BOTTOM_BLOCK_UPPER) * TMPL_MAIN_BLOCK_NUMBYTES );

			stat.Result = StatCompleted;
        }

        else
        {
            stat.Result = StatBadBlock;
        }

    }

    else
    {    /* Top Boot Device */
        if (  (blocknum >= TMPL_TOP_BLOCK_LOWER && blocknum <= (TMPL_TOTAL_NUMBLOCKS-1) ) )
        {

            *address = TMPL_BASE_FLASH_ADDRESS + ( ((TMPL_TOP_BLOCK_LOWER)*TMPL_MAIN_BLOCK_NUMBYTES) + ( (blocknum-(TMPL_TOP_BLOCK_LOWER)) * TMPL_PARM_BLOCK_NUMBYTES) );


            stat.Result = StatCompleted;
        }

        else if

             ( (blocknum >= 0 && blocknum <= (TMPL_TOP_BLOCK_LOWER-1 )) )
        {
            *address = TMPL_BASE_FLASH_ADDRESS + ( blocknum * TMPL_MAIN_BLOCK_NUMBYTES );

            stat.Result = StatCompleted;
        }

        else
        {
            stat.Result = StatBadBlock;
        }

    }


    return( stat );

}



/****************************************************************************
 *
 * TMPL_LockBlock
 *
 * Description:
 *
 *    This procedure is called to lock the specified block on the flash
 *    device.  See the flash device datasheet for specific details on this
 *    command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_LockBlock ( UINT16 blocknum,
                             UINT8  returnSR )
{

    TMPL_Status stat;

    UINT32 blockaddr;

⌨️ 快捷键说明

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