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

📄 nandtest.c

📁 Nand Flash low driver。
💻 C
字号:

/***************************************************************
Copyright(c) 2002 VIA Technologies, Inc. All Rights Reserved.

Filename: Main.C

Description:
platform : fpga_top.5-2-19-18.bit

*****************************************************************/
#include <stdio.h>
#include "Common.h"
#include"FALUserDirective.h"
#include"TranslationModule.h"
#include "NAND_DRV.h"
#include "NandFAT.h"





#if 0
UINT8 ReadBuff[512] ;
UINT8 WriteBuff[512] ;
UINT8 ReadOOB[16] ;
UINT8 WriteOOB[16] ;
#endif

int NandTest()
{
	NFTL_Return res;
	UINT8 Buffer[SECTOR_SIZE];
	UINT32 VirtualAddress = 0;
	UINT32 Index, i;
	UINT32 FileSize;
	UINT8 ident = 1;

	UINT32 pages ;
	UINT32 offsets;
	UINT8 *pWriteBuf;
	UINT32 udAddress = 0 ;

	NAND_Init();
#if 0
	res = NandChipFastErase();
	if (res != 1)
	{
		ident = 0 ;
	}
#endif
	//res = NandFATFormat();
	//res = NFTL_Initialize();
	if (res == FAILURE)
	{
		ident = 0 ;
	}
#if 1
	res = NandFATFormat();
	if (res == FAILURE)
	{
		ident = 0 ;
	}
	res = NFTL_Unmount();
	if (res != SUCCESS)
	{
		ident = 0 ;
	}
#endif
#if 0
res =  NandInitializeFat();//gNandFATSYS
if (res == FAILURE)
{
ident=0 ;
}

#endif
#if 1
	//Suppose to write a file containing as data 0xAA
	memset(Buffer,0xAA,SECTOR_SIZE);
	FileSize = 200;

	for (i = 0; i < 512; i++)
		Buffer[i] = i ;
	//initialize the FileSize equal to 36 sectors (the file dimension in byte is //35x512byte= 18kbytes)

	//write file in Flash
	for (VirtualAddress = 0; VirtualAddress < FileSize; VirtualAddress ++)
	{
		//write Sector
		Buffer[0] = Buffer[0] + VirtualAddress ;
		res = NFTL_WriteSector(VirtualAddress,Buffer);
		if (res != SUCCESS)
		{
			ident = 0 ;
		}
	}
	// read the file previously written to verify if it is correct
	for (VirtualAddress = 0; VirtualAddress < FileSize; VirtualAddress ++)
	{
		//write Sector
		res = NFTL_ReadSector(VirtualAddress,Buffer);
		if (res != SUCCESS)
		{
			ident = 0 ;
		}
	}
	for (i = 0; i < 512; i++)
		Buffer[i] = i + 3 ;
	// Now suppose to re-write the file
	for (VirtualAddress = 0; VirtualAddress < FileSize; VirtualAddress ++)
	{
		//write Sector
		Buffer[0] = Buffer[0] + VirtualAddress ;
		res = NFTL_WriteSector(VirtualAddress,Buffer);
		if (res != SUCCESS)
		{
			ident = 0 ;
		}
	}
	//To erase the old data generated by re-write operation the user can call Defrag
	res = Defrag();
	if (res != SUCCESS)
	{
		ident = 0 ;
	}
	//Call Unmount STNFTL to free the space allocated in RAM to manage the data
	res = NFTL_Unmount();
	if (res != SUCCESS)
	{
		ident = 0 ;
	}

	return 0;
#endif
}


⌨️ 快捷键说明

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