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

📄 erase_copy.c

📁 uboot底层驱动
💻 C
字号:
#include "my_printf.h"
#include "erase_copy.h"
extern int count;

ER NorFlash_idlejud(U32 address)
{
	U16 temp = 0;
	
	*(RP16)address = 0x70;
	temp = *(RP16)address;
	while( (temp & 0x80) != 0x80 )
	{
		temp = *(RP16)address ;
	}
	
	*(RP16)address = 0xff;
	
	return YES;
}
	

ER NorFlash_unlock( U32 address)
{
	
	
	*(RP16)address = 0x60;
	*(RP16)address = 0xd0;
	
	
	NorFlash_idlejud(address);
	
	return YES;
}

ER NorFlash_clearSR(void)
//ER NorFlash_clearSR(U32 address)
{
	*(RP16)(0x20000000) = 0x50;
	return YES;
}

ER NorFlash_bolckerase(U32 blockadd)
{
	U16 temp;
	
	*(RP16)blockadd = 0x20;
	*(RP16)blockadd = 0xd0;
	
	temp = NorFlash_idlejud(blockadd);
	
	temp = NorFlash_clearSR();			       
	return YES;
}


ER NorFlash_read( U32 address)
{
	U16 i;
	
	*(RP16)address = 0xff;	
	i = *(RP16)address;
	
	NorFlash_idlejud(address);
	
	return i;
}


 ER NorFlash_write( U32 address, U16 data )
{
	U16 temp;
		
	*(RP16)address = 0x40;
	*(RP16)address = data;
	
	NorFlash_idlejud(address);
	
	temp = NorFlash_read(address);
	
	if(temp != data) 
	{
		my_printf("the error addr is 0x%x\n\r", address);
		my_printf("write error!original data is 0x%x and data read out is 0x%x!!\n\r",(U16)data,(U16)temp);
		
		return NO;
	}
	
	return YES;
}



ER check(U32 head1, U32 head2, U32 num)
{
	RP8 p1, p2;
	char data;
	
	p1 = (RP8)head1;
	p2 = (RP8)head2;
	
	
	while(num-->0)
	{
		data = *((RP8)p1++);
		
		if(data!= *((RP8)p2++))
		{
			my_printf("the copyed data is not the orignal one!!\n\r");
			return NO;
		}
	}
	
	return YES;
}

void flash_erase(int NorHead)
{  	
	  int i;
	  int EraseBlockCount=(count+ERASEBLOCKSIZE)/ERASEBLOCKSIZE;
   	for(i = 0; i<EraseBlockCount; i++) 
   	{	NorFlash_unlock(NorHead + i*ERASEBLOCKSIZE );
		NorFlash_bolckerase(NorHead + i*ERASEBLOCKSIZE );
		//my_printf("i = 
	}
 	my_printf("Erase operation OK!!\n\r");
 	my_printf("Be ready to load code image!!\n\r");
}


  void copy(int DataHead, int NorHead)
  {
    	int		SIZE1 = (count/WordLen) ; /* μúò?′?é???μ????t′óD?£?μ¥???aflash×?3¤*/
	   	int i;
	   	int temp;
	    for(i=0;i<SIZE1;i++)
	    {   temp = *(POINTER)(DataHead + i*WordLen);
	    	NorFlash_write( (NorHead + i*WordLen), temp );    	
	    }    
	    if( (check(DataHead, NorHead, SIZE1*WordLen)) != YES)
	    	my_printf("bootloader burning error!\n");
	    else my_printf("Everything is OK now!!\n");
	 }
	

⌨️ 快捷键说明

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