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

📄 nandflash.h

📁 基于S3C2410和SM501的彩屏控制器程序
💻 H
字号:
#ifndef NANDFLASH_H
#define NANDFLASH_H

//********************** Including Libs **********************
#include <stdio.h>
#include <string.h>
#include "2410.h"
#include "comdef.h"



//********************** Macro Definition **********************
/*
 * Standard NAND flash commands
 */
#define NAND_CMD_READ0		0
#define NAND_CMD_READ1		1
#define NAND_CMD_PAGEPROG	0x10
#define NAND_CMD_READOOB	0x50
#define NAND_CMD_ERASE1		0x60
#define NAND_CMD_STATUS		0x70
#define NAND_CMD_SEQIN		0x80
#define NAND_CMD_READID		0x90
#define NAND_CMD_ERASE2		0xd0
#define NAND_CMD_RESET		0xff

#define PAGES			32		//每块nandflash的页数
#define PAGE_BYTES		512		//NandFlash每页字节数
#define BLOCK_BYTES		(PAGE_BYTES*PAGES)//nandflash每块字节数

#define CFG_NAND_BASE   	0x4E000000
#define CFG_MAX_NAND_DEVICE	1	/* Max number of NAND devices		*/
#define SECTORSIZE 512

#define ADDR_COLUMN 1
#define ADDR_PAGE 2
#define ADDR_COLUMN_PAGE 3

#define NAND_ChipID_UNKNOWN 	0x00
#define NAND_MAX_FLOORS 1
#define NAND_MAX_CHIPS 1

#define NAND_WAIT_READY(nand)	{while(!(rNFSTAT&(1<<0)));}

#define NAND_DISABLE			rNFCONF &= (~(1<<15));
#define NAND_ENABLE				rNFCONF |= (1<<15);

#define NAND_DISABLE_CE(nand)	{rNFCONF|=(1<<11);}
#define NAND_ENABLE_CE(nand)	{rNFCONF&=(~(1<<11));}


#define WRITE_NAND_COMMAND(d, adr)	{rNFCMD=d;}
#define WRITE_NAND_ADDRESS(d, adr)	{rNFADDR=d;}
#define WRITE_NAND(d, adr)		{rNFDATA=d;}
#define READ_NAND(adr)			(rNFDATA)

/* the following functions are NOP's because S3C24X0 handles this in hardware */

#define NAND_CTL_CLRALE(nandptr)
#define NAND_CTL_SETALE(nandptr)
#define NAND_CTL_CLRCLE(nandptr)
#define NAND_CTL_SETCLE(nandptr)

#define TEMP_LZMA_ADDR		0x30600000	// 解压过程临时地址

#define	 ALLOW_ERASE_BAD_DEBUG 0
#define CONFIG_MTD_NAND_ECC			// enable ECC

#define NANDRW_READ		0x01
#define NANDRW_WRITE	0x00
#define NANDRW_JFFS2	0x02

#define JFFS2_MAGIC_BITMASK 0x1985
#define JFFS2_NODE_ACCURATE 0x2000 
#define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
/* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
#define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
#define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)

#define ROUND_DOWN(value,boundary)      ((value) & (~((boundary)-1)))
/*
 * General Purpose Utilities
 */
#define min(x, y) x>y?y:x

/*
 * NAND Flash Manufacturer ID Codes
 */
#define NAND_MFR_TOSHIBA	0x98
#define NAND_MFR_SAMSUNG	0xec

/*
* Constants for oob configuration
*/
#define NAND_NOOB_ECCPOS0		0
#define NAND_NOOB_ECCPOS1		1
#define NAND_NOOB_ECCPOS2		2
#define NAND_NOOB_ECCPOS3		3
#define NAND_NOOB_ECCPOS4		6
#define NAND_NOOB_ECCPOS5		7
#define NAND_NOOB_BADBPOS		-1
#define NAND_NOOB_ECCVPOS		-1

#define NAND_JFFS2_OOB_ECCPOS0		0
#define NAND_JFFS2_OOB_ECCPOS1		1
#define NAND_JFFS2_OOB_ECCPOS2		2
#define NAND_JFFS2_OOB_ECCPOS3		3
#define NAND_JFFS2_OOB_ECCPOS4		6
#define NAND_JFFS2_OOB_ECCPOS5		7
#define NAND_JFFS2_OOB_BADBPOS		5
#define NAND_JFFS2_OOB_ECCVPOS		4

#define NAND_JFFS2_OOB8_FSDAPOS		6
#define NAND_JFFS2_OOB16_FSDAPOS	8
#define NAND_JFFS2_OOB8_FSDALEN		2
#define NAND_JFFS2_OOB16_FSDALEN	8



//**************** Structure & Type Definition ****************
/*
 * Enumeration for NAND flash chip state
 */
typedef enum {
	FL_READY,
	FL_READING,
	FL_WRITING,
	FL_ERASING,
	FL_SYNCING
} nand_state_t;


struct Nand {
	char floor, chip;
	unsigned long curadr;
	unsigned char curmode;
	/* Also some erase/write/pipeline info when we get that far */
};

struct nand_chip {
	int 		page_shift;
	u_char 		data_buf[528];
	u_char 		data_cache[528];
	int		cache_page;
	u_char 		ecc_code_buf[6];
	u_char 		reserved[2];
	char ChipID; /* Type of DiskOnChip */
	struct Nand chips[2];
	int chipshift;
	char chips_name[64];
	unsigned long erasesize;
	unsigned long mfr; /* Flash IDs - only one type of flash per device */
	unsigned long id;
	char name[64];
	int numchips;
	char page256;
	char pageadrlen;
	unsigned long IO_ADDR;  /* address to access the 8 I/O lines to the flash device */
	unsigned long totlen;
	uint oobblock;  /* Size of OOB blocks (e.g. 512) */
	uint oobsize;   /* Amount of OOB data per block (e.g. 16) */
	uint eccsize;
};

struct nand_flash_dev {
	char name[64];
	int manufacture_id;
	int model_id;
	int chipshift;
	char page256;
	char pageadrlen;
	unsigned long erasesize;
};

struct jffs2_unknown_node
{
	/* All start like this */
	__u16 magic;
	__u16 nodetype;
	__u32 totlen; /* So we can skip over nodes we don't grok */
	__u32 hdr_crc;
} ;// __attribute__((packed));


/*
 * Definition of the out of band configuration structure
 */
struct nand_oob_config {
	int ecc_pos[6];		/* position of ECC bytes inside oob */
	int badblock_pos;	/* position of bad block flag inside oob -1 = inactive */
	int eccvalid_pos;	/* position of ECC valid flag inside oob -1 = inactive */
};


//********************** Local Function **********************
#ifdef __NANDFLASH
	#define EXTERN
#else
	#define EXTERN	extern
#endif

ulong nand_init(void);
int NandReadData(u32 dwRamAddr,u32 dwNandAddr,u32 dwLen);
int NandWriteData(u32 dwNandAddr,u32 dwRamAddr,u32 dwLen);
int NandErase(ulong ofs, ulong len);

#undef EXTERN


//********************** Extern Variable **********************



//********************** Extern Function **********************


//*****************************************************************
#endif

⌨️ 快捷键说明

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