?? main.c
字號:
SSectStartEnd.pEndOffset = &SectorInfo[i].ulEndOff;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_SECSTARTEND, (COMMAND_STRUCT *)&SSectStartEnd );
}
AFP_SectorInfo = (int*)&SectorInfo[0];
return(ErrorCode);
}
//----------- G e t F l a s h I n f o ( ) ----------//
//
// PURPOSE
// Get the manufacturer code and device code
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
ERROR_CODE GetFlashInfo()
{
ERROR_CODE ErrorCode = NO_ERR; //return error code
static GET_CODES_STRUCT SGetCodes; //structure for GetCodes
COMMAND_STRUCT CmdStruct;
//setup code so that flash programmer can just read memory instead of call GetCodes().
CmdStruct.SGetCodes.pManCode = (unsigned long *)&AFP_ManCode;
CmdStruct.SGetCodes.pDevCode = (unsigned long *)&AFP_DevCode;
CmdStruct.SGetCodes.ulFlashStartAddr = FLASH_START_ADDR;
AFP_Error = ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_CODES, &CmdStruct );
AFP_Error = ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_DESC, &CmdStruct );
AFP_Title = pEzKitTitle;
AFP_Description = CmdStruct.SGetDesc.pDesc;
AFP_DeviceCompany = CmdStruct.SGetDesc.pFlashCompany;
return(ErrorCode);
}
//----------- F i l l D a t a ( ) ----------//
//
// PURPOSE
// Fill flash device with a value.
//
// INPUTS
// unsigned long ulStart - address in flash to start the writes at
// long lCount - number of elements to write, in this case bytes
// long lStride - number of locations to skip between writes
// int *pnData - pointer to data buffer
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs during fill
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
ERROR_CODE FillData( unsigned long ulStart, long lCount, long lStride, int *pnData )
{
long i = 0; // loop counter
ERROR_CODE ErrorCode = NO_ERR; // tells whether we had an error while filling
bool bVerifyError = FALSE; // lets us know if there was a verify error
unsigned long ulStartAddr; // current address to fill
unsigned long ulSector = 0; // sector number to verify address
int nCompare = 0; // value that we use to verify flash
ADI_DEV_1D_BUFFER WriteBuff; // buffer pointer
ADI_DEV_1D_BUFFER ReadBuff; // buffer pointer
ulStartAddr = FLASH_START_ADDR + ulStart;
COMMAND_STRUCT CmdStruct; //structure for GetSectStartEnd
// verify writes if the user wants to
if( AFP_Verify == TRUE )
{
// fill the value
for (i = 0; ( ( i < lCount ) && ( ErrorCode == NO_ERR ) ); i++, ulStartAddr += ( lStride ) )
{
// check to see that the address is within a valid sector
CmdStruct.SGetSectNum.ulOffset = ulStartAddr;
CmdStruct.SGetSectNum.pSectorNum = &ulSector;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_SECTNUM, &CmdStruct );
if( NO_ERR == ErrorCode )
{
// unlock the flash, do the write, and wait for completion
WriteBuff.Data = (void *)&pnData[0];
WriteBuff.pAdditionalInfo = (void *)&ulStartAddr;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Write(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&WriteBuff);
ReadBuff.Data = (void *)&nCompare;
ReadBuff.pAdditionalInfo = (void *)&ulStartAddr ;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Read(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&ReadBuff);
//if( nCompare != ( pnData[0] & 0x0000FFFF ) )
if( ( nCompare & 0xFF ) != (pnData[0] & 0xFF) )
{
bVerifyError = TRUE;
break;
}
}
else
{
return ErrorCode;
}
}
// return appropriate error code if there was a verification error
if( bVerifyError == TRUE )
return VERIFY_WRITE;
}
// user did not want to verify writes
else
{
// fill the value
for (i = 0; ( ( i < lCount ) && ( ErrorCode == NO_ERR ) ); i++, ulStartAddr += ( lStride ))
{
// check to see that the address is within a valid sector
CmdStruct.SGetSectNum.ulOffset = ulStartAddr;
CmdStruct.SGetSectNum.pSectorNum = &ulSector;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_SECTNUM, &CmdStruct );
if( NO_ERR == ErrorCode )
{
// unlock the flash, do the write, and wait for completion
WriteBuff.Data = (void *)&pnData[0];
WriteBuff.pAdditionalInfo = (void *)&ulStartAddr;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Write(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&WriteBuff);
}
else
{
return ErrorCode;
}
}
}
// return the appropriate error code
return ErrorCode;
}
//----------- W r i t e D a t a ( ) ----------//
//
// PURPOSE
// Write a buffer to flash device.
//
// INPUTS
// unsigned long ulStart - address in flash to start the writes at
// long lCount - number of elements to write, in this case bytes
// long lStride - number of locations to skip between writes
// int *pnData - pointer to data buffer
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs during writing
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
ERROR_CODE WriteData( unsigned long ulStart, long lCount, long lStride, int *pnData )
{
long i = 0; // loop counter
ERROR_CODE ErrorCode = NO_ERR; // tells whether there was an error trying to write
int nCompare = 0; // value that we use to verify flash
bool bVerifyError = FALSE; // lets us know if there was a verify error
unsigned long ulAbsoluteAddr; // current address to write
unsigned long ulSector = 0; // sector number to verify address
ADI_DEV_1D_BUFFER WriteBuff; // buffer pointer
ADI_DEV_1D_BUFFER ReadBuff; // buffer pointer
ulAbsoluteAddr = FLASH_START_ADDR + ulStart;
COMMAND_STRUCT CmdStruct; //structure for GetSectStartEnd
// if the user wants to verify then do it
if( AFP_Verify == TRUE )
{
// write the buffer up to BUFFER_SIZE items
for (i = 0; ( i < lCount ) && ( ErrorCode == NO_ERR ); i++, ulAbsoluteAddr += lStride)
{
// check to see that the address is within a valid sector
//CmdStruct.SGetSectNum.ulOffset = ulAbsoluteAddr;
CmdStruct.SGetSectNum.ulOffset = 0;
CmdStruct.SGetSectNum.pSectorNum = &ulSector;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_SECTNUM, &CmdStruct );
if( NO_ERR == ErrorCode )
{
// unlock the flash, do the write, increase shift, and wait for completion
WriteBuff.Data = (void *)&pnData[i];
WriteBuff.pAdditionalInfo = (void *)&ulAbsoluteAddr ;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Write(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&WriteBuff);
ReadBuff.Data = (void *)&nCompare;
ReadBuff.pAdditionalInfo = (void *)&ulAbsoluteAddr ;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Read(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&ReadBuff);
if( ( nCompare & 0xFF ) != (pnData[i] & 0xFF) )
{
bVerifyError = TRUE;
break;
}
}
else
{
return ErrorCode;
}
}
// return appropriate error code if there was a verification error
if( bVerifyError == TRUE )
return VERIFY_WRITE;
}
// the user does not want to verify
else
{
// write the buffer up to BUFFER_SIZE items
for (i = 0; ( i < lCount ) && ( ErrorCode == NO_ERR ); i++, ulAbsoluteAddr += lStride)
{
// check to see that the address is within a valid sector
CmdStruct.SGetSectNum.ulOffset = ulAbsoluteAddr;
CmdStruct.SGetSectNum.pSectorNum = &ulSector;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_SECTNUM, &CmdStruct );
if( NO_ERR == ErrorCode )
{
// unlock the flash, do the write, increase shift, and wait for completion
WriteBuff.Data = (void *)&pnData[i] ;
WriteBuff.pAdditionalInfo = (void *)&ulAbsoluteAddr ;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Write(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&WriteBuff);
}
else
{
return ErrorCode;
}
}
}
// return the appropriate error code
return ErrorCode;
}
//----------- R e a d D a t a ( ) ----------//
//
// PURPOSE
// Read a buffer from flash device.
//
// INPUTS
// unsigned long ulStart - address in flash to start the reads at
// long lCount - number of elements to read, in this case bytes
// long lStride - number of locations to skip between reads
// int *pnData - pointer to data buffer to fill
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs during reading
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
ERROR_CODE ReadData( unsigned long ulStart, long lCount, long lStride, int *pnData )
{
long i = 0; // loop counter
ERROR_CODE ErrorCode = NO_ERR; // tells whether there was an error trying to read
unsigned long ulAbsoluteAddr; // current address to read
unsigned long ulSector = 0; // sector number to verify address
unsigned long ulMask =0xffff;
ADI_DEV_1D_BUFFER ReadBuff; // buffer pointer
COMMAND_STRUCT CmdStruct; //structure for GetSectStartEnd
ulAbsoluteAddr = FLASH_START_ADDR + ulStart;
// read the buffer up to BUFFER_SIZE items
for (i = 0; (i < lCount) && (i < BUFFER_SIZE); i++, ulAbsoluteAddr += lStride)
{
// check to see that the address is within a valid sector
CmdStruct.SGetSectNum.ulOffset = ulAbsoluteAddr;
CmdStruct.SGetSectNum.pSectorNum = &ulSector;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_SECTNUM, &CmdStruct );
if( NO_ERR == ErrorCode )
{
ReadBuff.Data = (void *)&pnData[i];
ReadBuff.pAdditionalInfo = (void *)&ulAbsoluteAddr ;
ErrorCode = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Read(NULL, ADI_DEV_1D, (ADI_DEV_BUFFER *)&ReadBuff);
}
else
{
return ErrorCode;
}
}
// return the appropriate error code
return ErrorCode;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -