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

📄 flashamd.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
字号:
/*
===============================================================================
            TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION           
                                                                             
   Property of Texas Instruments 
   For  Unrestricted  Internal  Use  Only 
   Unauthorized reproduction and/or distribution is strictly prohibited.  
   This product is protected under copyright law and trade secret law 
   as an unpublished work.  
   Created 1999, (C) Copyright 1999 Texas Instruments.  All rights reserved.
   Filename       	: Flash.c

   Description    	: functions to handle flash

   Project        	: arm925st 

   Author         	: Daniel BLANC

===============================================================================
*/

#include "mem.h"
#include "mif.h"
#include "flashamd.h"
#include "result.h"

//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdReset
//               
// DESCRIPTION : Set the read array command in the flash 
//               
// SYNOPSYS    : void FLASH_FlashAmdReset(UWORD32 read_address)
//               
// PARAMETERS  : read_address           An address in the flash 
//               
//               
// RETURN VALUE: None
//               
// LIMITATIONS : Mif block must be initialized
//---------------------------------------------------------------------
void FLASH_FlashAmdReset(UWORD32 write_address)
{

 /* Program command */
 WriteFlash(write_address,FAMD_RESET);
}


//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdReadId
//              
// DESCRIPTION : Get the Manufacturer id or the device id
//              
// SYNOPSYS    : UWORD16 FlashAmdPairReadID(UWORD32 Address, BOOL IdRequest)
//
//              
// PARAMETERS  :    Address,         Base Address of the flash package
//                  IdRequest        MANUFACTERER_ID_REQ or DEV16MBITBOTTOM_ID_REQ
//              
// RETURN VALUE:    UWORD16          contains the status of the flash package
//                                   //
// LIMITATIONS :    Setup the MIF block before access to flash 
//              
//              
//---------------------------------------------------------------------
UWORD16 FLASH_FlashAmdReadId(UWORD32 Address, BOOL IdRequest)
{
 UWORD16 Id;

 WriteFlash((Address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((Address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash((Address|FAMD_ADD_COMMAND),FAMD_AUTOSELECT);

 if (IdRequest==MANUFACTERER_ID_REQ)
   {
 // Read the value of the manufacturer id 
   Id=ReadFlash((Address|FAMD_MANUFID));
   }
 else
   {
 // Read the value of the device id 
   Id=ReadFlash((Address|FAMD_DEVID));
   } 
 
 //Go out of Autoselect mode
 FLASH_FlashAmdReset(Address);
 return Id;
}


BOOL FLASH_FlashAmdWaitProgramed(UWORD32 write_address, UWORD16 write_value)
{
UWORD16 status;
BOOL ok = False;
BOOL error = False;
// extract only Bit 7
write_value &= 0x80; 

while ((!ok) && (!error))
	{
	// read flash status 
	status=ReadFlash(write_address);
	// check DQ7
	if ((status & 0x80) == write_value)
		{
		ok = True ;
		}
	else
		{
		// check DQ5
		if ((status & 0x20) == 0x20)
			{
			status=ReadFlash(write_address);
			if ((status & 0x80) == write_value)
				ok = True ;
			else
				error = True ;
			}
		}
	}
return(ok);
}


//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdProgram
//               
// DESCRIPTION : Programme a word in the flash pair
//               
// SYNOPSYS    : void FLASH_FlashAmdProgramPair16(UWORD32 write_address, UWORD32 write_value)
//               
// PARAMETERS  : write_address            Address where the user wants to write
//               write_value              Value the user wants to store
//               
//               
// RETURN VALUE: IS_OK or NOT_OK
//               
// LIMITATIONS : MIF block must be initialized before use of that function
//               
//               
//---------------------------------------------------------------------
BOOL FLASH_FlashAmdProgram(UWORD32 base_address, UWORD32 write_address, UWORD16 write_value)
{

 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash((base_address|FAMD_ADD_COMMAND),FAMD_PROGRAM);
 WriteFlash(write_address,write_value);
 // wait for flash ready
 if (FLASH_FlashAmdWaitProgramed(write_address,write_value))
 	//return(IS_OK);
        return True;
 else
 	//return(NOT_OK);
        return False;
}

//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdUnlockBypass
//               
// DESCRIPTION : Send Unlock Bypass sequence to AMD Flah
//               
// PARAMETERS  : flash_address  
//               
//               
// RETURN VALUE: none
//               
// LIMITATIONS : MIF block must be initialized before use of that function
//               
//---------------------------------------------------------------------
void FLASH_FlashAmdUnlockBypass(UWORD32 flash_address)
{
WriteFlash((flash_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
WriteFlash((flash_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
WriteFlash((flash_address|FAMD_ADD_COMMAND),FAMD_UNLOCK_BYPASS);
}

//---------------------------------------------------------------------
// NAME        : FlashAmdBypassProgram
//               
// DESCRIPTION : Programm a word in the flash pair
//               
// PARAMETERS  : write_address            Address where the user wants to write
//               write_value              Value the user wants to store
//               
//               
// RETURN VALUE: IS_OK or NOT_OK
//               
// LIMITATIONS : call FLASH_FlashAmdUnlockBypass finction before using the programming mode
//---------------------------------------------------------------------
BOOL FLASH_FlashAmdUnlockBypassProgram(UWORD32 write_address, UWORD16 write_value)
{
 WriteFlash(write_address,FAMD_BYPASS_PROGRAM);
 WriteFlash(write_address,write_value);
 return(FLASH_FlashAmdWaitProgramed(write_address,write_value));
}

//---------------------------------------------------------------------
// NAME        : FlashAmdBypassReset
//               
// DESCRIPTION : send flash bypass reset sequence
//               
// PARAMETERS  : write_address            Address where the user wants to write
//               
// RETURN VALUE: IS_OK or NOT_OK
//               
// LIMITATIONS : MIF block must be initialized before use of that function
//               
//               
//---------------------------------------------------------------------
void FLASH_FlashAmdUnlockBypassReset(UWORD32 write_address)
{

 WriteFlash(write_address,FAMD_STOP_BYPASS_PROGRAM1);
 WriteFlash(write_address,FAMD_STOP_BYPASS_PROGRAM2);
}


//---------------------------------------------------------------------
// NAME        : FlashAmdEraseBlock
//               
// DESCRIPTION : Erase the block memory which contains the address specified
//               
// SYNOPSYS    : BOOL FlashAmdEraseBlock(UWORD32 erase_address)
//               
// PARAMETERS  : erase_address            specify the block to erase
//               
//               
// RETURN VALUE: YES if succeed NO if fail
//               
// LIMITATIONS : MIf block must be initialized
//               
//               
//---------------------------------------------------------------------
BOOL FLASH_FlashAmdEraseSector(UWORD32 base_address ,UWORD32 erase_address)
{
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash((base_address|FAMD_ADD_COMMAND),FAMD_ERASE_SECTOR1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash(erase_address,FAMD_ERASE_SECTOR2);

 if (FLASH_FlashAmdWaitProgramed(base_address,0xFFFF))
 	//return(IS_OK);
        return True;
 else
 	//return(NOT_OK);
	return False;
}
//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdEraseChip
//               
// DESCRIPTION : Erase the block memory which contains the address specified
//               
// SYNOPSYS    : BOOL FlashAmdEraseBlock(UWORD32 erase_address)
//               
// PARAMETERS  : erase_address            specify the block to erase
//               
//               
// RETURN VALUE: YES if succeed NO if fail
//               
// LIMITATIONS : MIf block must be initialized
//               
//               
//---------------------------------------------------------------------
BOOL FLASH_FlashAmdEraseChip(UWORD32 base_address)
{
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash((base_address|FAMD_ADD_COMMAND),FAMD_ERASE_SECTOR1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_ERASE_CHIP);

 if (FLASH_FlashAmdWaitProgramed(base_address,0xFFFF))
 	//return(IS_OK);
	return True;
 else
 	//return(NOT_OK);
	return False;

}

//---------------------------------------------------------------------
// NAME        : FlashAmdEraseBlock
//               
// DESCRIPTION : Erase the block memory which contains the address specified
//               
// SYNOPSYS    : BOOL FlashAmdEraseBlock(UWORD32 erase_address)
//               
// PARAMETERS  : erase_address            specify the block to erase
//               
//               
// RETURN VALUE: YES if succeed NO if fail
//               
// LIMITATIONS : MIf block must be initialized
//               
//               
//---------------------------------------------------------------------
BOOL FLASH_FlashChipEraseSector(UWORD32 base_address ,UWORD32 erase_address)
{
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash((base_address|FAMD_ADD_COMMAND),FAMD_ERASE_SECTOR1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
 WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
 WriteFlash(erase_address,FAMD_ERASE_SECTOR2);

 if (FLASH_FlashAmdWaitProgramed(base_address,0xFFFF))
 	//return(IS_OK);
	return True;
 else
 	//return(NOT_OK);
	return False;
}


//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdReadData
//               
// DESCRIPTION : Read a 16 bits word in the flash pair
//               
// SYNOPSYS    : UWORD32 FLASH_FlashAmdReadData(UWORD32 read_address)
//               
// PARAMETERS  : read_address           place where to read the data in 
//               
//               
// RETURN VALUE: UWORD16                Value read
//               
// LIMITATIONS : Mif block must be initialized
//---------------------------------------------------------------------
UWORD16 FLASH_FlashAmdReadData(UWORD32 read_address)
{

 /* Program command */
 return(ReadFlash(read_address));

}


//---------------------------------------------------------------------
// NAME        : FLASH_FlashAmdBurstModeEnable
//               
// DESCRIPTION : Enable Burst Mode 
//               
// SYNOPSYS    : void FLASH_FlashAmdBurstModeEnable(UWORD32 base_address)
//               
// PARAMETERS  : base_address : Flash base adress
//               
//               
// RETURN VALUE: None
//               
// LIMITATIONS : MIf block must be initialized
//               
//               
//---------------------------------------------------------------------
void FLASH_FlashAmdBurstModeEnable(UWORD32 base_address)
{
	WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
	WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
	WriteFlash((base_address|FAMD_ADD_BURST),FAMD_DATA_BURST);
	WriteFlash((base_address),FAMD_DATA_BURST_ENABLE);
}


//---------------------------------------------------------------------
// NAME        : FlashAmdBurstModeDisbale
//               
// DESCRIPTION : Disable Burst Mode 
//               
// SYNOPSYS    : void FLASH_FlashAmdBurstModeDisable(UWORD32 base_address)
//               
// PARAMETERS  : base_address : Flash base adress
//               
//               
// RETURN VALUE: None
//               
// LIMITATIONS : MIf block must be initialized
//               
//               
//---------------------------------------------------------------------
void FLASH_FlashAmdBurstModeDisable(UWORD32 base_address)
{
	WriteFlash((base_address|FAMD_ADD_UNLOCK1),FAMD_DATA_UNLOCK1);
	WriteFlash((base_address|FAMD_ADD_UNLOCK2),FAMD_DATA_UNLOCK2);
	WriteFlash((base_address|FAMD_ADD_BURST),FAMD_DATA_BURST);
	WriteFlash((base_address),FAMD_DATA_BURST_DISABLE);
}


BOOL FLASH_FlashAmdDownloadProgram(UWORD32 FlashBaseAddress,UWORD16 * PrgData, UWORD32 PrgLengthInByte)
{
BOOL ok = True;

// set unlock bypass mode
FLASH_FlashAmdUnlockBypass(FlashBaseAddress);
while ((PrgLengthInByte>0) && (ok))
	{
	FLASH_FlashAmdUnlockBypassProgram(FlashBaseAddress, (*PrgData));
	PrgData++;
	// increment address
	FlashBaseAddress +=2;
	// decrement size
	PrgLengthInByte -=2;
	}

// reset unlock bypass mode
FLASH_FlashAmdUnlockBypassReset(FlashBaseAddress);

return(ok);
}

⌨️ 快捷键说明

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