⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sst39vf160x.h

📁 44b0+PDIUSBD12开发的U盘源码
💻 H
📖 第 1 页 / 共 3 页
字号:

 
/***********************************************************************/
/* 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             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_39VF16021            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) = 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(WORD *Src)
{ 
    //  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 (WORD 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(WORD *SST_SecID, WORD *User_SecID)
{
         //  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 (WORD 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_One_Sector                                        */
/*                                                                      */
/* This procedure can be used to erase a total of 2048 words.           */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address where the erase operation starts    */
/*                                                                      */
/* Output:                                                              */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -