中国自动化学会专家咨询工作委员会指定宣传媒体
免费注册 登录 广告服务 | 客服中心
您现在所在的是:

嵌入式系统

抖音 德嘉 泓格论坛 FLIR红外热像论坛
工控论坛首页 嵌入式系统 → 浏览主题: 【分享】飞凌S3C6410 NAND Flash驱动程序 WindowsCE版
发表新帖 回复该主题
回帖:0个,阅读:439 [上一页] [1] [下一页]
* 帖子主题:

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

分享到
720
死亡天使
文章数:13
年度积分:50
历史总积分:720
注册时间:2010/8/4
发站内信
发表于:2010/8/6 10:21:37
#0楼
这段时间一直在研究S3C6410 NAND驱动,把找到的一些源码发出来,希望对正在做这部分的朋友有所帮助。

   由于内容比较长,受字数和篇幅限制,详细代码可以在附件中下载。

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


// Copyright (c) Microsoft Corporation.  All rights reserved.
//
#include <fmd.h>
#include <nkintr.h>
#include <oal.h>

// 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 <ethdbg.h>
#include "Cfnand.h"
//#include <kitl.h>

//#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)

附件:【附件】OK6410NAND驱动源码.zip
[本地下载]
工控学堂推荐视频:

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

31.2002