📄 m29w320.c
字号:
///////////////////////////////////////////////////////////////
//
// m292w320.c
//
// Analog Devices, Inc. - 2004
//
//
// Change Log
//
// 1.00.0
// - initial release
//
// VisualDSP++ "Flash Programmer" flash driver for use with the
// ADSP-BF538 EZ-KIT Lite containing the STMicroelectronics M29W320DB
// flash device.
//
///////////////////////////////////////////////////////////////
/*===== I n c l u d e s =====*/
#include <services/services.h>
#include <drivers/adi_dev.h> // device manager includes
#include <stdlib.h>
#include <drivers\flash\util.h> // library struct includes
#include <drivers\flash\adi_m29w320.h> // flash-M29W320 includes
#include <drivers\flash\Errors.h> // error type includes
#define FLASH_SECTOR_65 65
#define FLASH_SECTOR_69 69
#define FLASH_START_ADDR 0x20000000
#define FLASH_SECTOR_OFFSET 0x003E0000
/*********************************************************************
*
* Function: main
*
*********************************************************************/
int TEST_FLASH(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 M29W320DB or M29W320EB
pCmdBuffer.SGetCodes.pManCode = (unsigned long *)&nManCode;
pCmdBuffer.SGetCodes.pDevCode = (unsigned long *)&nDevCode;
pCmdBuffer.SGetCodes.ulFlashStartAddr = FLASH_START_ADDR;
iResult = adi_dev_Control(DevHandleM29W320, CNTRL_GET_CODES, &pCmdBuffer );
// erase the second to last sector
// (the last sector on the BF537 and STAMP have the mac address)
if( nDevCode == 0x2257 )
{
pCmdBuffer.SEraseSect.nSectorNum = FLASH_SECTOR_69;
}
else
{
pCmdBuffer.SEraseSect.nSectorNum = FLASH_SECTOR_65;
}
pCmdBuffer.SEraseSect.ulFlashStartAddr = FLASH_START_ADDR;
// Erase the flash
iResult = adi_dev_Control(DevHandleM29W320, 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(DevHandleM29W320, 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(DevHandleM29W320, 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 + -