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

📄 flash.c.svn-base

📁 lwip协议在arm7+uCos系统上的移植
💻 SVN-BASE
字号:
/***************************************************************************
  文件名称:flash.c
  版本号:	1.0
  日期:	2005-12-16
  说明:	搭配flash.h使用,对flash进行擦写
  调用列表:--
  修改历史:--
*****************************************************************************/
#include "semihosting.h"
#include "delay.h"
#include "flash.h"


/****************************************************************************
  函数名称:EraserFlash(int type,int address)
  说明:	擦除Flash
  调用函数:Delay()
  输入参数:type 擦除类型,address擦除地址
  输出参数:0擦除失败,1擦除成功
****************************************************************************/
int EraserFlash(int type,unsigned int address)
{
	volatile int old_s,new_s;
	
	WriteFlash(0x5555,0xaa);
	WriteFlash(0x2aaa,0x55);
	WriteFlash(0x5555,0x80);
	WriteFlash(0x5555,0xaa);
	WriteFlash(0x2aaa,0x55);
	
	Delay(0);//Reset the clock
	
	switch(type)
	{
		case 1:
			WriteFlash(0x5555,0x10);
			Delay(1500);
			break;
		case 2:
			WriteFlash(address,0x50);
			Delay(300);
			break;
		case 3:
			WriteFlash(address,0x30);
			Delay(300);
			break;
		default :
			return 0;
	}
	
	old_s = ReadFlash(0x0);
	new_s = ReadFlash(0x0);
	if((old_s & 0x40) == (new_s & 0x40))
		return 1; 
	else
		return 0;
}


/****************************************************************************
  函数名称:WriteFH(int address,unsigned short data)
  说明:	擦除Flash
  调用函数:
  输入参数:address 写入地址,date 写入数据
  输出参数:0写入失败,1写入成功
****************************************************************************/
int WriteFH(unsigned int address, unsigned short data)
{
	volatile unsigned short old_s,new_s;
	int WriteOver = 1;
	
	if(address > 0xfffff)   //SST39VF160's highest address
		return 0;
		
	WriteFlash(0x5555,0xaa);
	WriteFlash(0x2aaa,0x55);
	WriteFlash(0x5555,0xa0);
	WriteFlash(address,data);
	
	
	old_s = ReadFlash(0x0);
	while(WriteOver)
	{
		new_s = ReadFlash(0x0);
		if((old_s & 0x40) == (new_s & 0x40))
			WriteOver = 0; 
		else
			old_s = new_s;
	}
	
	if(data == ReadFlash(address))
		return 1;
	else
		return 0;
		
}
/****************************************************************************
  函数名称:ReadFID(unsigned short* MID, unsigned short* DID)
  说明:	读取flash的ID
  调用函数:
  输入参数:MID指向manufacturer ID, DID指向device ID
  输出参数:无
****************************************************************************/
void ReadFID(unsigned short* MID, unsigned short* DID)
{
	WriteFlash(0x5555,0xaa);
	WriteFlash(0x2aaa,0x55);
	WriteFlash(0x5555,0x90);
	
	*MID = ReadFlash(0x0);
	*DID = ReadFlash(0x1);
	
	WriteFlash(0x5555,0xaa);
	WriteFlash(0x2aaa,0x55);
	WriteFlash(0x5555,0xf0);
}

⌨️ 快捷键说明

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