?? 39vf160.c
字號:
/***********************************************************************/
//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
//"C" LANGUAGE DRIVERS
/***********************************************************************/
/* Copyright Silicon Storage Technology, Inc. (SST), 1994-2001 */
/* Example "C" language Driver of 39VF160 16 Mbit Multi-Purpose Flash */
/* Nelson Wang, Silicon Storage Technology, Inc. */
/* */
/* Revision 1.0, Sept. 12, 2001 */
/* */
/* This file requires these external "timing" routines: */
/* */
/* 1.) Delay_150_Nano_Seconds */
/* 2.) Delay_25_Milli_Seconds */
/* 3.) Delay_100_Milli_Seconds */
/***********************************************************************/
#define FALSE 0
#define TRUE 1
#define SECTOR_SIZE 2048 /* Must be 2048 words for 39VF160 */
#define BLOCK_SIZE 32768 /* Must be 32K words for 39VF160 */
#define SST_ID 0xBF /* SST Manufacturer's ID code */
#define SST_39VF160 0x2782 /* SST 39VF160 device code */
typedef unsigned char BYTE;
typedef unsigned int WORD;
/* -------------------------------------------------------------------- */
/* EXTERNAL ROUTINES */
/* -------------------------------------------------------------------- */
extern void Delay_150_Nano_Seconds();
extern void Delay_25_Milli_Seconds();
extern void Delay_100_Milli_Seconds();
*************************************************************************/
/* 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 */
/************************************************************************/
int Check_SST_39VF160()
{
WORD far *Temp;
WORD SST_id1;
WORD far *Temp1;
WORD SST_id2;
int ReturnStatus;
/* Issue the Software Product ID code to 39VF160 */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1= 0xAAAA; /* write data 0xAAAA to the address */
Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp1= 0x5555; /* write data 0x5555 to the address */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1= 0x9090; /* write data 0x9090 to the address */
Delay_150_Nano_Seconds();
/* Read the product ID from 39VF160 */
Temp = (WORD far *)0xC0000000; /* set up address to be C000:0000h */
SST_id1 = *Temp; /* get first ID word */
SST_id1 = SST_id1 & 0xFF /* mask of higher byte */
Temp1 = (WORD far *)0xC0000001;/* set up address to be C000:0001h */
SST_id2 = *Temp1; /* get second ID word */
/* Determine whether there is a SST39VF160 installed or not */
if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39VF160))
ReturnStatus = TRUE;
else
ReturnStatus = FALSE;
/* Issue the Soffware Product ID Exit code thus returning the 39VF160 */
/* to the read operating mode */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1 = 0xAAAA; /* write data 0xAAAA to the address */
Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp1 = 0x5555; /* write data 0x5555 to the address */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1 = 0xF0F0; /* write data 0xF0F0 to the address */
Delay_150_Nano_Seconds();
return(ReturnStatus);
}
*************************************************************************/
/* PROCEDURE: CFI_Query */
/* */
/* This procedure should be used to query for CFI information */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* None */
/************************************************************************/
int CFI_Query()
{
WORD far *Temp1;
/* Issue the Software Product ID code to 39VF160 */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1= 0xAAAA; /* write data 0xAAAA to the address */
Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp1= 0x5555; /* write data 0x5555 to the address */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1= 0x9898; /* write data 0x9898 to the address */
Delay_150_Nano_Seconds();
/* --------------------------------- */
/* Perform all CFI operations here */
/* NOTE: no sample code provided */
/* --------------------------------- */
/* Issue the CFI Exit code thus returning the 39VF160 */
/* to the read operating mode */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1 = 0xAAAA; /* write data 0xAAAA to the address */
Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp1 = 0x5555; /* write data 0x5555 to the address */
Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp1 = 0xF0F0; /* write data 0xF0F0 to the address */
Delay_150_Nano_Seconds();
}
*************************************************************************/
/* PROCEDURE: Erase_Entire_Chip */
/* 整片的Flash擦除 */
/* This procedure can be used to erase the entire chip. */
/* */
/* Input: */
/* NONE */
/* */
/* Output: */
/* NONE */
/************************************************************************/
int Erase_Entire_Chip
{
WORD far *Temp;
/* Issue the Chip Erase command to 39VF160 */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0x8080; /* write data 0x8080 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0x1010; /* write data 0x1010 to the address */
Delay_100_Milli_Seconds(); /* Delay Tsce time */
}
*************************************************************************/
/* 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 */
/************************************************************************/
int Erase_One_Sector (WORD far *Dst)
{
WORD far *Temp;
/* Issue the Sector Erase command to 39VF160 */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0x8080; /* write data 0x8080 to the address */
Temp = (WORD far *)0xC0005555; /* set up address to be C000:5555h */
*Temp = 0xAAAA; /* write data 0xAAAA to the address */
Temp = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh */
*Temp = 0x5555; /* write data 0x5555 to the address */
Temp = Dst /* set up starting address to be erased */
*Temp = 0x3030; /* write data 0x3030 to the address */
Delay_25_Milli_Seconds(); /* Delay time = Tse */
}
*************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -