📄 device.c
字号:
TMPL_FDATA value,
UINT8 returnSR )
{
UINT32 baseadd;
UINT32 address;
TMPL_Status stat;
if ( location > TMPL_OTP_NUMWORDS )
{
stat.Result = StatBadOtp;
return( stat );
}
baseadd = TMPL_BASE_FLASH_ADDRESS;
address = TMPL_OTP_BASE + TMPL_BASE_FLASH_ADDRESS;
address += ( location * sizeof(TMPL_FDATA) );
if ( returnSR )
{
TMPL_ClearStatus();
}
TMPL_WriteF(baseadd, 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 );
}
#endif /* X_16 */
/****************************************************************************
*
* 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 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 program
* mode for the block identified.
*
***************************************************************************/
TMPL_Status TMPL_ProgramSuspend ( UINT16 blocknum,
UINT8 returnSR )
{
TMPL_Status stat;
UINT32 blockadd;
stat = TMPL_GetBlockAddress( blocknum, &blockadd );
if ( stat.Result != StatCompleted )
{
return( stat );
}
TMPL_WriteF(blockadd, 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_PTR blockstat )
{
UINT32 stataddress;
TMPL_Status stat;
UINT32 blockadd;
stat = TMPL_GetBlockAddress( blocknum, &blockadd );
if ( stat.Result != StatCompleted )
{
return( stat );
}
#if X_8
stataddress = ( blockadd + 4 );
#endif
#if PX_16
stataddress = ( blockadd + ( 2 * sizeof( TMPL_FDATA ) ) );
#endif
#if X_16
stataddress = ( blockadd + ( 2 * sizeof( TMPL_FDATA ) ) );
#endif
#if X_32
stataddress = ( blockadd + ( 2 * sizeof( TMPL_FDATA ) ) );
#endif
#if ILX_32
stataddress = ( blockadd + ( 4 * sizeof( TMPL_FDATA ) ) );
#endif
TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, 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;
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, TMPL_FDATA_PTR value )
{
UINT32 baseadd;
UINT32 address;
TMPL_Status stat;
if ( location > TMPL_OTP_NUMWORDS )
{
stat.Result = StatBadOtp;
return( stat );
}
baseadd = TMPL_BASE_FLASH_ADDRESS;
address = TMPL_OTP_BASE + TMPL_BASE_FLASH_ADDRESS;
address += ( location * sizeof(TMPL_FDATA) );
TMPL_WriteF(baseadd, 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 ( UINT16 blocknum, UINT8 returnSR )
{
TMPL_Status stat;
UINT32 blockadd;
TMPL_FDATA status;
stat = TMPL_GetBlockAddress( blocknum, &blockadd );
if ( stat.Result != StatCompleted )
{
return( stat );
}
if ( returnSR )
{
TMPL_ClearStatus();
}
TMPL_WriteF(blockadd, 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_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 )
{
UINT32 blockadd;
TMPL_Status stat;
stat = TMPL_GetBlockAddress( blocknum, &blockadd );
if ( stat.Result != StatCompleted )
{
return( stat );
}
if ( returnSR )
{
TMPL_ClearStatus();
}
TMPL_WriteF(blockadd, TMPL_CONFIG_SETUP);
TMPL_WriteF(blockadd, TMPL_LOCK_BIT_CLEAR);
if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
{
/* timeout during erase */
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 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -