📄 fmd.cpp
字号:
RETAILMSG(SANKA_DBG,(_T("ERROR: Flashwrite: command sequence error ... .\r\n")));
if ((status & 0x0020) == 0x0020)
RETAILMSG(SANKA_DBG,(_T("ERROR: Flashwrite: clear lock bits error ... .\r\n")));
if (status != 0x0080)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: Flashwrite: status register returned 0x%X\r\n"), status));
RETAILMSG(SANKA_DBG,(_T("ERROR: Flashwrite: unrecoverable failure encountered while erasing flash.\r\n")));
WRITE_COMMAND(ulBlockAddress, READ_ARRAY_CMD);
FMDHAL_ASMInterruptEnable();
return 0;
}
RETAILMSG(SANKA_DBG,(_T("Now Write \r\n")));
WRITE_COMMAND(ulBlockAddress, CLEAR_STATUS_CMD);
WRITE_COMMAND(ulBlockAddress, BUFFER_WRITE_CMD);
status = READ_FLASH(ulBlockAddress);
while ( (status & 0x0080) != 0x0080)
{
WRITE_COMMAND(ulBlockAddress, BUFFER_WRITE_CMD);
status = READ_FLASH(ulBlockAddress);
}
if (g_bPairedFlash)
{
PULONG pLongBuffer = (PULONG)pBuffer;
WRITE_ULONG (ulBlockAddress, (dwWordCount << 16) | dwWordCount);
for(k = 0 ; k < NumWriteBytes ; k += dwBusWidth)
{
WRITE_ULONG (physicalSectorAddr + k, *pLongBuffer++);
}
}
else
{
PUSHORT pShortBuffer = (PUSHORT)pBuffer;
WRITE_USHORT (ulBlockAddress, (USHORT)dwWordCount);
for(k = 0 ; k < NumWriteBytes ; k += dwBusWidth)
{
WRITE_USHORT (physicalSectorAddr + k, *pShortBuffer++);
}
}
// Now program the buffer into flash...
//
WRITE_COMMAND(ulBlockAddress, BLOCK_PROCEED_CMD);
status = READ_FLASH(ulBlockAddress);
while ( (status & 0x0080) != 0x0080)
{
status = READ_FLASH(ulBlockAddress);
}
WRITE_COMMAND(ulBlockAddress, READ_ARRAY_CMD);
FMDHAL_ASMInterruptEnable();
#if 0
PUSHORT pShortBuffer1 = (PUSHORT)pBuffer;
for(k = 0 ; k < NumWriteBytes ; k += dwBusWidth)
{
if(READ_USHORT (physicalSectorAddr + k) != *pShortBuffer1++)
{
RETAILMSG(SANKA_DBG,(_T( "ERROR: FlashWrite: verification failure at address 0x%x (expected 0x%x actual 0x%x))\r\n"), physicalSectorAddr + k, *(pShortBuffer1-1), READ_USHORT (physicalSectorAddr + k) ));
return k;
}
}
#endif
return NumWriteBytes;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: FMD_GetBlockStatus()
Description: Returns the status of a block. For read-only blocks, checks the sector
info data for the first sector of the block. Block is always good, so no need to check.
Returns: Block status.
------------------------------------------------------------------------------*/
DWORD FMD_GetBlockStatus(BLOCK_ID blockID)
{
SECTOR_ADDR Sector = blockID * g_FMDInfo.SectorsPerBlock;
SectorInfo SI;
DWORD dwResult = 0;
if (!FMD_ReadSector(Sector, NULL, &SI, 1))
return BLOCK_STATUS_UNKNOWN;
if (!(SI.bOEMReserved & OEM_BLOCK_READONLY))
dwResult |= BLOCK_STATUS_READONLY;
if (!(SI.bOEMReserved & OEM_BLOCK_RESERVED))
dwResult |= BLOCK_STATUS_RESERVED;
return dwResult;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: FMD_SetBlockStatus()
Description: Sets the status of a block.
Returns: TRUE if no errors in setting.
------------------------------------------------------------------------------*/
BOOL FMD_SetBlockStatus(BLOCK_ID blockID, DWORD dwStatus)
{
if (dwStatus & (BLOCK_STATUS_READONLY | BLOCK_STATUS_RESERVED)) {
SECTOR_ADDR Sector = blockID * g_FMDInfo.SectorsPerBlock;
SectorInfo SI;
if (!FMD_ReadSector(Sector, NULL, &SI, 1)) {
return FALSE;
}
if (dwStatus & BLOCK_STATUS_READONLY) {
SI.bOEMReserved &= ~OEM_BLOCK_READONLY;
}
if (dwStatus & BLOCK_STATUS_RESERVED) {
SI.bOEMReserved &= ~OEM_BLOCK_RESERVED;
}
if (!FMD_WriteSector (Sector, NULL, &SI, 1)) {
return FALSE;
}
}
return TRUE;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: FMD_EraseBlock()
Description: Erases the specified Flash block.
Returns: Boolean indicating success.
------------------------------------------------------------------------------*/
BOOL FMD_EraseBlock(BLOCK_ID blockID)
{
volatile ULONG ulBlockAddress = 0;
BOOL bRetVal = TRUE;
BOOL bLastMode = SetKMode(TRUE);
BYTE cNullSignature[BLOCK_SIG_BYTES] = {0};
USHORT * pFlash;
DWORD status = 0;
RETAILMSG(SANKA_DBG,(_T("FMD_EraseBlock %d \r\n"),blockID));
// Determine the address for the specified block.
ulBlockAddress = g_FMDInfo.BaseAddress + (blockID * g_FMDInfo.BlockSize);
pFlash = (USHORT *)ulBlockAddress;
/* // Whack the block signature
if (!SignBlock(ulBlockAddress, cNullSignature))
{
DEBUGMSG(1, (TEXT("FMD_EraseBlock: Unable to whack block signature\r\n")));
bRetVal = FALSE;
goto Error;
}*/
RETAILMSG(SANKA_DBG,(_T("First unlock \r\n")));
//first ulock
FMDHAL_ASMInterruptDisable();
WRITE_COMMAND(ulBlockAddress, BLOCK_LOCK_CMD);
WRITE_COMMAND(ulBlockAddress, BLOCK_PROCEED_CMD);
status = READ_FLASH(ulBlockAddress);
while ((status & 0x0080) != 0x0080)
{
status = READ_FLASH(ulBlockAddress);
}
if ((status & 0x0008) == 0x0008)
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: voltage range error ... .\r\n")));
if ((status & 0x0030) == 0x0030)
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: command sequence error ... .\r\n")));
if ((status & 0x0020) == 0x0020)
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: clear lock bits error ... .\r\n")));
if (status != 0x0080)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: status register returned 0x%X\r\n"), status));
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: unrecoverable failure encountered while erasing flash.\r\n")));
goto Error;
}
RETAILMSG(SANKA_DBG,(_T("Now Erase \r\n")));
WRITE_COMMAND(ulBlockAddress, CLEAR_STATUS_CMD);
// Issue erase and confirm command.
// Note: eventually this should be changed to issue mass block erases, then loop to
// verify each completes.
WRITE_COMMAND(ulBlockAddress, BLOCK_ERASE_CMD);
WRITE_COMMAND(ulBlockAddress, BLOCK_PROCEED_CMD);
status = READ_FLASH(ulBlockAddress);
while ((status & 0x0080) != 0x0080)
{
status = READ_FLASH(ulBlockAddress);
}
if(status & 0x0008)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: Voltage error %x.\r\n"),status));
goto Error;
}
else if(status & 0x0030)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: Command sequence error %x.\r\n"),status));
//goto Error;
}
else if(status & 0x0020)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: Block erase error %x.\r\n"),status));
goto Error;
}
else if(status & 0x0002)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: Locked block erase error %x.\r\n"),status));
goto Error;
}
RETAILMSG(SANKA_DBG,(_T("No ERROR: FlashErase: status %x.\r\n"),status));
WRITE_COMMAND(ulBlockAddress, READ_ARRAY_CMD);
// Flash erase verification.
for (UINT i = 0; i < g_FMDInfo.BlockSize / 2; i++)
{
if (*pFlash++ != 0xFFFF)
{
RETAILMSG(SANKA_DBG,(_T("ERROR: FlashErase: erase verification failure at address 0x%X Data 0x%02X.\r\n"), pFlash-1, *(pFlash-1)));
goto Error;
}
}
// Sign the block
if (!SignBlock(ulBlockAddress, (PUCHAR) gc_cBlockSig))
{
DEBUGMSG(1, (TEXT("FMD_EraseBlock: Unable to create block signature\r\n")));
bRetVal = FALSE;
goto Error;
}
Error:
// Set the block back to read array mode...
FMDHAL_ASMInterruptEnable();
WRITE_COMMAND(ulBlockAddress, READ_ARRAY_CMD);
SetKMode(bLastMode);
return bRetVal;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: FMD_PowerUp()
Description: Restores power to the Flash memory device (if applicable).
Returns: None.
------------------------------------------------------------------------------*/
VOID FMD_PowerUp(VOID)
{
return;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: FMD_PowerDown()
Description: Suspends power to the Flash memory device (if applicable).
Returns: None.
------------------------------------------------------------------------------*/
VOID FMD_PowerDown(VOID)
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -