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

📄 flash.c

📁 著名的嵌入式操作系统Nucleus的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	unsigned short *Temp;
        unsigned short *SourceBuf;
        unsigned short *DestBuf;
        int Index;
	unsigned short *TMP;
	TMP=(unsigned short *)FLASH_BASE;
        DestBuf = Dst;

        Temp =  (TMP+0x5555); /* set up address to be FLASH_BASE:555h   */
        *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 = 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                                                       */
/*Written by: Wang Tong Xaing (王同翔)					*/
/************************************************************************/

void Program_One_Sector (unsigned short *Src,    unsigned short *Dst)
{
        unsigned short *Temp;
        unsigned short *SourceBuf;
        unsigned short *DestBuf;
        int Index;
	unsigned short *TMP;
	TMP=(unsigned short *)FLASH_BASE;
        DestBuf = Dst;

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

        for (Index = 0; Index < SECT_SIZE; Index++)
        {
            Temp =  (TMP+0x5555);
            /* set up address to be FLASH_BASE:555h           */
            *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 = 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:   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                                                       */
/* Written By : Wang Tong Xiang (王同翔)				*/
/************************************************************************/

void Program_One_Block (unsigned short *Src,    unsigned short *Dst)
{
        unsigned short *Temp;
        unsigned short *SourceBuf;
        unsigned short *DestBuf;
        int Index;
	unsigned short *TMP;
        DestBuf = Dst;
	
	TMP=(unsigned short *)FLASH_BASE;
        Erase_One_Block(Dst);          /* erase the sector first */

        for (Index = 0; Index < BLOCK_SIZE; Index++)
        {
            Temp =  (TMP+0x5555);
            /* set up address to be FLASH_BASE:555h           */
            *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 = 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_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                                                       */
/* Written by: Wang Tong Xaing						*/
/************************************************************************/

void Check_Data_Polling (unsigned short  *Dst,       unsigned short TrueData)
{
        unsigned char Loop = TRUE;
        unsigned short 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++;
        }
}


void Program(unsigned short *Src, unsigned short *Dst, unsigned long size)
{
	unsigned short *ss;
	unsigned short *dd;
	unsigned short fg;
	unsigned long ff;
	ss=Src;
	dd=Dst;
	for(ff=0;ff<size;ff++)
	{
		fg=*ss;
		Program_One_Word (fg, dd);
		ss+=1;
		dd+=1;
	}
}

⌨️ 快捷键说明

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