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

📄 s29al004d_8d.c

📁 基于visual dsp++开发环境
💻 C
字号:
////////////////////////////////////////////////////////////////////////////
//
//  Program to test the S29AL004D internal flash on the BF538 EZ-KIT
//
//

//--------------------------------------------------------------------------//
// includes
//--------------------------------------------------------------------------//
#include <services/services.h>
#include <drivers/adi_dev.h>		// device manager includes
#include <stdlib.h>
#include <drivers\flash\adi_S29AL004D_8D.h>	// flash-S29AL004D/8D includes
#include <drivers\flash\util.h> 			// library struct includes
#include <drivers\flash\Errors.h>			// error type includes

//--------------------------------------------------------------------------//
// Common defines and variables
//--------------------------------------------------------------------------//
#define FLASH_SECTOR_18				18
#define FLASH_SECTOR_10				10

#define FLASH_START_ADDR 			0x20000000
#define FLASH_SECTOR_OFFSET			0x00070000



//--------------------------------------------------------------------------//
// Function:	TEST_FLASH_INTERNAL(void)
//
// Parameters:	None
//
// Return:		pass or fail
//
// Description:	Test the flash on the EZ-KIT
//--------------------------------------------------------------------------//
int TEST_FLASH_INTERNAL(void)
{
	int i;
	unsigned int iPassed = 0;
	unsigned int iResult;				// result
	ADI_DEV_1D_BUFFER FlashBuff1D;		// write buffer pointer	
	unsigned short sVal = 0;
	unsigned int nSector = 0;
	int nManCode = 0;
	int nDevCode = 0;
	
	COMMAND_STRUCT pCmdBuffer;
	
	// setup the external bus control
	*pEBIU_AMGCTL = 0xFF;
		

	// need to GetCodes because that is also where we figure
	// out the number of sectors because we don't know if the flash
	// is the S29AL004D_8D or S29AL004D_8D
	pCmdBuffer.SGetCodes.pManCode = (unsigned long *)&nManCode;
	pCmdBuffer.SGetCodes.pDevCode = (unsigned long *)&nDevCode;
	pCmdBuffer.SGetCodes.ulFlashStartAddr = FLASH_START_ADDR;

	iResult = adi_dev_Control(DevHandleS29AL004D_8D, CNTRL_GET_CODES, &pCmdBuffer );
		
	// erase a common sector whether it is the 4D or 8D
	if( nDevCode == 0x5B )
	{
		pCmdBuffer.SEraseSect.nSectorNum = FLASH_SECTOR_18;
	}
	else
	{
		pCmdBuffer.SEraseSect.nSectorNum = FLASH_SECTOR_10;
	}					
	
	pCmdBuffer.SEraseSect.ulFlashStartAddr = FLASH_START_ADDR;
	
	// Erase the flash
	iResult = adi_dev_Control(DevHandleS29AL004D_8D, CNTRL_ERASE_SECT, &pCmdBuffer );
	if(ADI_DEV_RESULT_SUCCESS == iResult)
	{
		// initialize our buffer
		FlashBuff1D.Data = &sVal;
	
		for( i = 0; i < 0xFFFF; i+=2 )
		{
			unsigned long ulOffset = (FLASH_SECTOR_OFFSET | FLASH_START_ADDR) + i ;
			FlashBuff1D.pAdditionalInfo = (void *)&ulOffset;
			FlashBuff1D.pNext = NULL;
			sVal = i;
						
			// write to the flash	
			iResult = adi_dev_Write(DevHandleS29AL004D_8D, ADI_DEV_1D, (ADI_DEV_BUFFER *)&FlashBuff1D);
			if(ADI_DEV_RESULT_SUCCESS == iResult)
			{
				iPassed = 1;
				sVal = 0;
								
				// Read back the values from sector 
				// set the parameters needed to do a read
							
				// read from the flash	
				iResult = adi_dev_Read(DevHandleS29AL004D_8D, ADI_DEV_1D, (ADI_DEV_BUFFER *)&FlashBuff1D);
				if(ADI_DEV_RESULT_SUCCESS == iResult)
				{
					if( i != sVal )
					{
						iPassed = 0;
						break;
					}
				}
			}//end adi_pdd_Write() -- if(ADI_DEV_RESULT_SUCCESS == iResult)
		}// end for( i = 0; i < 0xFFFF; i+=2 )
	}//end adi_pdd_Control() -- if(ADI_DEV_RESULT_SUCCESS == iResult)
		
		
	return iPassed;
}


/*********************************************************************
*
*	Function:	main
*
*********************************************************************/
#ifdef _STANDALONE_ // use this to run standalone tests
int main(void)
{
	int iStatus;
	
	asm("nop;");
	
	while(1)
	{
		iStatus = TEST_FLASH();
		if( 0 == iStatus )
		{
			asm("emuexcpt;");
		}
	}
	
}
#endif //#ifdef _STANDALONE_ // use this to run standalone tests

⌨️ 快捷键说明

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