BOOL
FMD_ReadSector(
SECTOR_ADDR startSectorAddr,
LPBYTE pSectorBuff,
PSectorInfo pSectorInfoBuff,
DWORD dwNumSectors
)
{
DWORD i, r = 0;
BYTE ecc0,ecc1,ecc2;
BOOL rc = TRUE;
ECCRegVal eccRegVal;
// BUGBUGBUG: I need to come back to support dwNumSectors > 1
//
// Sanity check
if (!pSectorBuff && !pSectorInfoBuff || dwNumSectors > 1 || !pSectorBuff) {
// Uart_SendString("ERROR_INVALID_PARAMETER\n");
return FALSE;
}
// Uart_SendString("R: ");
// Uart_SendDWORD(startSectorAddr, TRUE);
_retry:
// Initialize ECC register
NF_RSTECC();
NF_MECC_UnLock();
// Enable the chip
NF_nFCE_L();
NF_CLEAR_RB();
// Issue Read command
NF_CMD(CMD_READ);
// Set up address
NF_ADDR(0x00);
NF_ADDR((startSectorAddr) & 0xff);
NF_ADDR((startSectorAddr >> 8) & 0xff);
if (NEED_EXT_ADDR) {
NF_ADDR((startSectorAddr >> 16) & 0xff);
}
for (i = 0; i < 5; i++); // wait tWB(100ns)
NF_DETECT_RB(); // wait tR(max 12us)
// read the data
__RdPage512(pSectorBuff);
// __RdPage256(pSectorBuff);
NF_MECC_Lock();
// for ( i = 0; i < 512; i++ )
// Uart_SendByte(*(pSectorBuff+i));
// Read the ECC from ECC Register
eccRegVal.dwECCVal = NF_ECC();
// Skip first 8 bytes
for(i=0; i<8; i++){
ecc0 = (BYTE)NF_DATA_R();
}
ecc0 = (BYTE)NF_DATA_R();
ecc1 = (BYTE)NF_DATA_R();
ecc2 = (BYTE)NF_DATA_R();
NF_nFCE_H();
if ( !rc && r++ < 3 ) {
Uart_SendString("FMD_ReadSector: ");
Uart_SendDWORD(startSectorAddr, TRUE);
NF_Reset();
for (i = 0; i < 5; i++); // delay
rc = TRUE;
goto _retry;
}
if ( startSectorAddr < 0x120 ) // NO ECC Check about EBOOT
{
rc = TRUE;
}
else
{
if( ecc0 != eccRegVal.bECCBuf[0] ||
ecc0 != eccRegVal.bECCBuf[0] ||
ecc0 != eccRegVal.bECCBuf[0] ) {
// Uart_SendString("ECC mismatch for Sector: ");
// Uart_SendDWORD(startSectorAddr, TRUE);
rc = FALSE;
}
}
return rc;
}
红色标记改怎么理解呢??NF_ADDR(addr) 定义:
#define NF_ADDR(addr) {rNFADDR = (addr); }