• PUDN用户
  • Visual C++
  • 5KB
  • rar
  • 0
  • 1 积分
  • 92
  • 2006-06-29 05:02
  • SST39VF160x.c
Software Driver SST39VF1601/SST39VF1602 16 Mbit Multi-Purpose Flash (MPF+) June 2003 ABOUT THE SOFTWARE This application note provides a software driver example for 39VF1601/39VF1602 16 Mbit Multi-Purpose Flash (MPF+) that can be used in any microprocessor based system. The SST39VF1601 supports bottom boot block protection, and the SST39VF1602 supports top boot block protection. The boot block memory area is protected when WP# is low and unprotected when WP# is high. Software driver example routines provided in this document utilize high-level "C" programming language for broad platform support. In many cases, software driver routines can be inserted "as is" into the main body of code being developed by the system software developers. Extensive comments are included in each routine to describe the function of each routine. The software driver routines in "C" can be used with many microprocessors and microcontrollers. ABOUT THE SST39VF1601/SST39VF1602 Companion product datasheet for 39VF1601/39VF1602 should be reviewed in conjunction with this application note for a complete understanding of the device. The C code in this document contains the following routines, which are listed in this order: Name Function ------------------------------------------------------------------ Check_SST_39VF160X Check manufacturer and device ID CFI_Query CFI Query Entry/Exit command sequence SecID_Query SecID Query Entry/Exit command sequence Erase_One_Sector Erase a sector of 2048 words Erase_One_Block Erase a block of 32K words Erase_Entire_Chip Erase the contents of the entire chip 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 SecID_Lock_Status Check the Lock Status of Security ID segment User_SecID_Word_Program Write data into User Security ID Segment User_SecID_Lock_Out Lock out the User Security ID Segment Erase_Suspend Suspend Sector/Block Erase operation Erase_Resume Resume Sector/Block Erase operation 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-2003 */ /* Example "C" language Driver of 39VF160X 16 Mbit MPF+ Device */ /* Nelson Wang, Silicon Storage Technology, Inc. */ /* */ /* Revision 1.0, June 19, 2003 */ /* */ /* This file requires these external "timing" routines: */ /* */ /* 1.) Delay_10_Micro_Seconds */ /* 2.) Delay_20_Micro_Seconds */ /* 3.) Delay_150_Nano_Seconds */ /* 4.) Delay_25_Milli_Seconds */ /* 5.) Delay_50_Milli_Seconds */ /***********************************************************************/ #define FALSE 0 #define TRUE 1 #define SECTOR_SIZE 2048 // Must be 2048 words for 39VF160X #define BLOCK_SIZE 32768 // Must be 32K words for 39VF160X #define SST_ID 0x00BF // SST Manufacturer's ID code #define SST_39VF1601 0x234B // SST39VF1601 device code #define SST_39VF1602 0x234A // SST39VF1602 device code typedef unsigned char BYTE; // BYTE is 8-bit in length typedef unsigned int WORD; // WORD is 16-bit in length typedef unsigned long int Uint32; // Uint32 is 32-bit in length Uint32 system_base = 0xC0000000; // 4GByte System Memory Address. // This sample code uses 0xC0000000 as the system_base address. // The user should modify this address accordingly. #define sysAddress(offset) ((volatile WORD *)(system_base + offset)) #define MAX_TIMEOUT 0x07FFFFFF // A ceiling constant used by Check_Toggle_ // Ready() and Check_Data_Polling(). // The user should modify this constant accordingly. // -------------------------------------------------------------------- // EXTERNAL ROUTINES // -------------------------------------------------------------------- extern void Delay_10_Micro_Seconds(); extern void Delay_20_Micro_Seconds(); extern void Delay_150_Nano_Seconds(); extern void Delay_25_Milli_Seconds(); extern void Delay_50_Milli_Seconds(); // -------------------------------------------------------------------- int Check_SST_39VF160X(void); void CFI_Query(WORD*); void SecID_Query(WORD*, WORD*); int Erase_One_Sector(Uint32); int Erase_One_Block (Uint32); void Erase_Entire_Chip(void); int Program_One_Word (WORD*, Uint32); int Program_One_Sector (WORD*, Uint32); int Program_One_Block (WORD *Src, Uint32 Dst); int SecID_Lock_Status(void); int User_SecID_Word_Program (WORD*, WORD*, int); void User_SecID_Lock_Out (void); void Erase_Suspend (void); void Erase_Resume (void); int Check_Toggle_Ready (Uint32); int Check_Data_Polling (Uint32, WORD); /************************************************************************/ /* PROCEDURE: Check_SST_39VF160X */ /* */ /* This procedure decides whether a physical hardware device has a */ /* SST39VF160X 16 Mbit MPF+ Device installed or not. */ /* */ /* Input: */ /* None */ /* */ /* Output: */ /* return TRUE: indicates a SST39VF160X */ /* return FALSE: indicates not a SST39VF160X */ /************************************************************************/ int Check_SST_39VF160X(void) { WORD SST_id1; WORD SST_id2; int ReturnStatus; // Issue the Software Product ID code to 39VF160X *sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555 *sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA *sysAddress(0x5555) = 0x0090; // write data 0x0090 to device addr 0x5555 Delay_150_Nano_Seconds(); // Tida Max 150ns for 39VF160X // Read the product ID from 39VF160X SST_id1 = *sysAddress(0x0000); // get first ID byte SST_id2 = *sysAddress(0x0001); // get second ID byte // ------------------------------------------------------------ // Determine whether there is a SST 39VF1601 installed or not // use the following code: if ((SST_id1 == SST_ID) && (SST_id2 == SST_39VF1601)) ReturnStatus = TRUE; else ReturnStatus = FALSE; // ------------------------------------------------------------ // Or determine whether there is a SST 39VF1602 installed or not // use the following code: if ((SST_id1 == SST_ID) && (SST_id2 == SST_39VF1602)) ReturnStatus = TRUE; else ReturnStatus = FALSE; // ------------------------------------------------------------ // Issue the Software Product ID Exit code, thus returning the // 39VF160X to the normal operation. *sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555 *sysAddress(0x2AAA)