【分享】飞凌S3C6410 NAND Flash驱动程序 WindowsCE版

发布时间:2010-8-6 13:03    发布者:死亡天使
关键词: Flash , NAND , WindowsCE , 程序 , 飞凌
这段时间一直在研究S3C6410 NAND驱动,把找到的一些源码发出来,希望对正在做这部分的朋友有
所帮助。
    由于内容比较长,受字数和篇幅限制,详细代码可以在附件中下载。

本文转引自 飞凌嵌入式 ARM11 OK6410讨论区 www.witech.com.cn

// Copyright (c) Microsoft Corporation.  All rights reserved.
//
#include
#include
#include
// BSP Configuration Files
#include "bsp_cfg.h"
#include "bsp_base_reg_cfg.h"
// Base Definitions
#include "s3c6410_base_regs.h"
#include "s3c6410_nand.h"
#include "s3c6410_syscon.h"
//#include
#include "Cfnand.h"
//#include
//#define SYNC_OP
#define CHECK_SPAREECC    (1)
#define NAND_DEBUG        (0)
#define NAND_BASE        (0xB0200000)    // PA:0x70200000
#define SYSCON_BASE        (0xB2A0F000)    // PA:0x7E00F000
#ifdef    SYNC_OP
CRITICAL_SECTION    g_csNandFlash;
#endif
static volatile S3C6410_NAND_REG *g_pNFConReg = NULL;
static volatile S3C6410_SYSCON_REG *g_pSysConReg = NULL;

NANDDeviceInfo GetNandInfo(void) { return stDeviceInfo; }
static DWORD ReadFlashID(void)
{
    BYTE Mfg, Dev;
    int i;
    NF_nFCE_L();                // Deselect the flash chip.
    NF_CMD(CMD_READID);        // Send flash ID read command.
    NF_ADDR(0);
    for (i=0; i<10; i++)
    {
        Mfg    = NF_RDDATA_BYTE();
        if (Mfg == 0xEC || Mfg == 0x98) break;
    }
    Dev    = NF_RDDATA_BYTE();
    NF_nFCE_H();
    return ((DWORD)(Mfg<<8)+Dev);
}
PVOID FMD_Init(LPCTSTR lpActiveReg, PPCI_REG_INFO pRegIn, PPCI_REG_INFO pRegOut)
{
    volatile DWORD nNandID;
    UINT8 nMID, nDID;
    UINT32 nCnt;
    BOOL bNandExt = FALSE;
    RETAILMSG(1, (TEXT("[FMD] ++FMD_Init() ****\r\n")));


    if (pRegIn && pRegIn->MemBase.Num && pRegIn->MemBase.Reg[0])
    {
        g_pNFConReg = (S3C6410_NAND_REG *)(pRegIn->MemBase.Reg[0]);
    }
    else
    {
        g_pNFConReg = (S3C6410_NAND_REG *)NAND_BASE;
    }
    g_pSysConReg = (S3C6410_SYSCON_REG *)SYSCON_BASE;
#ifdef    SYNC_OP
    InitializeCriticalSection(&g_csNandFlash);
    EnterCriticalSection(&g_csNandFlash);
#endif

    if (!bNandExt)
    {
        RETAILMSG(1, (TEXT("[FMD:ERR] FMD_Init() : Unknown ID = 0x%08x\n"), nNandID));
        return NULL;
    }
    NUM_OF_BLOCKS = astNandSpec[nCnt].nNumOfBlks;
    PAGES_PER_BLOCK = astNandSpec[nCnt].nPgsPerBlk;
    SECTORS_PER_PAGE = astNandSpec[nCnt].nSctsPerPg;
    RETAILMSG(1, (TEXT("[FMD] --FMD_Init()\n")));
    return((PVOID)g_pNFConReg);
}

BOOL FMD_ReadSector(SECTOR_ADDR startSectorAddr, LPBYTE pSectorBuff, PSectorInfo
pSectorInfoBuff, DWORD dwNumSectors)
{
    BOOL bRet;
    //RETAILMSG(1, (TEXT("[R:0x%08x] \n"), startSectorAddr));
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] ++FMD_ReadSector(0x%08x) \n"), startSectorAddr));
#endif
#ifdef    SYNC_OP
    EnterCriticalSection(&g_csNandFlash);
#endif
    if ( IS_LB )
    {
        bRet = FMD_LB_ReadSector(startSectorAddr, pSectorBuff, pSectorInfoBuff,
dwNumSectors, USE_NFCE);
    }
    else
    {
        bRet = FMD_SB_ReadSector(startSectorAddr, pSectorBuff, pSectorInfoBuff,
dwNumSectors, USE_NFCE);
    }
#ifdef    SYNC_OP
    LeaveCriticalSection(&g_csNandFlash);
#endif
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] --FMD_ReadSector()\n")));
#endif
    return bRet;
}

BOOL FMD_EraseBlock(BLOCK_ID blockID)
{
    BOOL    bRet = TRUE;
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] ++FMD_EraseBlock(0x%08x) \n"), blockID));
#endif
#ifdef    SYNC_OP
    EnterCriticalSection(&g_csNandFlash);
#endif
    if ( IS_LB )
    {
        bRet = FMD_LB_EraseBlock(blockID, USE_NFCE);
    }
    else
    {
        bRet = FMD_SB_EraseBlock(blockID, USE_NFCE);
    }
#ifdef    SYNC_OP
    LeaveCriticalSection(&g_csNandFlash);
#endif
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] --FMD_EraseBlock()\n")));
#endif
    return bRet;
}

BOOL FMD_WriteSector(SECTOR_ADDR startSectorAddr, LPBYTE pSectorBuff, PSectorInfo
pSectorInfoBuff, DWORD dwNumSectors)
{
    BOOL    bRet = TRUE;
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] ++FMD_WriteSector(0x%08x) \n"), startSectorAddr));
#endif
#ifdef    SYNC_OP
    EnterCriticalSection(&g_csNandFlash);
#endif
    if ( IS_LB )
    {
        bRet = FMD_LB_WriteSector(startSectorAddr, pSectorBuff, pSectorInfoBuff,
dwNumSectors, USE_NFCE);
    }
    else
    {
        bRet = FMD_SB_WriteSector(startSectorAddr, pSectorBuff, pSectorInfoBuff,
dwNumSectors, USE_NFCE);
    }
#ifdef    SYNC_OP
    LeaveCriticalSection(&g_csNandFlash);
#endif
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] --FMD_WriteSector()\n")));
#endif
    return bRet;
}

VOID FMD_PowerUp(VOID)
{
#if (NAND_DEBUG)
    RETAILMSG(1, (TEXT("[FMD] FMD_PowerUp() \n")));
#endif
    // Set up initial flash controller configuration.
    g_pNFConReg->NFCONF = (TACLS<<12) | (TWRPH0<<8) | (TWRPH1<<4);
    g_pNFConReg->NFCONT = (0<<17)|(0<<16)|(0<<10)|(0<<9)|(0<<8)|(1<<7)|(1<<6)|(1<<5)|
(1<<4)|(0x3<<1)|(1<<0);
    g_pNFConReg->NFSTAT = (1<<4);
}

VOID FMD_PowerDown(VOID)
本文地址:https://www.eechina.com/thread-19717-1-1.html     【打印本页】

本站部分文章为转载或网友发布,目的在于传递和分享信息,并不代表本网赞同其观点和对其真实性负责;文章版权归原作者及原出处所有,如涉及作品内容、版权和其它问题,我们将根据著作权人的要求,第一时间更正或删除。
youyou_zh 发表于 2011-5-24 21:19:08
kanbudong
您需要登录后才可以发表评论 登录 | 立即注册

厂商推荐

相关视频

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表