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

📄 device.c

📁 intel p33 driver file
💻 C
📖 第 1 页 / 共 3 页
字号:
    }


    address =  TMPL_OTP_BASE + TMPL_OTP_BLOCK_OFFSET;

    address += ( location * sizeof(TMPL_FDATA) );

    if ( returnSR )
    {
        TMPL_ClearStatus();
    }


	TMPL_WriteF( address, TMPL_OTP_PROGRAM );

    TMPL_WriteF( address, value );



    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 );

}
/****************************************************************************
 *
 * TMPL_ProgramSuspend
 *
 * Description:
 *
 *    This procedure is called to issue the program suspend command to
 *    the flash device.  See the flash device datasheet for specific details
 *    on this 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:
 *
 *    When this function is called the device is currently in the program
 *    mode for the block identified.
 *
 ***************************************************************************/
TMPL_Status TMPL_ProgramSuspend ( 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 );

}


/****************************************************************************
 *
 * TMPL_ReadBlockStatus
 *
 * Description:
 *
 *    This procedure is called to read the status for the specified block
 *    from the flash device.  See the flash device datasheet for specific
 *    details on this command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    OUT     blockstat- the status of the block as: unlocked, locked,
 *                       or locked down.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_ReadBlockStatus ( UINT16         blocknum,
                                   TMPL_FDATA     *blockstat )
{

    UINT32      stataddress;
    TMPL_Status stat;
    UINT32      blockaddr;

    stat = TMPL_GetBlockAddress( blocknum, &blockaddr );

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


#if PX_16
    stataddress = ( blockaddr + ( 2 * sizeof( TMPL_FDATA ) ) );
#endif

#if X_16
    stataddress = ( blockaddr + ( 2 * sizeof( TMPL_FDATA ) ) );
#endif

#if X_32
    stataddress = ( blockaddr + ( 2 * sizeof( TMPL_FDATA ) ) );
#endif

#if ILX_32
    stataddress = ( blockaddr + ( 4 * sizeof( TMPL_FDATA ) ) );
#endif


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



    TMPL_WriteF( stataddress, TMPL_READ_ID_CODES );

    TMPL_ReadF( stataddress, blockstat );

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

    stat.Result = StatCompleted;
	stat.SR = TMPL_ReadStatus();

    return( stat );

}



#if X_16
/****************************************************************************
 *
 * TMPL_ReadProtection
 *
 * Description:
 *
 *    This procedure is called to read the protection register value on
 *    the flash device from the specified location.  See the flash device
 *    datasheet for specific details on this command.
 *
 * Parameters:
 *
 *    IN      location - the protection register location on the flash
 *                       device to be read from.
 *
 *    OUT     value    - the data item read from the register.
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_ReadProtection ( UINT32         location,
                                  UINT16_PTR     value )
{
    UINT32      address;
    TMPL_Status stat;

    if ( location > TMPL_OTP_NUMWORDS )
    {
        stat.Result = StatBadOtp;
        return( stat );
    }


	address = TMPL_OTP_BASE + TMPL_OTP_BLOCK_OFFSET;


    address += ( location * sizeof(TMPL_FDATA) );

    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_OTP_READ );

    TMPL_ReadF( address, value);


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

    stat.Result = StatCompleted;

    return( stat );

}
#endif /* X_16 */


/****************************************************************************
 *
 * TMPL_Resume
 *
 * Description:
 *
 *    This procedure is called to issue the resume command to the flash
 *    device for the specified block. See the flash device datasheet for
 *    specific details on this command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number to resume.
 *
 *    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:
 *
 *    The block indicated was previously program suspended or erase
 *    suspended.
 *
 ***************************************************************************/
TMPL_Status TMPL_Resume ( UINT8  returnSR )
{

    TMPL_Status stat;

    TMPL_WriteF( TMPL_BASE_FLASH_ADDRESS, TMPL_BLOCK_RESUME );

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

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

    return( stat );

}

/****************************************************************************
 *
 * TMPL_SetConfiguration
 *
 * Description:
 *
 *    This function is used to write data to the Read Configuration
 *    Register (RCR) on the device.  Use this function to set RCR
 *    values such as read mode, latency count, wait polarity, data hold,
 *    burst sequence, clock edge, and burst length.  See datasheet for
 *    more details of the RCR.
 *
 * Parameters:
 *
 *    IN            - address of configuration data to be read in
 *
 * Returns:
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    A valid configuration setting
 *
 ***************************************************************************/
TMPL_Status TMPL_SetConfiguration ( UINT16 data )
{

    TMPL_Status stat;
	UINT32      address; /* contains the address to load the
                                    Read Configuration Register with */


    /********************************************************/
    /* Convert the RCR into valid address then write it     */
    /********************************************************/
    address = (UINT32) data;
    address = address << (sizeof(UINT16)-1);

	/* write Read Configuration command */

    TMPL_WriteF(address,TMPL_CONFIG_SETUP);
    TMPL_WriteF(address,TMPL_SET_READ_CONFIG);


    stat.Result = StatCompleted;
	stat.SR = TMPL_ReadStatus();


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

    return( stat );

}


/****************************************************************************
 *
 * TMPL_UnlockAllBlocks
 *
 * Description:
 *
 *    This procedure is called to unlock all blocks on the flash device.
 *    See the flash device datasheet for specific details on this 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:
 *
 *    The blocks were previously locked.
 *
 ***************************************************************************/
TMPL_Status TMPL_UnlockAllBlocks ( UINT8  returnSR )
{

    TMPL_Status stat;
    UINT16 block;

    for ( block=0; block < TMPL_TOTAL_NUMBLOCKS; block++ )
    {
        stat = TMPL_UnlockBlock( block, returnSR );

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

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

    stat.Result = StatCompleted;

    return( stat );

}


#if !DEVICE_UNLOCK_BLOCK /* if there is no device.c implementation */
/****************************************************************************
 *
 * TMPL_UnlockBlock
 *
 * Description:
 *
 *    This procedure is called to unlock the specified block on the flash
 *    device.  See the flash device datasheet for specific details on this
 *    command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number to unlock.
 *
 *    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:
 *
 *    The block indicated was previously locked.
 *
 ***************************************************************************/
TMPL_Status TMPL_UnlockBlock ( UINT16 blocknum,
                               UINT8  returnSR )
{
    TMPL_Status stat;
    UINT32 address;


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


    TMPL_GetBlockAddress ( blocknum,  &address );

    TMPL_WriteF(address,TMPL_CONFIG_SETUP );

    TMPL_WriteF(address,TMPL_LOCK_BIT_CLEAR);



    if (!TMPL_WaitUntilReady(TMPL_ERASE_TIMEOUT))
    {
        stat.Result = StatTimeout;
        return(stat);
    }


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


    stat.Result = StatCompleted;

    return(stat);

}
#endif /* !DEVICE_UNLOCK_BLOCK */



⌨️ 快捷键说明

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