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

📄 flashintel.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
📖 第 1 页 / 共 2 页
字号:

//---------------------------------------------------------------------
// NAME        : FLASH_SetFlashProgrammVoltage
//               
// DESCRIPTION : Set the voltage of Vpp on the flash
//               
// SYNOPSYS    : void FLASH_SetFlashProgrammVoltage(BOOL VoltageLevel)
//               
// PARAMETERS  : VoltageLevel                 PROGRAM_LEVEL or PROTECT_LEVEL
//               
//               
// RETURN VALUE: None
//               
// LIMITATIONS : None
//---------------------------------------------------------------------
void FLASH_SetFlashProgrammVoltage(BOOL VoltageLevel)
{
// Set the voltage of the pin Vpp of the flash
 if (VoltageLevel==PROGRAM_LEVEL)
   return;
 else
   return;
}

//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelProgramPair
//               
// DESCRIPTION : Programme a word in the flash pair
//               
// SYNOPSYS    : void FLASH_FlashIntelProgramPair(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
// 				  Authorize the flash write must be done in EMIF Interface 
//					  by function MIF_MifSetWriteProtect(WRITE_AUTHORIZED);              
//---------------------------------------------------------------------
BOOL FLASH_FlashIntelProgramPair(UWORD32 write_address, UWORD32 write_value)
{
UWORD32 Status,i;
#define MAX_WAIT_READY                 100 

// send program command
WriteFlashPairRegister(write_address,FPAIR_PROGRAMDATA,write_address,write_value);

// wait for both flash ready
i=0;
do
   {
   // Read the value of the status register
   Status=ReadFlashPair(write_address);
   i++;
   }
while ((TestBit(Status,FPAIR_WSMS_READY_MASK)==FALSE ) AND (i<MAX_WAIT_READY));
// ckeck status
if (Status != FPAIR_WSMS_READY_MASK)
   return((BOOL)NOT_OK);
else
   return((BOOL)IS_OK);

}

//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelProgram
//               
// DESCRIPTION : Programme a word in the flash pair
//               
// SYNOPSYS    : void FLASH_FlashIntelProgramPair16(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 Interface must be initialized
// 				  Authorize the flash write must be done in EMIF Interface 
//					  by function MIF_MifSetWriteProtect(WRITE_AUTHORIZED);              
//---------------------------------------------------------------------
BOOL FLASH_FlashIntelProgram(UWORD32 write_address, UWORD16 write_value)
{
UWORD16 StatusDefinitionRegister;

// send program command to flash
WriteFlashRegister(write_address,FLASH_PROGRAMDATA,write_address,write_value);
do
   {
	// after sending program command sequence, the device read provides status register 
   // Read the value of the status register
   StatusDefinitionRegister=ReadFlash(write_address);
   }
//wait until Ready bit (bit 7) in status register
while (TestBit(StatusDefinitionRegister,FLASH_WSMS_READY_MASK)==FALSE ) ;

// check status 
if (StatusDefinitionRegister != FLASH_WSMS_READY_MASK)
   return((BOOL)NOT_OK);
else
   return((BOOL)IS_OK);
}

//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelEraseBlockPair
//               
// DESCRIPTION : Erase the block memory which contains the address specified
//               
// SYNOPSYS    : BOOL FLASH_FlashIntelEraseBlockPair(UWORD32 erase_address)
//               
// PARAMETERS  : erase_address            specify the block to erase
//               
// RETURN VALUE: YES if succeed NO if fail
//               
// LIMITATIONS : Mif Interface must be initialized
// 				  Authorize the flash write must be done in EMIF Interface 
//					  by function MIF_MifSetWriteProtect(WRITE_AUTHORIZED);              
//---------------------------------------------------------------------
BOOL FLASH_FlashIntelEraseBlockPair(UWORD32 erase_address)
{
UWORD32 Status;

// send erase command sequence
WriteFlashPairRegister(erase_address,FPAIR_ERASEBLOCK,erase_address,FPAIR_ERASEBLOCKCONFIRM);

// Read Status Register command 
do
	{
	// after sending erase command sequence, the device read provides status register 
	// Read Status register 
	Status=ReadFlashPair(erase_address);
	}
while( TestBit(Status,FPAIR_WSMS_READY_MASK)==FALSE );
if (Status != FPAIR_WSMS_READY_MASK)
   return((BOOL)NOT_OK);
else
   return((BOOL)IS_OK);

}

//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelEraseBlock
//               
// DESCRIPTION : Erase the block memory which contains the address specified
//               
// SYNOPSYS    : BOOL FLASH_FlashIntelEraseBlock(UWORD32 erase_address)
//               
// PARAMETERS  : erase_address  specify the block to erase
//               
// RETURN VALUE: IS_OK if succeed NOT_OK if fail
//               
// LIMITATIONS : MIf block must be initialized
// 				  Authorize the flash write must be done in EMIF Interface 
//					  by function MIF_MifSetWriteProtect(WRITE_AUTHORIZED);              
//---------------------------------------------------------------------
BOOL FLASH_FlashIntelEraseBlock(UWORD32 erase_address)
{
UWORD16 Status;
// send erase command to flash
WriteFlashRegister(erase_address,FLASH_ERASEBLOCK,erase_address,FLASH_ERASEBLOCKCONFIRM);
// wait for device ready by polling status register
do
   {
   // Read Status register 
   Status=ReadFlash(erase_address);
   }
// Wait until SR.7 is set to 1 (ready)
while( TestBit(Status,FLASH_WSMS_READY_MASK)==FALSE );
// check status 
if (Status != FLASH_WSMS_READY_MASK)
   return((BOOL)NOT_OK);
else
   return((BOOL)IS_OK);
}

BOOL FLASH_IntelStrataFlashEraseDevice(UWORD32 flash_base_address)
{
#define INTEL_STRATA_NB_SECTOR	128
#define SECTOR_SIZE_128Kb	0x20000
UWORD32 i;
BOOL ok;
ok=True;
//Erase the whole device 
for (i=0; i < INTEL_STRATA_NB_SECTOR ; i++)
	{
   if (!FLASH_FlashIntelEraseBlock(flash_base_address))
      {
		ok = False;
		break;
		}
	flash_base_address += SECTOR_SIZE_128Kb;
	}
return (ok);
}



BOOL FLASH_IntelBurstFlashEraseDevice(UWORD32 flash_base_address)
{
#define INTEL_BURST_NB_SECTOR_64Kb	31
#define INTEL_BURST_NB_SECTOR_8Kb	8
#define SECTOR_SIZE_8Kb			0x2000
#define SECTOR_SIZE_64Kb		0x10000
UWORD32 i;
BOOL ok;
ok=True;
// for 16 Mbit top memory map 
// - 31 sectors of 32Kwords (64 Kbytes) at the beginning of device
// -  8 sectors of 4Kwords (8 Kbytes) then

//Erase the whole device 
for (i=0; i < INTEL_BURST_NB_SECTOR_64Kb ; i++)
	{
   if (!FLASH_FlashIntelEraseBlock(flash_base_address))
      {
		ok = False;
		break;
		}
	flash_base_address += SECTOR_SIZE_64Kb;
	}
if (ok)
	{
	for (i=0; i < INTEL_BURST_NB_SECTOR_8Kb ; i++)
		{
   	if (!FLASH_FlashIntelEraseBlock(flash_base_address))
      	{
			ok = False;
			break;
			}
		flash_base_address += SECTOR_SIZE_8Kb;
		}
	}
return (ok);
}

//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelReadDataPair
//               
// DESCRIPTION : Read a 32 bits word in the flash pair
//               
// SYNOPSYS    : UWORD32 FLASH_FlashIntelReadDataPair(UWORD32 read_address)
//               
// PARAMETERS  : read_address           place where to read the data in 
//               
//               
// RETURN VALUE: UWORD32                Value read
//               
// LIMITATIONS : Mif block must be initialized
//---------------------------------------------------------------------
UWORD32 FLASH_FlashIntelReadDataPair(UWORD32 read_address)
{
return(REG32(read_address));
}

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


//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelPairReadArray
//               
// DESCRIPTION : Set the read array command in the flash pair
//               
// SYNOPSYS    : void FLASH_FlashIntelPairReadArray(UWORD32 read_address)
//               
// PARAMETERS  : read_address           An address in the flash 
//               
//               
// RETURN VALUE: None
//               
// LIMITATIONS : Mif block must be initialized
//---------------------------------------------------------------------
void FLASH_FlashIntelPairReadArray(UWORD32 write_address)
{
// set device in read array mode
WriteFlashPair(write_address,FPAIR_READARRAYDATA);
}


//---------------------------------------------------------------------
// NAME        : FLASH_FlashIntelReadArray
//               
// DESCRIPTION : Set the read array command in the flash 
//               
// SYNOPSYS    : void FlashIntelPairRead(UWORD32 read_address)
//               
// PARAMETERS  : read_address           An address in the flash 
//               
//               
// RETURN VALUE: None
//               
// LIMITATIONS : Mif block must be initialized
//---------------------------------------------------------------------
void FLASH_FlashIntelReadArray(UWORD32 write_address)
{
// set device in read array mode
WriteFlash(write_address,FLASH_READARRAYDATA);
}


//---------------------------------------------------------
//NAME        : FLASH_FlashIntelDowloadProgram
//DESCRIPTION : Program flash with array of data
//PARAMETERS  : 
//             UWORD32 FlashBaseAddress : flash address
//					PrgData : pointer on data to be programmed
//					PrgLengthInByte : program size in bytes
//RETURN VALUE: True if Program ok
//LIMITATIONS : flash must be erased 
//---------------------------------------------------------

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

while ((PrgLengthInByte>0) && (ok))
	{
	ok &= FLASH_FlashIntelProgram(FlashBaseAddress, (*PrgData));
	PrgData++;
	// increment address
	FlashBaseAddress +=2;
	// decrement size
	PrgLengthInByte -=2;
	}
//Put the flash in read array mode
FLASH_FlashIntelReadArray(FlashBaseAddress);

return(ok);
}


⌨️ 快捷键说明

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