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

📄 sst39vf400a.c

📁 外设存储器接口程序
💻 C
📖 第 1 页 / 共 2 页
字号:
extern void Erase_Entire_Chip(void)
{
        WORD * Temp;

        /*  Issue the Chip Erase command to 39VF400A  */

        Temp  = Addr5555; 				/* set up address to be C000:5555h  */
        *Temp = 0x00AA;                 /* write data 0xAAAA to the address */
        Temp  = Addr2AAA; 				/* set up address to be C000:2AAAh  */
        *Temp = 0x0055;                 /* write data 0x5555 to the address */
        Temp  = Addr5555; 				/* set up address to be C000:5555h  */
        *Temp = 0x0080;                 /* write data 0x8080 to the address */
        Temp  = Addr5555; 				/* set up address to be C000:5555h  */
        *Temp = 0x00AA;                 /* write data 0xAAAA to the address */
        Temp  = Addr2AAA; 				/* set up address to be C000:2AAAh  */
        *Temp = 0x0055;                 /* write data 0x5555 to the address */
        Temp  = Addr5555; 				/* set up address to be C000:5555h  */
        *Temp = 0x0010;                 /* write data 0x1010 to the address */
        Delay_100_Milli_Seconds();      /* Delay Tsce time                  */
}


/************************************************************************/
/* PROCEDURE:   Program_One_Word                                        */
/*                                                                      */
/* This procedure can be used to program ONE word of data to the        */
/* 39VF400.                                                             */
/*                                                                      */
/* NOTE:  It is necessary to first erase the sector containing the      */
/*        word to be programmed.                                		*/
/*                                                                      */
/* Input:                                                               */
/*           SrcWord The WORD which will be written to the 39VF400A     */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

extern void Program_One_Word (WORD SrcWord, WORD * Dst)
{
	    WORD * Temp;
        WORD * DestBuf;

        DestBuf = Dst;

        Temp =  Addr5555; 				/* set up address to be C000:555h   */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp =  Addr2AAA; 				/* set up address to be C000:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */
        Temp =  Addr5555; 				/* set up address to be C000:5555h  */
        *Temp = 0xA0A0;                 /* write data 0xA0A0 to the address */
        *DestBuf = SrcWord;             /* 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 2048 words of data  */
/* to the SST39VF400A.                                                  */
/*                                                                      */
/* Input:                                                               */
/*           Src     SOURCE address containing the data which will be   */
/*                   written to the 39VF400A                            */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

extern void Program_One_Sector (WORD * Src, WORD * Dst)
{
        WORD * Temp;
        WORD * SourceBuf;
        WORD * DestBuf;
        int Index;

        SourceBuf = Src;
        DestBuf = Dst;

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

        for (Index = 0; Index < SECTOR_SIZE; Index++)
        {
            Temp =  Addr5555;
            /* set up address to be C000:555h           */
            *Temp = 0x00AA;
            /* write data 0xAAAA to the address         */
            Temp =  Addr2AAA;
            /* set up address to be C000:2AAAh          */
            *Temp = 0x0055;
            /* write data 0x5555 to the address         */
            Temp =  Addr5555;
            /* set up address to be C000:5555h          */
            *Temp = 0x00A0;
            /* write data 0xA0A0 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:   Program_One_Block                                       */
/*                                                                      */
/* This procedure can be used to program a total of 32k words of data   */
/* to the SST39VF400A.                                                  */
/*                                                                      */
/* Input:                                                               */
/*           Src     SOURCE address containing the data which will be   */
/*                   written to the 39VF400A                            */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

extern void Program_One_Block(WORD * Src, WORD * Dst)
{
        WORD * Temp;
        WORD * SourceBuf;
        WORD * DestBuf;
        int Index;

        SourceBuf = Src;
        DestBuf = Dst;

        Erase_One_Block(Dst);          /* erase the sector first */

        for (Index = 0; Index < BLOCK_SIZE; Index++)
        {
            Temp =  Addr5555;
            /* set up address to be C000:555h           */
            *Temp = 0xAAAA;
            /* write data 0xAAAA to the address         */
            Temp =  Addr2AAA;
            /* set up address to be C000:2AAAh          */
            *Temp = 0x5555;
            /* write data 0x5555 to the address         */
            Temp =  Addr5555;
            /* set up address to be C000:5555h          */
            *Temp = 0xA0A0;
            /* write data 0xA0A0 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 be set-up by the caller            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

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

        PreData = *Dst;
        PreData = PreData & 0x4040;
        while ((TimeOut< 0x07FFFFFF) && (Loop))
        {
            CurrData = *Dst;
            CurrData = CurrData & 0x4040;
            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            */
/*           True       Data is the original (true) data                */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

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

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


/* -------------------------------------------------------------------- */
/*             Define   time-delay functions                            */
/* -------------------------------------------------------------------- */
extern void Delay_150_Nano_Seconds(void)
 {
  	int i;						// System main clock 200MHz, 5 nanoseconds per instruction cycle
  	for(i = 0; i < 40; i++) {}	// 延时200纳妙
 }

extern void Delay_25_Milli_Seconds(void)
 {
  	int i,j;			  		// System main clock 200MHz, 5 nanoseconds per instruction cycle		
  	for(i = 0; i < 1100; i++) 	// Perform 5000000 instruction cycles
   	{							// Perform 5500000 instruction cycles  为27.5Ms
    	for(j = 0; j < 5000; j++) {}
   	}
 }
 
extern void Delay_100_Milli_Seconds(void)
 {
  	int i,j;			  		// System main clock 200MHz, 5 nanoseconds per instruction cycle		
  	for(i = 0; i < 5000; i++) 	// Perform 20000000 instruction cycles
   	{							// Perform 25000000 instruction cycles  为125Ms
    	for(j = 0; j < 5000; j++) {}
   	}
 }
 
/***********************************************************************************/
//	No	more
/***********************************************************************************/

⌨️ 快捷键说明

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