|
BOOL OEMWriteFlash(DWORD dwStartAddr, DWORD dwLength); 关于这个函数,我在网上找到了微软通用的源代码
BOOL OEMWriteFlash(DWORD dwImageStart, DWORD dwImageLength)
{
DWORD dwFlashAddr, dwExtraBytes = 0;
LPBYTE pbCache = NULL;
UCHAR nNumBlocks = 0;
//确认起始地址和长度都在Flash区域内
if (!OEMIsFlashAddr(dwImageStart) || !OEMIsFlashAddr(dwImageStart + dwImageLength - 1))
{
return(FALSE);
}
//确认起始地址是Block字节对齐的
if (dwImageStart % FLASH_BLOCK_SIZE)
{
return(FALSE);
}
//计算要写入的block数量
nNumBlocks = (UCHAR)(dwImageLength / FLASH_BLOCK_SIZE);
dwExtraBytes = (dwImageLength % FLASH_BLOCK_SIZE);
dwFlashAddr = dwImageStart;
pbCache = OEMMapMemAddr (dwImageStart, dwFlashAddr);
//写Flash
while(nNumBlocks)
{
if (CFI_Write_Block((unsigned32*)dwFlashAddr, (unsigned32*)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 (dwImageStart, dwFlashAddr);
--nNumBlocks;
}
//将额外的数据写入Flash中
if (dwExtraBytes)
{
if (CFI_Write_Block((unsigned32*)dwFlashAddr, (unsigned32*)pbCache, dwExtraBytes, NULL) != PASS)
{
EdbgOutputDebugString("ERROR: OEMWriteFlash - unable to write to block (block address=0x%x).\r\n", dwFlashAddr);
return(FALSE);
}
}
return(TRUE);
}
但关键是这里面的函数CFI_Write_Block不知道怎么实现啊,BSP里面没有这个函数,请问各位高手这个问题怎么解决啊?老师现在天天催项目进度,都逼死了。。谢谢! |
|