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

📄 flash.c

📁 著名的嵌入式操作系统Nucleus的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "wtx.h"
#include "e:\nucleus\nucleus_plus\nucleus.h"
#define FALSE                   0
#define TRUE                    1

/************************************************************************/
/* 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                                                       */
/* Written By : Wang Tong Xaing (王同翔)				*/
/************************************************************************/


void Check_Toggle_Ready(unsigned short  *Dst)
{
	
        unsigned char Loop = TRUE;
        unsigned short PreData;
        unsigned short 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:    Erase_One_Sector
//
//This procedure can be used to erase a sector, or total of 4096 bytes,
// in the SST39VF400A.
//
// Input:
//       Dst   points to the beginning address of the "Destination" 
//               sector which will be erased.
//               ==> Note: The address MUST be on a sector boundary,
//                         that is, a multiple of 4096.
//
// Output:
//       None
// Writen by:  Wang Tong Xiang (王同翔)
// =====================================================================

void Erase_One_Sector (unsigned short *Dst)
{
        unsigned short *Temp;
        unsigned short *TMP;
	TMP=(unsigned short *)FLASH_BASE;
        /*  Issue the Sector Erase command to 39VF400A  */

        Temp  = TMP+0x5555; /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp  = (TMP+0x2AAA); /* set up address to be FLASH_BASE:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0x8080;                 /* write data 0x8080 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp  = (TMP+0x2AAA); /* set up address to be FLASH_BASE:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */

        Temp  = Dst;                  /* set up starting address to be erased */
        *Temp = 0x3030;                 /* write data 0x3030 to the address */
        NU_Sleep(3);       /* Delay time = Tse                 */
}


/************************************************************************/
/* PROCEDURE:   Erase_One_Block                                         */
/*                                                                      */
/* This procedure can be used to erase a total of 32K words.            */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address where the erase operation starts    */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/*Written by: Wang Tong Xiang (王同翔)  				*/
/************************************************************************/

void Erase_One_Block (unsigned short *Dst)
{
        unsigned short *Temp;
	unsigned short *TMP;
	TMP=(unsigned short *)FLASH_BASE;
        /*  Issue the Sector Erase command to 39VF400A  */

        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp  = (TMP+0x2AAA); /* set up address to be FLASH_BASE:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0x8080;                 /* write data 0x8080 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp  = (TMP+0x2AAA); /* set up address to be FLASH_BASE:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */

        Temp  = Dst;                  /* set up starting address to be erased */
        *Temp = 0x5050;                 /* write data 0x5050 to the address */
        NU_Sleep(3);       /* Delay time = Tbe                 */
}

/************************************************************************/
/* PROCEDURE:   Erase_Entire_Chip                                       */
/*                                                                      */
/* This procedure can be used to erase the entire chip.                 */
/*                                                                      */
/* Input:                                                               */
/*      NONE                                                            */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/*Written By : Wang Tong Xiang (王同翔)				*/
/************************************************************************/

void Erase_Entire_Chip()
{
        unsigned short *Temp;
	unsigned short *TMP;
	TMP=(unsigned short *)FLASH_BASE;
        /*  Issue the Chip Erase command to 39VF400A  */

        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp  = (TMP+0x2AAA); /* set up address to be FLASH_BASE:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0x8080;                 /* write data 0x8080 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
        Temp  = (TMP+0x2AAA); /* set up address to be FLASH_BASE:2AAAh  */
        *Temp = 0x5555;                 /* write data 0x5555 to the address */
        Temp  = (TMP+0x5555); /* set up address to be FLASH_BASE:5555h  */
        *Temp = 0x1010;                 /* write data 0x1010 to the address */
        NU_Sleep(10);      /* 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                                                       */
/* Written By : Wang Tong Xiang (王同翔)				*/
/************************************************************************/

void Program_One_Word (unsigned short SrcWord,    unsigned short *Dst)
{

⌨️ 快捷键说明

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