www.pudn.com > OS.rar > NAND.c, change:2006-12-11,size:3347b


 
#include 	"Typedef.h" 
#include	".\component\GPL162002_Far\include\FileSystem\Nand.h" 
#include	".\component\GPL162002_Far\include\FileSystem\Nand_Oper.h" 
 
INT16 bNandInit = -1; 
 
/************************************************************************/ 
/* NAND_Initial  
func:	 
		对物理器件进行使能 
		使用复位指令,使器件进行强制复位动作 
		初始化 驱动层 的转换表 
 
input:	void 
 
output:	0		成功 
		-1		失败 
    
note:	初始化成功后,设置了一个全局变量 bNandInit  
 
                                                                  */ 
/************************************************************************/ 
INT16 NAND_Initial(void) 
{ 
	 INT16 ret; 
 
	 ret = _Nand_Initial();	 
	 if(ret!=0) 
	 { 
		 bNandInit = -1; 
		 return ret; 
	 } 
	 _Nand_Reset(); 
	 ret = InitMapTable(); 
	 if(ret!=0) 
	 { 
		 bNandInit = -1; 
		 return ret; 
	 } 
	 NAND_PowerOff_init(); 
	 
	 bNandInit = 0; 
	 
	 return 0; 
} 
 
/************************************************************************/ 
/*  
                                                                     */ 
/************************************************************************/ 
INT16 NAND_Uninitial(void) 
{ 
	 if(bNandInit == 0) 
	 { 
		 _NAND_EndOfWrite(); 
		 
		 bNandInit = -1; 
	 } 
 
	 return 0; 
} 
 
/************************************************************************/ 
/*		NAND_GetMemSize 
func:	获得器件的逻辑容量 
input:	void 
output:		  
note:	提供给 U盘时,为了时U盘格式化时,产生的容量与机器格式化时一致 
		增加了特殊的处理 
		 
                                                                 */ 
/************************************************************************/ 
UDWORD NAND_GetMemSize() 
{ 
 
	// new code lanzhu @ [2/13/2006] 电脑格式化,容量不一致 
	if(gFS_USBReadWriteFlag && (Nand_Part0_Size>=UNSP_FS_RESERVED)) 
	{ 
		// 发送给U盘使用时,数值应该与 BPB 
		return (Nand_Part0_Size - UNSP_FS_RESERVED); 
	}	 
 
	return Nand_Part0_Size;				 
} 
 
/************************************************************************/ 
/*  
                                                                     */ 
/************************************************************************/ 
INT16 NAND_ReadSector(UDWORD blkno , UWORD blkcnt ,  UINT32 buf) 
{ 
	return _NAND_ReadSector(blkno , blkcnt , buf); 
} 
 
/************************************************************************/ 
/*		NAND_WriteSector 
func:	往物理介质上写入数据 
input:	 
output:	0		成功 
		其他值	失败 
 
note:	增加了对电脑是否可以格式化的控制 
		当定义了 _PC_UNABLE_FORMAT_UDISK 时,禁止了对逻辑盘 逻辑0 扇的写入动作 
		PC 不能对U盘进行格式化 
   
                                                                     */ 
/************************************************************************/ 
INT16 NAND_WriteSector(UDWORD blkno , UWORD blkcnt ,  UINT32 buf) 
{ 
	int i,ret; 
 
	 if(( Nand_Part0_Mode & DEVICE_WRITE_ALLOW ) == 0) 
	 { 
		 return -1; 
	 } 
 
	// 不是 U盘的话,直接处理 
	if(!gFS_USBReadWriteFlag)  
	{ 
		return _NAND_WriteSector(blkno , blkcnt , buf);		 
	} 
 
	for(ret=0x00, i=0x00; i<blkcnt; i++, blkno++, buf += 0x100) 
	{ 
		if( gFS_USBReadWriteFlag && (blkno == BPB_START_SECTOR) ) 
		{ 
			continue;		 
		}		 
 
		ret = _NAND_WriteSector(blkno,1,buf);	// 每次只写一个扇区	 
 
		if(ret) { break; }		// 失败,直接返回 
	} 
 
	return ret; 
}