📄 1601driver.h
字号:
#ifndef __1601DRIVER_H__#define __1601DRIVER_H__ /***********************************************************************//* 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 *//***********************************************************************/#include"User.h"//#define FALSE 0//#define TRUE 1#define SECTOR_SIZE_1601 2048 // Must be 2048 U16s for 39VF160X#define BLOCK_SIZE 32768 // Must be 32K U16s for 39VF160X#define SST_ID 0x00BF // SST Manufacturer's ID code#define SST_39VF1601 0x234B // SST39VF1601 device codeU32 system_base = 0x00000000; //Flash硬件编址#define sysAddress(offset) ((volatile U16 *)((system_base + offset)<<1))#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// --------------------------------------------------------------------void Delay_10_Micro_Seconds(){int i;for(i=0;i<0x100000;i++);}void Delay_20_Micro_Seconds(){int i;for(i=0;i<0x100000;i++);}void Delay_150_Nano_Seconds(){int i;for(i=0;i<0x100000;i++);}void Delay_25_Milli_Seconds(){int i;for(i=0;i<0x100000;i++);}void Delay_50_Milli_Seconds(){int i;for(i=0;i<0x100000;i++);}// --------------------------------------------------------------------int Check_SST_39VF160X(void);void CFI_Query(U16*);void SecID_Query(U16*, U16*);int Erase_Sector(U32);int Erase_Block (U32);void Erase_Entire_Chip(void);int Program_One_U16 (U16*, U32);int Program_Sector (U16*, U32);int Program_Block (U16 *Src, U32 Dst);int SecID_Lock_Status(void);int User_SecID_U16_Program (U16*, U16*, int);void User_SecID_Lock_Out (void);void Erase_Suspend (void);void Erase_Resume (void);int Check_Toggle_Ready (U32);int Check_Data_Polling (U32, U16);/************************************************************************//* 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) /*读 Flash Product ID*/{ U16 SST_id1; U16 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 U8 SST_id2 = *sysAddress(0x0001); // get second ID U8 // ------------------------------------------------------------ // 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; // ------------------------------------------------------------ // 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) = 0x0055; // write data 0x0055 to device addr 0x2AAA *sysAddress(0x5555) = 0x00F0; // write data 0x00F0 to device addr 0x5555 Delay_150_Nano_Seconds(); // Tida Max 150ns for 39VF160X return (ReturnStatus);}/************************************************************************//* PROCEDURE: CFI_Query *//* *//* This procedure should be used to query for CFI information *//* *//* Input: *//* Src Source address to store CFI_Query data string *//* *//* Output: *//* None *//************************************************************************/void CFI_Query(U16 *Src) { U16 index; // Issue the CFI Query entry 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) = 0x0098; // write data 0x0098 to device addr 0x5555 Delay_150_Nano_Seconds(); // insert delay time = Tida // ---------------------------------------------------------- // Perform all CFI operations here: // CFI_Query_address is from 0010H--0034H for (index = 0x0010; index <= 0x0034; index++) { *Src = *sysAddress(index); ++Src; // CFI query data is stored in user-defined memory space. } // ---------------------------------------------------------- // Issue the CFI Exit code thus returning the 39VF160X // to the read operating mode *sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555 *sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA *sysAddress(0x5555) = 0x00F0; // write data 0x00F0 to device addr 0x5555 Delay_150_Nano_Seconds(); // insert delay time = Tida}/************************************************************************//* PROCEDURE: SecID_Query *//* *//* This procedure should be used to query for Security ID information. *//* *//* Input: *//* SST_SecID Source address to store SST SecID string *//* User_SecID Source address to store User SecID string *//* *//* Output: *//* None *//************************************************************************/void SecID_Query(U16 *SST_SecID, U16 *User_SecID){ U16 index; // Issue the SecID Entry 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) = 0x0088; // write data 0x0088 to device addr 0x5555 Delay_150_Nano_Seconds(); // insert delay time = Tida // Perform all Security ID operations here: // SST programmed segment is from address 000000H--000007H, // User programmed segment is from address 000010H--000017H. for (index = 0x0000; index <= 0x0007; index++) { *SST_SecID = *sysAddress(index); ++SST_SecID; *User_SecID = *sysAddress(index+0x0010); ++User_SecID; // Security query data is stored in user-defined memory space. } // Issue the Sec ID Exit code thus returning the 39VF160X // to the read operating mode *sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555 *sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA *sysAddress(0x5555) = 0x00F0; // write data 0x00F0 to device addr 0x5555 Delay_150_Nano_Seconds(); // insert delay time = Tida}/************************************************************************//* PROCEDURE: Erase_Sector *//* *//* This procedure can be used to erase a total of 2048 U16s. *//* *//* Input: *//* Dst DESTINATION address where the erase operation starts *//* *//* Output: *//* return TRUE: indicates success in sector-erase *//* return FALSE: indicates failure in sector-erase *//************************************************************************/int Erase_Sector(U32 Dst){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -