Пример #1
0
ERROR_CODE EraseBlock( int nBlock, unsigned long ulAddr )
{

	ERROR_CODE 	  ErrorCode   = NO_ERR;		//tells us if there was an error erasing flash
 	unsigned long ulSectStart = 0x0;		//stores the sector start offset
 	unsigned long ulSectEnd   = 0x0;		//stores the sector end offset(however we do not use it here)
	unsigned long ulFlashStartAddr;			//flash start address

	// get flash start address from absolute address
	// The ulAddr should ideally be pointing to the flash start
	// address. However we just verify it here again.
	ulFlashStartAddr = GetFlashStartAddress(ulAddr);

	// Get the sector start offset
	// we get the end offset too however we do not actually use it for Erase sector
	GetSectorStartEnd( &ulSectStart, &ulSectEnd, nBlock );

	// send the erase block command to the flash
	WriteFlash( (ulFlashStartAddr + 0x0AAA), 0xaa );
	WriteFlash( (ulFlashStartAddr + 0x0554), 0x55 );
	WriteFlash( (ulFlashStartAddr + 0x0AAA), 0x80 );
	WriteFlash( (ulFlashStartAddr + 0x0AAA), 0xaa );
	WriteFlash( (ulFlashStartAddr + 0x0554), 0x55 );

	// the last write has to be at an address in the block
	WriteFlash( (ulFlashStartAddr + ulSectStart), 0x30 );

	// poll until the command has completed
	ErrorCode = PollToggleBit(ulFlashStartAddr + ulSectStart);

 	// block erase should be complete
	return ErrorCode;
}
Пример #2
0
u32 adi_pdd_Write(	ADI_DEV_PDD_HANDLE 	PDDHandle,
 			  	 	ADI_DEV_BUFFER_TYPE BufferType,
 			  		ADI_DEV_BUFFER		*pBuffer)
{
	ADI_DEV_1D_BUFFER *pBuff1D;			// buffer pointer
	short   		  *psValue;			// stores the value to be written to flash
	unsigned long     *pulAbsoluteAddr;	// the absolute address to write
	unsigned long 	  ulFlashStartAddr;	// flash start address
	u32				  Result;			// error code returned

	// cast our buffer to a 1D buffer
	pBuff1D = (ADI_DEV_1D_BUFFER*)pBuffer;

	// cast our data buffer
	psValue = (short *)pBuff1D->Data;

	// cast our offset
	pulAbsoluteAddr = (unsigned long *)pBuff1D->pAdditionalInfo;

	// get flash start address from absolute address
	ulFlashStartAddr = GetFlashStartAddress(*pulAbsoluteAddr);

	// unlock flash
	WriteFlash( ulFlashStartAddr + 0x0AAA, 0xaa );
	WriteFlash( ulFlashStartAddr + 0x0554, 0x55 );
	WriteFlash( ulFlashStartAddr + 0x0AAA, 0xa0 );

	// program our actual value now
	Result = WriteFlash( *pulAbsoluteAddr, *psValue );

	// make sure the write was successful
	Result = PollToggleBit(*pulAbsoluteAddr);

	return(Result);
}
Пример #3
0
ERROR_CODE EraseFlash(unsigned long ulAddr)
{
	ERROR_CODE ErrorCode = NO_ERR;	// tells us if there was an error erasing flash
	int nBlock = 0;					// index for each block to erase
	unsigned long ulFlashStartAddr;	// flash start address

	// get flash start address from absolute address
	// The ulAddr should ideally be pointing to the flash start
	// address. However we just verify it here again.
	ulFlashStartAddr = GetFlashStartAddress(ulAddr);

	// erase contents of Flash
	WriteFlash( ulFlashStartAddr + 0x0AAA, 0xaa );
	WriteFlash( ulFlashStartAddr + 0x0554, 0x55 );
	WriteFlash( ulFlashStartAddr + 0x0AAA, 0x80 );
	WriteFlash( ulFlashStartAddr + 0x0AAA, 0xaa );
	WriteFlash( ulFlashStartAddr + 0x0554, 0x55 );
	WriteFlash( ulFlashStartAddr + 0x0AAA, 0x10 );

	// poll until the command has completed
	ErrorCode = PollToggleBit(ulFlashStartAddr + 0x0000);


	// erase should be complete
	return ErrorCode;
}
Пример #4
0
//涉及到的地址是Flash的绝对地址 BYTE 不支持跨扇区操作
int DeleteDataInSector(U32 Addr, U32 size)
{
	int i,index;
	U32 a;
	U16 *buf;
	
	index = GetFlashSectorIndex(Addr);
	if (index < 0) return -1;
	a = GetFlashStartAddress(index);
	if ((size + Addr) > (a + FlashSectorSizes[index]))
		size = a + FlashSectorSizes[index] - Addr;
	//复制数据
	buf = (U16*)malloc(FlashSectorSizes[index]);
	for(i = 0; i < FlashSectorSizes[index]/2; i++)
		buf[i] = ((U16*)a)[i];

	//移除数据
	for(i=Addr-a;i<FlashSectorSizes[index]-size;i++)
		((U8*)buf)[i]=((U8*)buf)[i+size];
	for(i=FlashSectorSizes[index]-size;i<FlashSectorSizes[index];i++)
		((U8*)buf)[i]=0xFF;
	//回写数据
	i=FlashSaveBuffer(a, buf, FlashSectorSizes[index]);
	free(buf);
	return i;
}
Пример #5
0
ERROR_CODE ResetFlash(unsigned long ulAddr)
{

	unsigned long ulFlashStartAddr;		//flash start address

	// get flash start address from absolute address
	// The ulAddr should ideally be pointing to the flash start
	// address. However we just verify it here again.
	ulFlashStartAddr = GetFlashStartAddress(ulAddr);

	// send the reset command to the flash
	WriteFlash( ulFlashStartAddr + 0x0554, 0xf0 );

	// reset should be complete
	return NO_ERR;
}
Пример #6
0
ERROR_CODE GetCodes(int *pnManCode, int *pnDevCode, unsigned long ulAddr)
{
    unsigned long ulFlashStartAddr;		//flash start address

	// get flash start address from absolute address
	// The ulAddr should ideally be pointing to the flash start
	// address. However we just verify it here again.
	ulFlashStartAddr = GetFlashStartAddress(ulAddr);

	// send the auto select command to the flash
	WriteFlash( ulFlashStartAddr + 0x0aaa, 0xaa );
	WriteFlash( ulFlashStartAddr + 0x0554, 0x55 );
	WriteFlash( ulFlashStartAddr + 0x0aaa, 0x90 );

	// now we can read the codes
	ReadFlash( ulFlashStartAddr + 0x0000,(unsigned short *)pnManCode );
	*pnManCode &= 0x00FF;

	ReadFlash( ulFlashStartAddr + 0x0002, (unsigned short *)pnDevCode );
	*pnDevCode &= 0x00FF;

	if( *pnDevCode == 0x5B )
	{
	    gNumSectors = 19;
	  	pFlashDesc = "S29AL008D(512 x 16)";
	}
	else
	{
	    gNumSectors = 11;
		pFlashDesc = "S29AL004D(256 x 16)";
	}

	// we need to issue another command to get the part out
	// of auto select mode so issue a reset which just puts
	// the device back in read mode
	ResetFlash(ulAddr);

	// ok
	return NO_ERR;
}
Пример #7
0
//涉及到的地址是Flash的绝对地址 BYTE 不支持跨扇区操作!!!
//奇数地址, 则向后移写入(避免删除SECTOR 追加方式)
int FlashSaveBuffer(U32 Addr, void *Buffer, U32 Size)
{
	U32 i,SectorStartAddr,StartAddr,EndAddr,SecSize,Erased,ThisSize;
	U16 *TempBuffer;
	
	TempBuffer=(U16 *)malloc(STD_SECTOR_SIZE); 
	
	//get flash sector index and size
	i=GetFlashSectorIndex(Addr);
	SecSize=FlashSectorSizes[i];
	//get flash start address
	SectorStartAddr=GetFlashStartAddress(i);

	//read from flash to buffer
	for(i=0;i<SecSize/2;i++)
	{
		TempBuffer[i]=((U16*)SectorStartAddr)[i];
		//if(i%150==0) printf("%d %x\n", i, SectorStartAddr+i*2);
	}			
	//Determine the bound of tempbuffer and buffer		
	if(SectorStartAddr < Addr) 
	    StartAddr=Addr-SectorStartAddr;
	else 
	    StartAddr=0;
		
	EndAddr=StartAddr + Size;		
	if(EndAddr > SecSize) EndAddr = SecSize;
	ThisSize=EndAddr-StartAddr;
		
	//check diff of buffer
	if(memcmp((U8*)TempBuffer+StartAddr, Buffer, ThisSize))
	{
		//check if erase this section
		Erased=0;
		for(i=StartAddr;i<EndAddr;i+=2)
		{
			if(!(TempBuffer[i/2]==0xFFFF))
			{
			      if (!FlashSectorErase(SectorStartAddr)){
			           free(TempBuffer);
				    return -1;
				}
				Erased=1;
				break;
			}
		}
		memcpy((U8*)TempBuffer+StartAddr, Buffer, ThisSize);
		if(Erased)  //if erased old data, write back all data of the section
		{ 
			i=0; 
			EndAddr=SecSize;
		}
		else
		{ 
			i=(StartAddr/2)*2; //adjust odd address to previous
			EndAddr=((EndAddr+1)/2)*2; 			
		}
		
		while(i < EndAddr)
		{
			if (!FlashWriteWord(SectorStartAddr + i, TempBuffer[i/2]))
			{
				free(TempBuffer);
				return -2;
			}
			i+=2;
		}
	}
	
	free(TempBuffer);
	return 1;
}
Пример #8
0
int FlashSectorEraseByIndex(int i)
{	
    return FlashSectorErase(GetFlashStartAddress(i));
}
ERROR_CODE GetCodes(int *pnManCode, int *pnDevCode, unsigned long ulAddr)
{

	unsigned long ulFlashStartAddr;		//flash start address

	// get flash start address from absolute address
	// The ulAddr should ideally be pointing to the flash start
	// address. However we just verify it here again.
	ulFlashStartAddr = GetFlashStartAddress(ulAddr);

 	// send the auto select command to the flash
//	WriteFlash( ulFlashStartAddr + 0x0AAA, 0xaa );
//	WriteFlash( ulFlashStartAddr + 0x0554, 0x55 );
//	WriteFlash( ulFlashStartAddr + 0x0AAA, 0x90 );

	WriteFlash( ulFlashStartAddr + 2*0x0555, 0xaa );
	WriteFlash( ulFlashStartAddr + 2*0x02aa, 0x55 );
	WriteFlash( ulFlashStartAddr + 2*0x0555, 0x90 );

 	// now we can read the codes
//	ReadFlash( ulFlashStartAddr + 0x0402, (unsigned short *)pnManCode );
	ReadFlash( ulFlashStartAddr + 2*0x0000, (unsigned short *)pnManCode );
	*pnManCode &= 0x00FF;

//	ReadFlash( ulFlashStartAddr + 0x0400, (unsigned short *)pnDevCode );
	ReadFlash( ulFlashStartAddr + 2*0x0001, (unsigned short *)pnDevCode );
	*pnDevCode &= 0xFFFF;

//	ReadFlash( 0x1ffffffc, (unsigned short *)pnDevCode );
//	*pnDevCode &= 0xFFFF;

	// we need to issue another command to get the part out
	// of auto select mode so issue a reset which just puts
	// the device back in read mode
	ResetFlash(ulAddr);
	ResetFlash(ulAddr);

	return NO_ERR;

	WriteFlash( ulFlashStartAddr + 2*0x0055, 0x98 );
	unsigned long int a=0, b=0, c=0, d=0;
//	ReadFlash( ulFlashStartAddr + 2*0x10, (unsigned short *) &a );
//	ReadFlash( ulFlashStartAddr + 2*0x11, (unsigned short *) &b );
//	ReadFlash( ulFlashStartAddr + 2*0x12, (unsigned short *) &c );
//	ReadFlash( ulFlashStartAddr + 2*0x13, (unsigned short *) &d );
//	ReadFlash( ulFlashStartAddr + 2*0x40, (unsigned short *) &a );
//	ReadFlash( ulFlashStartAddr + 2*0x41, (unsigned short *) &b );
//	ReadFlash( ulFlashStartAddr + 2*0x42, (unsigned short *) &c );
//	ReadFlash( ulFlashStartAddr + 2*0x43, (unsigned short *) &d );
//	ReadFlash( ulFlashStartAddr + 2*0x27, (unsigned short *) &a );
//	ReadFlash( ulFlashStartAddr + 2*0x28, (unsigned short *) &b );
//	ReadFlash( ulFlashStartAddr + 2*0x29, (unsigned short *) &c );
//	ReadFlash( ulFlashStartAddr + 2*0x4e, (unsigned short *) &d );
//	ReadFlash( ulFlashStartAddr + 2*0x61, (unsigned short *) &a );
//	ReadFlash( ulFlashStartAddr + 2*0x62, (unsigned short *) &b );
//	ReadFlash( ulFlashStartAddr + 2*0x63, (unsigned short *) &c );
//	ReadFlash( ulFlashStartAddr + 2*0x64, (unsigned short *) &d );
//	ReadFlash( ulFlashStartAddr + 2*0x2d, (unsigned short *) &a );
//	ReadFlash( ulFlashStartAddr + 2*0x2e, (unsigned short *) &b );
//	ReadFlash( ulFlashStartAddr + 2*0x2f, (unsigned short *) &c );
//	ReadFlash( ulFlashStartAddr + 2*0x30, (unsigned short *) &d );
	ReadFlash( ulFlashStartAddr + 2*0x31, (unsigned short *) &a );
//	ReadFlash( ulFlashStartAddr + 2*0x32, (unsigned short *) &b );
//	ReadFlash( ulFlashStartAddr + 2*0x33, (unsigned short *) &c );
//	ReadFlash( ulFlashStartAddr + 2*0x34, (unsigned short *) &d );
	a &= 0xFFFF; b &= 0xFFFF; c &= 0xFFFF; d &= 0xFFFF;
//	a &= 0xFF; b &= 0xFF; c &= 0xFF; d &= 0xFF;
//	*pnDevCode = a<<24 + b<<26 + c<<8 + d;
//	*pnDevCode = a*16777216 + b*65536 + c*256 + d;

//	*pnDevCode = a*65536 + b;
//	*pnDevCode = c*65536 + d;
//	*pnDevCode = d;
	*pnDevCode = a;
//	*pnDevCode &= 0xFFFF;

/*	while(1) {
		WriteFlash( ulFlashStartAddr + 2*0x0055, 0x98 );
		ReadFlash( ulFlashStartAddr + 2*0x34, (unsigned short *) &a );
		a &= 0xFFFF;
		ResetFlash(ulAddr);
		WriteFlash( ulFlashStartAddr + 2*0x34, a );
		ResetFlash(ulAddr);
	}
*/

	ResetFlash(ulAddr);
	ResetFlash(ulAddr);
	
	// ok
	return NO_ERR;
}