19,500
社区成员
发帖
与我相关
我的任务
分享
BOOL OEMWriteFlash(DWORD dwStartAddr, DWORD dwLength)
{
//EdbgOutputDebugString("OEMWriteFlash 0x%x 0x%x\r\n", dwStartAddr, dwLength);
/* DWORD dwFlashAddr, dwExtraBytes = 0;
LPBYTE pbCache = NULL;
UCHAR nNumBlocks = 0;
//确认起始地址和长度都在Flash区域内
if(!OEMIsFlashAddr(dwStartAddr) || !OEMIsFlashAddr(dwStartAddr + dwLength - 1))
{
return(FALSE);
}
//确认起始地址是Block字节对齐的
if (dwStartAddr % FLASH_BLOCK_SIZE)
{
return(FALSE);
}
//计算要写入的block数量
nNumBlocks = (UCHAR) (dwLength/FLASH_BLOCK_SIZE);
dwExtraBytes = (dwLength % FLASH_BLOCK_SIZE);
dwFlashAddr = dwStartAddr;
pbCache = OEMMapMemAddr (dwStartAddr, dwFlashAddr);
//写Flash
while(nNumBlocks)
{
if (CFI_Write_Block((DWORD*)dwFlashAddr, (DWORD*)pbCache, FLASH_BLOCK_SIZE, NULL) != PASS)
{
EdbgOutputDebugString("ERROR: OEMWriteFlash - unable to write to block (block address=0x%x).\r\n", dwFlashAddr);
return(FALSE);
}
dwFlashAddr += FLASH_BLOCK_SIZE;
pbCache = OEMMapMemAddr (dwStartAddr, dwFlashAddr);
--nNumBlocks;
}
//将额外的数据写入Flash中
if(dwExtraBytes)
{
if (CFI_Write_Block((DWORD*)dwFlashAddr, (DWORD*)pbCache, dwExtraBytes, NULL) != PASS)
{
EdbgOutputDebugString("ERROR: OEMWriteFlash - unable to write to block (block address=0x%x).\r\n", dwFlashAddr);
return(FALSE);
}
}
*/
return TRUE;
}