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

📄 nand.h

📁 2KB大页面NAND Flash在WinCE5.0操作系统中的驱动程序。
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#ifndef __NAND_H__
#define __NAND_H__
#define K9F1G08_SUPPORT	(1)
#define K9F2G08_SUPPORT	(1)
#define K9F4G08_SUPPORT	(1)
#define K9F8G08_SUPPORT	(1)
#define K9K2G16_SUPPORT	(1)
#define NAND_BLOCK_CNT          (GetNumBlocks())      /* Each Plane has 1024 Blocks   */
#define NAND_PAGE_CNT           (GetSectorsPerBlock())            /* Each Block has 32 Pages      */
#define NAND_PAGE_SIZE          (GetBytesPerSector())           /* Each Page has 512 Bytes      */
#define NAND_BLOCK_SIZE         (NAND_PAGE_CNT * NAND_PAGE_SIZE)
#define SECTOR_SIZE	                (GetBytesPerSector()) 
#define LOG_2_PAGES_PER_BLOCK		(GetLog2PagesPerBlock(NAND_PAGE_CNT))//5			// Used to avoid multiplications
#define NUM_BLOCKS	(GetNumBlocks())
//  For flash chip that is bigger than 32 MB, we need to have 4 step address
//
//  Since we are using 64 MB NAND flash on SMDK2440, define NAND_SIZE_GT_32MB
//
#define NAND_SIZE_GT_32MB

#ifdef NAND_SIZE_GT_32MB
#define NEED_EXT_ADDR               1
#else
#define NEED_EXT_ADDR               0
#endif

//  Initialization value for configuration register
#define NFCONF_INIT                 0xF850
//#endif
#define CMD_READID              0x90        //  ReadID
#define CMD_READ                0x00        //  Read
#define CMD_READ1               0x01        //  Read1
#define CMD_READ2               0x50        //  Read2
#define CMD_RESET               0xff        //  Reset
#define CMD_ERASE               0x60        //  Erase phase 1
#define CMD_ERASE2              0xd0        //  Erase phase 2
#define CMD_WRITE               0x80        //  Write phase 1
#define CMD_WRITE2              0x10        //  Write phase 2
#define CMD_STATUS              0x70        //  Status read

//  Status bit pattern
#define STATUS_READY                0x40        //  Ready
#define STATUS_ERROR                0x01        //  Error

/* !!! Maximum Delay Setting, Please Adjust these value to Optimize */
//HCLK 133MHz
#define TACLS                   0     
#define TWRPH0                  6
#define TWRPH1                  2 
#define READ_REGISTER_ULONG(reg) \
    (*(volatile unsigned long * const)(reg))

#define WRITE_REGISTER_ULONG(reg, val) \
    (*(volatile unsigned long * const)(reg)) = (val)

#define READ_REGISTER_USHORT(reg) \
    (*(volatile unsigned short * const)(reg))

#define WRITE_REGISTER_USHORT(reg, val) \
    (*(volatile unsigned short * const)(reg)) = (val)

#define READ_REGISTER_UCHAR(reg) \
    (*(volatile unsigned char * const)(reg))

#define WRITE_REGISTER_UCHAR(reg, val) \
    (*(volatile unsigned char * const)(reg)) = (val)

#define NF_CMD(cmd)	            {s2440NAND->NFCMD   =  (cmd);}
#define NF_ADDR(addr)	        {s2440NAND->NFADDR  =  (unsigned char)(addr);}	
#define NF_nFCE_L()	            {s2440NAND->NFCONT &= ~(1 << 1);}
#define NF_nFCE_H()	            {s2440NAND->NFCONT |=  (1 << 1);}
#define NF_RSTECC()	            {s2440NAND->NFCONT |=  (1 << 4);}
#define NF_RDDATA() 	        READ_REGISTER_UCHAR((PUCHAR)&s2440NAND->NFDATA)
#define NF_WRDATA(data)         WRITE_REGISTER_UCHAR((PUCHAR)&s2440NAND->NFDATA, data)
#define NF_DATA_R4()		READ_REGISTER_ULONG(&s2440NAND->NFDATA)
#define NF_DATA_W4(val)		WRITE_REGISTER_ULONG(&s2440NAND->NFDATA, (ULONG) (val))
#define NF_RDDATA16() 	        READ_REGISTER_USHORT((PUSHORT)&s2440NAND->NFDATA)

#define NF_WAITRB()             {while (!(s2440NAND->NFSTAT & (1 << 1)));} 

#define NF_MECC_UnLock()	{s2440NAND->NFCONT &= ~(1 << 5);}
#define NF_MECC_Lock()		{s2440NAND->NFCONT |=  (1 << 5);}
#define NF_CLEAR_RB()			{s2440NAND->NFSTAT |=  (1 << 2);}
#define NF_DETECT_RB()		{while(!(s2440NAND->NFSTAT & (1<<2)));}
#define NF_ECC()					(s2440NAND->NFMECC0)
//  MACROS
#ifdef __cplusplus
extern "C" {
#endif 
WORD GetLog2PagesPerBlock(WORD pages_per_block);
DWORD GetNumBlocks();
WORD GetSectorsPerBlock();
WORD GetBytesPerSector();

#ifdef __cplusplus
}
#endif
#endif    // __NAND_H_.

⌨️ 快捷键说明

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