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

📄 sst39sf040.txt

📁 很全的flash芯片驱动程序包括:SST28SF040
💻 TXT
📖 第 1 页 / 共 2 页
字号:
Software
Drivers

39SF040
4 Mbit(512K x 8) Multi-Purpose Flash

September 2001

ABOUT THE SOFTWARE
This application note provides software driver examples for 39SF040, 4 Mbit
(512K x 8) Multi-Purpose Flash, that can be used in any microprocessor based 
system.  Software driver examples used in this document utilize two 
programming languages: (a) high -level "C" for broad platform support and 
(b) optimized 8086 assembly language. 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 driver in "C" language can be 
used with many microprocessors and microcontrollers, while the 8086 assembly 
language provides an optimized solution for 8086 microprocessors.

ABOUT THE 39SF040

Companion product datasheets for the 39SF040 should be reviewed in conjunction
with this application note for a complete understanding of the device.

Both the C and 8086 assembly code in the document contain the following
routines, in this order:

Name                    Function
------------------------------------------------------------------
Check_SST_39SF040       Check manufacturer and device ID
Erase_Entire_Chip       Erase the contents of the entire chip
Erase_One_Sector        Erase a sector of 4096 bytes
Program_One_Byte        Alter data in one byte
Program_One_Sector      Alter data in 4096 bytes sector
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 Drivers of 39SF040 4 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             4096    /* Must be 4096 bytes for 39SF040 */

#define SST_ID                  0xBF    /* SST Manufacturer's ID code   */
#define SST_39SF040             0xB7    /* SST 39SF040 device code      */

typedef unsigned char           BYTE;

/* -------------------------------------------------------------------- */
/*                       EXTERNAL ROUTINES                              */
/* -------------------------------------------------------------------- */

extern void     Delay_150_Nano_Seconds();
extern void     Delay_25_Milli_Seconds();
extern void     Delay_100_Milli_Seconds();


*************************************************************************/
/* PROCEDURE:   Check_SST_39SF040                                       */
/*                                                                      */
/* This procedure decides whether a physical hardware device has a      */
/* SST 39SF040  4 Mbit Multi-Purpose Flash installed or not.            */
/*                                                                      */
/* Input:                                                               */
/*          None                                                        */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates a SST 39SF040                       */
/*          return FALSE: indicates not a SST 39SF040                   */
/************************************************************************/

int Check_SST_39SF040()
{
        BYTE far *Temp;
        BYTE SST_id1;
        BYTE SST_id2;
        int  ReturnStatus;

        /*  Issue the Software Product ID code to 39SF040  */

        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp  = (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0x90;                   /* write data 0x90 to the address     */

        Delay_150_Nano_Seconds();       /* check DATABOOK for the most  */
                                        /* accurate value -- Tida       */

        /* Read the product ID from 39SF040 */

        Temp  = (BYTE far *)0xA0000000; /* set up address to be A000:0000h    */
        SST_id1  =  *Temp;              /* get first ID byte                  */
        Temp  = (BYTE far *)0xA0000001; /* set up address to be A000:0001h    */
        SST_id2  =  *Temp;              /* get first ID byte                  */

        /* Determine whether there is a SST 39SF040 installed or not */

        if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39SF040))
                ReturnStatus = TRUE;
        else
                ReturnStatus = FALSE;

        /* Issue the Soffware Product ID Exit code thus returning the 39SF040 */
        /* to the read operating mode                                         */

        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp  = (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp =0xF0;                    /* write data 0xF0 to the address     */

        Delay_150_Nano_Seconds();       /* check DATABOOK for the most  */
                                        /* accurate value -- Tida       */

        return (ReturnStatus);
}


*************************************************************************/
/* PROCEDURE:   Erase_Entire_Chip                                       */
/*                                                                      */
/* This procedure can be used to erase the entire chip.                 */
/*                                                                      */
/* Input:                                                               */
/*      NONE                                                            */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/

int Erase_Entire_Chip()
{
        BYTE far *Temp;

        /*  Issue the Sector Erase command to 39SF040   */

        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp  = (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0x80;                   /* write data 0x80 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp  = (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0x10;                   /* write data 0x10 to the address     */

        Delay_100_Milli_Seconds();      /* check DATABOOK for the most  */
                                        /* accurate value -- Tsce       */
}



*************************************************************************/
/* PROCEDURE:   Erase_One_Sector                                        */
/*                                                                      */
/* This procedure can be used to erase a total of 4096 bytes.           */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address at which the erase operation will   */
/*              start.                                                  */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/

int Erase_One_Sector(BYTE far *Dst)
{
        BYTE far *Temp;

        /*  Issue the Sector Erase command to 39SF040   */

        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp  = (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0x80;                   /* write data 0x80 to the address     */
        Temp  = (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp  = (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp  = Dst                   /* set up starting address to be erased */
        *Temp = 0x30;                   /* write data 0x30 to the address     */

        Delay_25_Milli_Seconds();       /* check DATABOOK for the most  */
                                        /* accurate value -- Tse        */
}


/************************************************************************/
/* PROCEDURE:   Program_One_Byte                                        */
/*                                                                      */
/* This procedure can be used to program ONE byte of date to the        */
/* 39SF040.                                                             */
/*                                                                      */
/* NOTE:  It is mandatory that the sector containing the byte to be     */
/*        programmed was ERASED first.                                  */
/*                                                                      */
/* Input:                                                               */
/*           SrcByte The BYTE which will be written to the 39SF040.     */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from SrcByte                        */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Program_One_Byte (BYTE SrcByte,    BYTE far *Dst)
{
        BYTE far *SourceBuf;
        BYTE far *DestBuf;
        int Index;

        DestBuf = Dst;

        Temp =  (BYTE far *)0xA0005555; /* set up address to be A000:555h     */
        *Temp = 0xAA;                   /* write data 0xAA to the address     */
        Temp =  (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh    */
        *Temp = 0x55;                   /* write data 0x55 to the address     */
        Temp =  (BYTE far *)0xA0005555; /* set up address to be A000:5555h    */
        *Temp = 0xA0;                   /* write data 0xA0 to the address     */
        *DestBuf = SrcByte;             /* transfer the byte to destination   */
        Check_Toggle_Ready(DestBuf);    /* wait for TOGGLE bit to get ready   */
}


/************************************************************************/
/* PROCEDURE:   Program_One_Sector                                      */
/*                                                                      */
/* This procedure can be used to program a total of 4096 bytes of data  */
/* to the SST's 39SF040.                                                */
/*                                                                      */
/* Input:                                                               */
/*           Src     SOURCE address containing the data which will be   */
/*                   written to the 39SF040.                            */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Program_One_Sector (BYTE far *Src,    BYTE far *Dst)
{
        BYTE far *Temp;
        BYTE far *SourceBuf;
        BYTE far *DestBuf;
        int Index;

        SourceBuf = Src;
        DestBuf = Dst;

        Erase_One_Sector(Src);          /* erase the sector first */

        for (Index = 0; Index < SECTOR_SIZE; Index++)
        {
            Temp =  (BYTE far *)0xA0005555; /* set up address to be A000:555h */
            *Temp = 0xAA;                   /* write data 0xAA to the address */
            Temp =  (BYTE far *)0xA0002AAA; /* set up address to be A000:2AAAh*/
            *Temp = 0x55;                   /* write data 0x55 to the address */
            Temp =  (BYTE far *)0xA0005555; /* set up address to be A000:5555h*/
            *Temp = 0xA0;                   /* write data 0xA0 to the address */
            Temp = DestBuf;
            	/* save the original Destination address    */
            *DestBuf++ = *SourceBuf++;
            	/* transfer data from source to destination */
            Check_Toggle_Ready(Temp);
            	/* wait for TOGGLE bit to get ready         */
        }
}


/************************************************************************/
/* PROCEDURE:    Check_Toggle_Ready                                     */
/*                                                                      */
/* During the internal program cycle, any consecutive read operation    */
/* on DQ6 will produce alternating 0's and 1's i.e. toggling between    */
/* 0 and 1. When the program cycle is completed, DQ6 of the data will   */
/* stop toggling. After the DQ6 data bit stops toggling, the device is  */
/* ready for next operation.                                            */
/*                                                                      */
/* Input:                                                               */
/*           Dst        must already set-up by the caller               */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Check_Toggle_Ready (BYTE far  *Dst)
{
        BYTE Loop = TRUE;
        BYTE PreData;
        BYTE CurrData;
        unsigned long TimeOut = 0;

        PreData = *Dst;
        PreData = PreData & 0x40;
        while ((TimeOut< 0x07FFFFFF) && (Loop))
        {
            CurrData = *Dst;
            CurrData = CurrData & 0x40;
            if (PreData == CurrData)
                    Loop = FALSE;   /* ready to exit the while loop */
            PreData = CurrData;
            TimeOut++;
        }
}


/************************************************************************/
/* PROCEDURE:   Check_Data_Polling                                      */
/*                                                                      */
/* During the internal program cycle, any attempt to read DQ7 of the    */
/* last byte loaded during the page/byte-load cycle will receive the    */
/* complement of the true data.  Once the program cycle is completed,   */
/* DQ7 will show true data.                                             */
/*                                                                      */
/* Input:                                                               */
/*           Dst        must already be set-up by the caller            */
/*           TrueData 	this is the original (true) data            	*/
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Check_Data_Polling (BYTE far  *Dst,       BYTE TrueData)
{
        BYTE Loop = TRUE;
        BYTE CurrData;
        unsigned long TimeOut = 0;

        TrueData = TrueData &  0x80;
        while ((TimeOut< 0x07FFFFFF) && (Loop))
        {

⌨️ 快捷键说明

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