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

📄 nand.h

📁 这是一个基于硬件平台s3c44B0和操作系统为ucos的nandflash的程序
💻 H
字号:

#include "def.h"

#ifndef S3C44B0_NAND_H
#define S3C44B0_NAND_H


#define BLOCK_NUM			1024
#define PAGES_PER_BLOCK		32
#define BYTES_PER_PAGE		512
#define SPARE_SIZE			16

#define CMD_READ		0x00        //  Read
#define CMD_READ1		0x01        //  Read1
#define CMD_READ2		0x50        //  Read2
#define CMD_READID		0x90        //  ReadID
#define CMD_WRITE		0x80        //  Write phase 1
#define CMD_WRITE2		0x10        //  Write phase 2
#define CMD_ERASE		0x60        //  Erase phase 1
#define CMD_ERASE2		0xd0        //  Erase phase 2
#define CMD_STATUS		0x70        //  Status read
#define CMD_RESET		0xFF        //  Reset

#define VALIDADDR		(0x5)
#define GPC_DATA		(0x01D20014)

#define READ_REG_USHORT(p) 	(*(volatile UINT16 *)(p))
#define WRITE_REG_USHORT(p,v) 	(*(volatile UINT16 *)(p)) = (v)
#define READ_REG_ULONG(p)  	(*(volatile UINT32 *)(p))
#define WRITE_REG_ULONG(p,v) 	(*(volatile UINT32 *)(p)) = (v)

#define WAIT_NAND_READY()	{ while(!(READ_REG_ULONG(GPC_DATA) & (1<<10))) ;}

#define NAND_CE_HIGH()		(WRITE_REG_ULONG(GPC_DATA, (READ_REG_ULONG(GPC_DATA) | (1<<14))))
#define NAND_CE_LOW()		(WRITE_REG_ULONG(GPC_DATA, (READ_REG_ULONG(GPC_DATA) & 0xFFFFBFFF)))

#define NAND_CLE_HIGH()		
#define NAND_CLE_LOW()			

#define NAND_ALE_HIGH()			
#define NAND_ALE_LOW()			


/* Nand Flash is connected to ROM Bank 1 */
#define NAND_IO		(*(volatile UINT8 *)(0x02000000))
#define CMD_PORT	(*(volatile UINT8 *)(0x02000004))
#define ADDR_PORT	(*(volatile UINT8 *)(0x02000008))	


/*	
	Reset the Nand Flash, and init the CPU port.
*/
UINT32 NandInit(void);

void NandReset(void);


/*	
	Check whether the block is bad or not.
	Return 1 if it is a bad block, return 0 if the block is OK. 
*/
UINT32 IsBadBlock(UINT32 BlockID);


/*	Erase a block, the BlockID is zero indexed.
	
	Return non-zero if the erase operation is success, or return zero 
	if the operation is not success.
*/
UINT32 EraseBlock(UINT32 BlockID);


/*	Read the device ID of the NAND
	The Samsung K9F2808U0B is 0x73 and K9F2808Q0B is 0x33
*/
int ReadDeviceID(void);


/*	Read a page, the page is specified by the BlockID and the Page ID,
	both of which are zero based. pData point to a 512bytes buffer.
	
	Return non-zero if success, and pData contants the return data.
*/ 	
UINT32 ReadPage(UINT32 BlockID,UINT32 PageID,char *pData);
UINT32 Flash_read(void *pBuffer,UINT32 Sector,UINT32 Unit);

/*	Program a page, the page is specified by the BlockID and the PageID,
	both of which are zero based. pData point to a 512bytes buffer which
	contants the data to be written to the nand page.
	
	Return non-zero if success, return zero if not success.
*/
UINT32 WritePage(UINT32 BlockID,UINT32 PageID,char *pData);
UINT32 Flash_write(void *pBuffer,UINT32 Sector,UINT32 Unit);

#endif //S3C44B0_NAND_H

⌨️ 快捷键说明

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