📄 sst39vf160.c
字号:
/*
ABOUT THE 39VF160/39VF160Q
Companion product datasheets for the 39VF160/39VF160Q should be reviewed in
conjunction with this application note for a complete understanding of
the device.
Name Function
------------------------------------------------------------------
Check_SST_39VF160 Check manufacturer and device ID
CFI_Query CFI Query Entry/Exit command sequence
Erase_Entire_Chip Erase the contents of the entire chip
Erase_One_Sector Erase a sector of 2048 word
Erase_One_Block Erase a block of 32K word
Program_One_Word Alter data in one word
Program_One_Sector Alter data in 2048 word sector
Program_One_Block Alter data in 32K word block
Check_Toggle_Ready End of internal program or erase detection using
Toggle bit
Check_Data_Polling End of internal program or erase detection using
Data# polling
*/
/***********************************************************************/
/* Copyright Silicon Storage Technology, Inc. (SST), 1994-1999 */
/* Example "C" language Driver of 39VF160 16 Mbit Multi-Purpose Flash */
/* Chi Chung Yin, Silicon Storage Technology, Inc. */
/* */
/* Revision 1.0, June 16, 1999 */
/* */
/* This file requires these external "timing" routines: */
/* */
/* 1.) Delay_150_Nano_Seconds */
/* 2.) Delay_25_Milli_Seconds */
/* 3.) Delay_100_Milli_Seconds */
/***********************************************************************/
#include "flash.h"
void Check_Toggle_Ready(UINT32 *);
void Delay_Milli_Seconds(unsigned long delayCount)
{
unsigned long ix;
for (ix = 0; ix < delayCount; ix ++);
}
/************************************************************************/
/* PROCEDURE: Check_SST_39VF160 */
/* */
/* This procedure decides whether a physical hardware device has a */
/* SST39VF160 16 Mbit Multi-Purpose Flash installed or not. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* return TRUE: indicates a SST39VF160 */
/* return FALSE: indicates not a SST39VF160 */
/************************************************************************/
STATUS Check_SST_39VF160()
{
UINT32 SST_id1;
UINT32 SST_id2;
STATUS ReturnStatus;
/* Issue the Software Product ID code to 39VF160 */
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_SWIDENTRY;
Delay_Milli_Seconds(2);
/* Read the product ID from 39VF160 */
SST_id1 = *(UINT32 *)FLASH_ADRS;
SST_id2 = *(UINT32 *)(FLASH_ADRS + 1);
/* Determine whether there is a SST39VF160 installed or not */
if ((SST_id1 == SST_ID) && (SST_id2 == SST_39VF160))
ReturnStatus = OK;
else
ReturnStatus = ERROR;
/* Issue the Soffware Product ID Exit code thus returning the 39VF160 */
/* to the read operating mode */
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_SWCFIEXIT;
Delay_Milli_Seconds(2);
return(ReturnStatus);
}
/************************************************************************/
/* PROCEDURE: CFI_Query */
/* */
/* This procedure should be used to query for CFI information */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* None */
/************************************************************************/
STATUS CFI_Query()
{
STATUS retVal = OK;
/* Issue the Software Product ID code to 39VF160 */
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_CFIENTRY;
Delay_Milli_Seconds(2);
/* Issue the CFI Exit code thus returning the 39VF160 */
/* to the read operating mode */
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_SWCFIEXIT;
Delay_Milli_Seconds(2);
return retVal;
}
/************************************************************************/
/* PROCEDURE: Erase_Entire_Chip */
/* */
/* This procedure can be used to erase the entire chip. */
/* */
/* Input: */
/* NONE */
/* */
/* Output: */
/* NONE */
/************************************************************************/
STATUS Erase_Entire_Chip(void)
{
STATUS retVal = OK;
/* Issue the Chip Erase command to 39VF160 */
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_ERASE;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FOURTH;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_FIFTH;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_CHIP;
Delay_Milli_Seconds(100000); /* Delay Tsce time */
return retVal;
}
/************************************************************************/
/* PROCEDURE: Erase_One_Sector */
/* */
/* This procedure can be used to erase a total of 2048 words. */
/* */
/* Input: */
/* Dst DESTINATION address which the erase operation starts */
/* */
/* Output: */
/* NONE */
/************************************************************************/
STATUS Erase_One_Sector (UINT32 *Dst)
{
UINT32 *Temp;
STATUS retVal = OK;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_SECTOR;
*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FOURTH;
*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_FIFTH;
Temp = Dst;
*Temp = SST_CMD_SECTOR;
Delay_Milli_Seconds(25000); /* Delay time = Tse */
return retVal;
}
/************************************************************************/
/* PROCEDURE: Erase_One_Block */
/* */
/* This procedure can be used to erase a total of 32K words. */
/* */
/* Input: */
/* Dst DESTINATION address which the erase operation starts */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -