flashrom.c

来自「实验1 ARM汇编指令实验 实验2 C和汇编语言的混合编程实验 实验3 外部」· C语言 代码 · 共 60 行

C
60
字号
#include "flashrom.h"
#include "def.h"

/*** SST39VF160 检查是否为空 ***
 扇区的值若为oxFF则判断为空 ****/
int SST39VF160_CheckBlank(U32 addr,U32 WordSize) 
{
	U32 i,temp;
	for (i=addr;i<(addr+WordSize);i++)
	{
		temp=*((volatile U16 *)(i<<1));
		if(temp!=0xffff)
			return 0;
	}
	return 1;	
}

/****** SST39VF160 的检测 ******
 Check if the bit6 toggle ends */
int Waitfor_endofprg(void)
{
	volatile U16 flashStatus,old;
	old=*((volatile U16 *)0x0);

	while(1)
	{
		flashStatus=*((volatile U16 *)0x0);
		if( (old&0x40) == (flashStatus&0x40) )
			break;
		else
		old=flashStatus;
	}
	return 1;
}

/*** SST39VF160 的写入操作,是一个word(16bit)写入的 ***/
int SST39VF160_WordProg (U32 addr,U16 dat)
{
	Writeflash (0x5555,0xAA);
	Writeflash (0x2AAA,0x55);
	Writeflash (0x5555,0xA0);
	Writeflash (addr,dat);
	return(Waitfor_endofprg());
	
}

/*** SST39VF160 扇区擦除 ***/
void  SST39VF160_SectorErase(U32 SAaddr)
{
	Writeflash(0x5555,0xAA);
	Writeflash(0x2AAA,0x55);
	Writeflash(0x5555,0x80);
	Writeflash(0x5555,0xAA);
	Writeflash(0x2AAA,0x55);
	Writeflash(SAaddr,0x30);
    Waitfor_endofprg();
}


⌨️ 快捷键说明

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