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

📄 template.c

📁 intel p33 driver file
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
 *** Intel Confidential
 *** Copyright (C) Intel Corporation 2003
 *** All Rights Reserved.
 *** --------------------------------------------------------------------
 ***
 *** Project Name: Flash Templates
 ***
 *** Module Name: Template
 ***
 *** File: Template.C - Common template C source file
 ***
 *** File Revision: $Revision: 2 $, $JustDate:  10/11/06 $, $Author: smangrul $
 ***
 *** Purpose:
 ***
 ***    The purpose of this file is to implement the common application
 ***    programmers interface for flash template software.  This module
 ***    implements all flash template subroutines that do not have
 ***    a device specific implementation in the device.c module for
 ***    the supported device.  Macros are used to determine if
 ***    the template.c common implementation or the device.c specific
 ***    implementation is used by the template for each subroutine.
 ***
 ***    Note that some common template functions implemented in this
 ***    module will return STATUS_UNSUPPORTED since no common
 ***    implementation is possible due to the differences between
 ***    supported devices for those functions.  The device.c module
 ***    must contain implementations for these particular functions
 ***    when the function is in fact supported for that device.
 ***
 *** $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"


#if !DEVICE_CLEAR_STATUS /* if there is no device.c implementation */
/****************************************************************************
 *
 * TMPL_ClearStatus
 *
 * Description:
 *    This procedure is called to clear the status register on the flash
 *    device.  See the flash device datasheet for specific details on
 *    this command.
 *
 * Parameters:
 *    NONE
 *
 * Returns:
 *    NONE
 *
 * Assumptions:
 *    NONE
 *
 ***************************************************************************/
void TMPL_ClearStatus ( void )
{

    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS,  TMPL_CLEAR_STATUS_REGISTER );

}
#endif /* !DEVICE_CLEAR_STATUS */


#if !DEVICE_ERASE_BLOCK /* if there is no device.c implementation */
/****************************************************************************
 *
 * TMPL_EraseBlock
 *
 * Description:
 *
 *    This procedure is called to erase a data 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_EraseBlock ( UINT16 blocknum,
                              UINT8  returnSR )
{

    TMPL_Status   stat;
    UINT32 blockadd;

    stat = TMPL_GetBlockAddress( blocknum, &blockadd );

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

    if ( returnSR )
    {
        TMPL_ClearStatus();
    }

    TMPL_WriteF(blockadd, TMPL_BLOCK_ERASE);

    TMPL_WriteF(blockadd, TMPL_CONFIRM );


    if ( !TMPL_WaitUntilReady( TMPL_ERASE_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 );

}
#endif /* !DEVICE_ERASE_BLOCK */


#if !DEVICE_GET_BLOCK_ADDRESS /* if there is no device.c implementation */
/****************************************************************************
 *
 * TMPL_GetBlockAddress
 *
 * Description:
 *
 *    This procedure is called to get the flash starting address for the
 *    specified block number.
 *
 * 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;

    stat.Result = StatUnsupported;

    return( stat );

}
#endif


#if !CLIENT_GET_FPTR /* if there is no client provided implementation */
/****************************************************************************
 *
 * TMPL_GetFptr
 *
 * Description:
 *
 *    This procedure is called to return a flash ptr given a
 *    specified device address.  This routine will likely need to be
 *    provided externally by the template client in order to properly
 *    deal with addressing details that are specific to the HW platform.
 *
 * Parameters:
 *
 *    IN      address  - the flash address
 *
 * Returns:
 *
 *    TMPL_FDATA_PTR  - address returned in ptr form
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_FDATA_PTR  TMPL_GetFptr ( UINT32 address )
{
    return( (TMPL_FDATA_PTR)address );
}
#endif /* !CLIENT_GET_FPTR */


#if !DEVICE_GET_QUERY_ADDRESS /* if there is no device.c implementation */
/****************************************************************************
 *
 * TMPL_GetQueryAddress
 *
 * Description:
 *
 *    This procedure is called to get the flash address for a given
 *    query offset.
 *
 *   Parameters:
 *
 *    IN      offset   - query offset location
 *
 *    OUT     address  - the flash address for the specified query
 *                       offset.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_GetQueryAddress ( UINT32 offset,
                                   UINT32_PTR address )
{
    TMPL_Status stat;

#if ( X_8 )
    *address = offset;
#elif ( X_16 )
    *address = offset << 1;
#elif( PX_16 || X_32 )
    *address = offset << 2;
#endif


    *address += TMPL_BASE_FLASH_ADDRESS;

    stat.Result = StatCompleted;

    return( stat );
}
#endif /* !DEVICE_GET_QUERY_ADDRESS */


#if !DEVICE_PROGRAM_FLASH /* if there is no device.c implementation */
    #if X_16
/****************************************************************************
 *
 * TMPL_ProgramFlash
 *
 * Description:
 *
 *    This procedure is called to program the flash device at the specified
 *    address with the single specified data value.  See the flash device
 *    datasheet for specific details on this command.
 *
 * Parameters:
 *
 *    IN      address  - the flash address to be programmed.
 *
 *    IN      item     - the data value to be programmed.
 *
 *    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_ProgramFlash ( UINT32 address,
                                UINT16 item,
                                UINT8  returnSR )
{

    TMPL_Status stat;

    TMPL_FDATA writedata;

    if ( address >= TMPL_TOTAL_SIZE )
    {
        stat.Result = StatBadAddress;

        return( stat );
    }

    if ( returnSR )
    {
        TMPL_ClearStatus();
    }

    writedata = (TMPL_FDATA)( item );

    if ( ( address & 0x1 ) != 0 )
    {
        address--;
#if (BIG_ENDIAN_ARCHITECTURE)
        writedata |= 0xFF00;
#else /* little endian */
        writedata = ( writedata << 8 ) | 0x00ff;
#endif
    } else
    {
#if BIG_ENDIAN_ARCHITECTURE
        writedata |= 0x00ff;
#else /* little endian */
        writedata |= 0xff00;
#endif /* BIG_ENDIAN_ARCHITECTURE */
    }

    TMPL_WriteF(address, TMPL_PROGRAM_SETUP );

    TMPL_WriteF(address, item);

    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 );
}
    #endif /* X_16 */
#endif /* !DEVICE_PROGRAM_FLASH */


#if !DEVICE_QUERY /* if there is no device.c implementation */
    #if X_16
/****************************************************************************
 *
 * TMPL_Query
 *
 * Description:
 *
 *    This procedure is called to issue the query command to
 *    the flash device.  See the flash device datasheet for specific details
 *    on this command.
 *
 * Parameters:
 *
 *    OUT      *query - pointer to query structure
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_Query ( struct TMPL_QueryData *query )
{

    TMPL_Status stat;
    UINT32 add;
    UINT32 offset;
    TMPL_FDATA item;
    UINT32 longitem;
    UINT32 i;

    TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_QUERY );

    offset = TMPL_QUERY_START_OFFSET;

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

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

        TMPL_ReadF(add, &item);

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

    /* read vendor id */
    query->VendorId = 0;
    for ( i=0; i < 2; i++ )
    {
        stat = TMPL_GetQueryAddress(offset, &add);

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

        TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
        item &= 0x00ff;
        item = item << (8*(1-i) );
#else
        item &= 0xff;
        item = item << (8*i);
#endif

        query->VendorId = (UINT16)( query->VendorId | item );
        offset++;
    }

    /* read extended table ptr */
    query->ExtTablePtr = 0;
    for ( i=0; i < 2; i++ )
    {
        stat = TMPL_GetQueryAddress(offset, &add);

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

        TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
        item &= 0x00ff;
        item = item << (8*(1-i) );
#else
        item &= 0xff;
        item = item << (8*i);
#endif

        query->ExtTablePtr = (UINT16)( query->ExtTablePtr | item );
        offset++;
    }

    /* read alternate vendor id */
    query->AltVendorId = 0;
    for ( i=0; i < 2; i++ )
    {
        stat = TMPL_GetQueryAddress(offset, &add);

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

        TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
        item &= 0x00ff;
        item = item << (8*(1-i) );
#else
        item &= 0xff;
        item = item << (8*i);
#endif
        query->AltVendorId = (UINT16)( query->AltVendorId | item );
        offset++;
    }

    /* read secondary extended table ptr */
    query->SecExtTablePtr = 0;
    for ( i=0; i < 2; i++ )
    {
        stat = TMPL_GetQueryAddress(offset, &add);

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

        TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
        item &= 0x00ff;
        item = item << (8*(1-i) );
#else
        item &= 0xff;
        item = item << (8*i);
#endif
        query->SecExtTablePtr = (UINT16)
                                ( query->SecExtTablePtr | item );
        offset++;
    }

    /* read minimum voltage */
    stat = TMPL_GetQueryAddress(offset, &add);

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

    TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
    item &= 0x00ff;
#else
    item &= 0xff;
#endif

    query->VccMin = (UINT8)item;
    offset++;

    /* read maximum voltage */
    stat = TMPL_GetQueryAddress(offset, &add);

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

    TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
    item &= 0x00ff;
#else
    item &= 0xff;
#endif

    query->VccMax = (UINT8)item;
    offset++;

    /* read supply voltage */
    stat = TMPL_GetQueryAddress(offset, &add);

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

    TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
    item &= 0x00ff;
#else
    item &= 0xff;
#endif

    query->VppMin = (UINT8)item;
    offset++;

    /* read supply max voltage */
    stat = TMPL_GetQueryAddress(offset, &add);

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

    TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
    item &= 0x00ff;
#else
    item &= 0xff;
#endif

    query->VppMax = (UINT8)item;
    offset++;

    /* read typical program timeout */
    stat = TMPL_GetQueryAddress(offset, &add);

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

    TMPL_ReadF(add, &item);

#if BIG_ENDIAN_ARCHITECTURE
    item &= 0x00ff;
#else
    item &= 0xff;
#endif

    query->TypicalProgTimeout = (UINT8)item;
    offset++;

⌨️ 快捷键说明

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