⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmd.cpp

📁 s3c2443 embedded windows ce 6.0 bsp s3c2443 embedded windows ce 6.0 bsp
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                WrPageInfo((PBYTE)pSectorInfoBuff);
                pSectorInfoBuff++;

            }
            else    // Make sure we advance the Flash's write pointer (even though we aren't writing the SectorInfo data)
            {
                BYTE TempInfo[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
                WrPageInfo(TempInfo);
            }
            pSectorBuff += NAND_PAGE_SIZE;

			MECC = NF_RDMECC0();
			NF_WRDATA((UINT8)(MECC      ) & 0xff);
			NF_WRDATA((UINT8)(MECC >>  8) & 0xff);
			NF_WRDATA((UINT8)(MECC >> 16) & 0xff);
			NF_WRDATA((UINT8)(MECC >> 24) & 0xff);

        }
            
        NF_CMD(CMD_WRITE2);                    // Send write confirm command.
        NF_WAITRB();                        // Wait for command to complete.

        NF_CMD(CMD_STATUS);
        Status = NF_RDDATA();
        if (Status & 1)
        {
//RETAILMSG(1,(TEXT("ERROR: FMD_WriteSector: failed sector write. \r\n")));
            // EdbgOutputDebugString("ERROR: FMD_WriteSector: failed sector write.\r\n");
            return(FALSE);
        }

        ++SectorAddr;
    }

    NF_nFCE_H();                            // Deselect the flash chip.

 
#if 0   
    {
        SectorInfo si;
	BYTE test2[1000];
	BYTE *test;
	test = (BYTE *)&si;
 FMD_ReadSector(startSectorAddr, (LPBYTE) test2, (PSectorInfo) &si, 1);
RETAILMSG(1,(TEXT("read: %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x . \r\n"),test[0],test[1],test[2],test[3],test[4],test[5],test[6],test[7],test[8],test[9],test[10],test[11]));
    }
#endif
    return(TRUE);
}


VOID FMD_PowerUp(VOID)
{
	// Set up initial flash controller configuration.
    //
#if 1
    s2440NAND->NFCONF =  (TACLS  <<  12) | /* CLE & ALE = HCLK * (TACLS  + 1)   */
                         (TWRPH0 <<  8) | /* TWRPH0    = HCLK * (TWRPH0 + 1)   */
                         (TWRPH1 <<  4);

    s2440NAND->NFCONT = (0<<13)|(0<<12)|(0<<10)|(0<<9)|(0<<8)|(0<<6)|(0<<5)|(1<<4)|(1<<1)|(1<<0);
	s2440NAND->NFSTAT = 0x4;
#else
        s2440NAND->NFCONF = 1 << 12 | 5 << 8 | 1 << 4 | 0 << 0;
        s2440NAND->NFCONT = 0 << 12 | 0 << 8 | 1 << 6 | 1 << 5 | 1 << 1 | 1 << 0;
//	s2440NAND->NFSTAT = 0x4;
#endif	
}


VOID FMD_PowerDown(VOID)
{
}

BOOL FMD_OEMIoControl(DWORD dwIoControlCode, PBYTE pInBuf, DWORD nInBufSize, PBYTE pOutBuf, DWORD nOutBufSize, PDWORD pBytesReturned)
{
    switch( dwIoControlCode )
    {
       case IOCTL_FMD_GET_INTERFACE:
		   return(FALSE);
	      break;
	   default:	  
          return(TRUE);
	      break;
    }	  
}

BOOL FMD_Deinit(PVOID hFMD)
{
    return(TRUE);
}


/*
    @func   BOOL | FMD_GetInfo | Provides information on the NAND flash.
    @rdesc  TRUE = Success, FALSE = Failure.
    @comm    
    @xref   
*/
BOOL FMD_GetInfo(PFlashInfo pFlashInfo)
{

    if (!pFlashInfo)
        return(FALSE);

    pFlashInfo->flashType            = NAND;
    pFlashInfo->wDataBytesPerSector = NAND_PAGE_SIZE;
    pFlashInfo->dwNumBlocks         = NAND_BLOCK_CNT;
    pFlashInfo->wSectorsPerBlock    = NAND_PAGE_CNT;
    pFlashInfo->dwBytesPerBlock        = (pFlashInfo->wSectorsPerBlock * pFlashInfo->wDataBytesPerSector);
	
	return(TRUE);
}

#define VALIDADDR	0x05	// S3C2440aNAND

static BOOL IsBlockBad(BLOCK_ID blockID)
{
#if 1	// S3C2440aNAND
    DWORD   dwPageID = blockID << 5;
    BOOL    bRet = FALSE;
    BYTE    wFlag;


	NF_nFCE_L();            // Select the flash chip.
//////	NF_CLEAR_RB();
    NF_CMD(CMD_RESET);        // Send reset command.
    NF_WAITRB();            // Wait for flash to complete command.
    //  Issue the command
    NF_CMD(CMD_READ2);
    //  Set up address
    NF_ADDR(VALIDADDR);
    NF_ADDR((dwPageID) & 0xff);
    NF_ADDR((dwPageID >> 8) & 0xff);

    if (NEED_EXT_ADDR) {
        NF_ADDR((dwPageID >> 16) & 0xff);
    }
    //  Wait for Ready bit
//////	NF_DETECT_RB();	 // Wait tR(max 12us)
    NF_WAITRB();            // Wait for flash to complete command.
    //  Now get the byte we want
    wFlag = (BYTE) NF_RDDATA();
    if(wFlag != 0xff) {
        bRet = TRUE;
    }
    //  Disable the chip
    NF_nFCE_H();
    return bRet;
#else

    BYTE Data;
    SECTOR_ADDR blockPage = (blockID * NAND_PAGE_CNT);


    NF_nFCE_L();            // Select the flash chip.
    NF_CMD(CMD_RESET);        // Send reset command.
    NF_WAITRB();            // Wait for flash to complete command.
    NF_CMD(CMD_READ2);        // Send read confirm command.
    NF_ADDR(0);                            // Column = 0.
    NF_ADDR(blockPage         & 0xff);    /* The mark of bad block is in 0 page   */
    NF_ADDR((blockPage >>  8) & 0xff);  /* For block number A[24:17]            */
    NF_ADDR((blockPage >> 16) & 0xff);  /* For block number A[25]               */
    NF_WAITRB();            // Wait for flash to complete command.

    // TODO
    Data = NF_RDDATA();        // Read command status.
    Data = NF_RDDATA();        // Read command status.
    Data = NF_RDDATA();        // Read command status.
    Data = NF_RDDATA();        // Read command status.
    Data = NF_RDDATA();        // Read command status.
    Data = NF_RDDATA();        // Read command status.

    if(0xff != Data)
    {
        return(TRUE);
    }

    NF_nFCE_H();            // Deassert the flash chip.

   
    return(FALSE);
#endif
}


/*
    @func   DWORD | FMD_GetBlockStatus | Returns the status of the specified block.
    @rdesc  Block status (see fmd.h).
    @comm    
    @xref   
*/
DWORD FMD_GetBlockStatus(BLOCK_ID blockID)
{
    SECTOR_ADDR Sector = (blockID * NAND_PAGE_CNT);
    SectorInfo SI;
    DWORD dwResult = 0;

    if (IsBlockBad(blockID))
        return BLOCK_STATUS_BAD;
    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);
}


/*
    @func   BOOL | MarkBlockBad | Marks the specified block as bad.
    @rdesc  TRUE = Success, FALSE = Failure.
    @comm    
    @xref   
*/
static BOOL MarkBlockBad(BLOCK_ID blockID)
{
    BYTE Status;
    ULONG blockPage = (blockID * NAND_PAGE_CNT);    // Convert block address to page address.


    NF_nFCE_L();            // Select the flash chip.
    NF_CMD(CMD_RESET);        // Send reset command.
    NF_WAITRB();            // Wait for flash to complete command.
    NF_CMD(CMD_READ2);        // Send read confirm command.
    NF_CMD(CMD_WRITE);        // Send write command.
    NF_ADDR(0);                            // Column = 0.
    NF_ADDR(blockPage         & 0xff);    /* The mark of bad block is in 0 page   */
    NF_ADDR((blockPage >>  8) & 0xff);  /* For block number A[24:17]            */
    NF_ADDR((blockPage >> 16) & 0xff);  /* For block number A[25]               */

    // TODO
    NF_WRDATA((UCHAR)0xFF);            // Write bad block marker.
    NF_WRDATA((UCHAR)0xFF);            // Write bad block marker.
    NF_WRDATA((UCHAR)0xFF);            // Write bad block marker.
    NF_WRDATA((UCHAR)0xFF);            // Write bad block marker.
    NF_WRDATA((UCHAR)0xFF);            // Write bad block marker.

    NF_WRDATA((UCHAR)0);            // Write bad block marker.
    NF_CMD(CMD_WRITE2);        // Send write confirm command.
    NF_WAITRB();            // Wait for flash to complete command.

    Status = NF_RDDATA();    // Read command status.
    NF_nFCE_H();            // Deassert the flash chip.

#if 1	// S3C2440
    return((Status & 0x4) ? FALSE : TRUE);
#else	// S3C2410
    return((Status & 1) ? FALSE : TRUE);
#endif
}

/*
    @func   BOOL | FMD_SetBlockStatus | Marks the block with the specified block status.
    @rdesc  TRUE = Success, FALSE = Failure.
    @comm    
    @xref   
*/
BOOL FMD_SetBlockStatus(BLOCK_ID blockID, DWORD dwStatus)
{
    if (dwStatus & BLOCK_STATUS_BAD)
    {
        if (!MarkBlockBad(blockID))
            return(FALSE);
    }

    if (dwStatus & (BLOCK_STATUS_READONLY | BLOCK_STATUS_RESERVED)) {
        
        SECTOR_ADDR Sector = blockID * NAND_PAGE_CNT;
        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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -