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

📄 drv_nf.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
📖 第 1 页 / 共 4 页
字号:
	unsigned char	 ReadStatus;
	unsigned char  RetVal;
	unsigned short pageAddr,blockAddrL,blockAddrH;
	
	#ifdef	DEBUG
		if((ulAddress < 0 ) || ( ulAddress >= (MAX_BLK_NUM * MAX_PG_NUM * PG_SIZE) ))	
  		return FLASH_PAR_ERR;
	#endif
	
  	pageAddr=(unsigned short)((ulAddress & 0x0001fe00)>>9);     /*A16-9 */
	blockAddrL=(unsigned short)((ulAddress & 0x01fe0000)>>17);  /*A24-17*/
	blockAddrH=(unsigned short)((ulAddress & 0x0e000000)>>25);  /*A27-25*/
		
	SET_CLE_H;	/* set CLE high*/

	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=AUTO_ERASE_CMD;/* write command*/
	
	SET_CLE_L;		/* set CLE low*/
	
	SET_ALE_H;		/* set ALE h*/
	
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=pageAddr;	  	 /* send page address*/
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=blockAddrL;		 /* send block l address*/
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=blockAddrH;   	/* send block h address*/
	
	SET_ALE_L;		/*set ALE L*/
	
	SET_CLE_H;		/* set CLE high*/
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=ERASE_CMD;
	
  	SET_CLE_L;		/*set CLE l*/
	
	asm("nop");
  	asm("nop");  
  	asm("nop"); 
  	asm("nop");
  	asm("nop");   
  	asm("nop"); 
  	asm("nop");
 	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop");  
 	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
 	asm("nop"); 
  	do{}	
 	while (!CHECK_BUSY);		/*wait R/#B to high*/
  
	
	SET_CLE_H;			/* set CLE high*/
	
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=READ_STATUS_CMD;
	
	SET_CLE_L;			/*set CLE l*/
	
	ReadStatus=*(volatile unsigned char*)NAND_Flash_BASE_ADDRESS;

	if (ReadStatus & 0x1)
		return FLASH_ERASE_ERR;
	
 	 return FLASH_SUCCESS;

}

//---------------------------------------------------------------------------------
//  	Function name 		: fnSMC_ReadID	
// 	Function description	: read ID of SMC
//				  
//		 
//      Parameters
//         Input  		: void
//         Output 		:
//         I/O    		: void
//      
//      Return value 		: void	
//							
//							
//	Global variable 	:void	
//--------------------------------------------------------------------------------- 
void fnSMC_ReadID(unsigned char* pID_Data){

	unsigned char Cnt;

  	SET_SMC_CE_L;		/*set SMC CE H*/
	
	SET_CLE_H;		/* set CLE H*/
	
	*( volatile unsigned char*)NAND_Flash_BASE_ADDRESS=READ_ID;	/* read id 1*/
	
	SET_CLE_L;		/* set CLE low*/
	
	SET_ALE_H;		/* set ALE h*/
	
	*( volatile unsigned char*)NAND_Flash_BASE_ADDRESS=READ_ID_ADDR;	/* send  address*/
	
	SET_ALE_L;		/*set ALE L*/

    	asm("nop");
  	asm("nop");  
  	asm("nop"); 
  	asm("nop");
  	asm("nop");   
  	asm("nop"); 
  	asm("nop");
 	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop");  
 	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
 	asm("nop"); 
  	do{}	
 	while (!CHECK_BUSY);		/*wait R/#B to high*/
  
  	for (Cnt = 0; Cnt <5; Cnt++){
		  *pID_Data++=*(volatile unsigned char*)NAND_Flash_BASE_ADDRESS;
 	 }
		  
  	SET_SMC_CE_H;		/*set SMC CE H*/
	
	return ;

}


//---------------------------------------------------------------------------------
//  	Function name 		: fnFlash_ReadID
// 	Function description	: read ID of nand flash
//				  
//		 
//      Parameters
//         Input  		: void
//         Output 		:
//         I/O    		: void
//      
//      Return value 		: void	
//							
//							
//	Global variable 	:void	
//---------------------------------------------------------------------------------      
unsigned char fnFlash_ReadID(unsigned char* pID_Data){

	unsigned char Cnt;
	
	SET_CLE_H;		/* set CLE H */
	
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=READ_ID;	/* read id 1*/
	
	SET_CLE_L;		/* set CLE low*/
	
	SET_ALE_H;		/* set ALE h*/
	
	*(volatile unsigned short*)NAND_Flash_BASE_ADDRESS=READ_ID_ADDR;	/* send  address*/
	
	SET_ALE_L;		/*set ALE L*/

    	asm("nop");
  	asm("nop");  
  	asm("nop"); 
  	asm("nop");
  	asm("nop");   
  	asm("nop"); 
  	asm("nop");
 	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop");  
 	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
  	asm("nop"); 
  	asm("nop");
  	asm("nop"); 
 	asm("nop"); 
  	do{}	
 	while (!CHECK_BUSY);		/*wait R/#B to high*/

  	for (Cnt = 0; Cnt <5; Cnt++){
	  	*pID_Data++=*(volatile unsigned char*)NAND_Flash_BASE_ADDRESS;
  	}
	
	return FLASH_SUCCESS;

}	


//---------------------------------------------------------------------------------
//  	Function name 		: Flash_Load_Init	
// 	Function description	: called by fnFlshErase, every time download srf/sa file from debug tool 
//				  must call fnFlshErase.
//		 
//      Parameters
//         Input  		: void
//         Output 		:
//         I/O    		: void
//      
//      Return value 		: unsigned char		
//							
//							
//	Global variable 	:void	
//--------------------------------------------------------------------------------- 
void Flash_Load_Init(void){
	
	/*Initialize count for fnFlashLoad*/
	databuf_cnt=0;
	fls_ldcnt=0;
	checkSum=0x0;
	page_cnt=0;

}	

//---------------------------------------------------------------------------------
//  	Function name 		: fnFlshLoad	
// 	Function description	: called by debug tool to download srf/sa file  
//				 
//		 
//      Parameters
//         Input  		: void
//         Output 		:
//         I/O    		: void
//      
//    	Return value 		:unsigned char	FLASH_SUCCESS		write Success
//						FLASH_ECC_ERROR		ecc check error
//						FLASH_PAR_ERR		parameter error
//						FLASH_WRITE_ERR		write error		
//							
//	Global variable 	:void	
//--------------------------------------------------------------------------------- 
unsigned char  fnFlshLoad(unsigned long ulPA, unsigned long ulData1, unsigned long ulData2){
	
	
	int i;	
	unsigned char  RetVal,TempData;
	unsigned long	 TempAddr;
	

	//if (ulPA<(ulOldPA+8))
	//	tmp_buf[p++]=ulPA;
	
	//ulOldPA=ulPA;	
	fls_ldcnt++;
	
	//ulData1;
	TempData=(unsigned short)(ulData1&0x00ff);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
	
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	TempData=(unsigned short)((ulData1&0xff00)>>8);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
	
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	
	TempData=(unsigned short)((ulData1&0xff0000)>>16);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
	
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	TempData=(unsigned short)((ulData1&0xff000000)>>24);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
	
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	//ulData2
	TempData=(unsigned short)(ulData2&0x00ff);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
		
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	TempData=(unsigned short)((ulData2&0xff00)>>8);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;

	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	TempData=(unsigned short)((ulData2&0xff0000)>>16);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
	
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	TempData=(unsigned short)((ulData2&0xff000000)>>24);
	write_buf[databuf_cnt++]=TempData;
	checkSum+=TempData;
	
	#ifdef BOOT_16
		// fill high 8 bit
		write_buf[databuf_cnt++]=0x00;
	#endif
	
	#ifdef BOOT
		if (!(fls_ldcnt%2)){//>16 calc checksum
			#ifdef BOOT_L05
				write_buf[databuf_cnt++]=~checkSum;
				
			#else
				
				write_buf[databuf_cnt++]=checkSum;
			#endif
			
			#ifdef BOOT_16
				// fill high 8 bit
				write_buf[databuf_cnt++]=0x00;
			#endif
		
			checkSum=0;
		}
	#endif 
	if (fls_ldcnt>=MAX_LD_CNT){
		#ifdef BOOT
			#ifdef BOOT_16
				memset(&write_buf[databuf_cnt],0xff,2); //only 255 
		
			#else
				memset(&write_buf[databuf_cnt],0xff,257); //only 255 
			#endif
			
		#endif 
		TempAddr=ulStAddr+page_cnt*PG_SIZE;
		
	
		RetVal=DOWNLOAD_FUN(TempAddr & 0xfffffe00,(unsigned char*)write_buf);
		
		databuf_cnt=0;
		fls_ldcnt=0;
		page_cnt++;
		
		
	}
	return FLASH_SUCCESS;
	
	


}
	

//---------------------------------------------------------------------------------
//  	Function name 		: fnFlshErase	
// 	Function description	: called by debug tool to erase srf/sa file  
//				 
//		 
//      Parameters
//         Input  		: unsigned short ulCtrlReg	the start destination address where need to write data to
//				  unsigned short ulBlockBgn	start block (base on 1)
//				  unsigned short ulBlockEnd	end block (base on 1)
//         Output 		:
//         I/O    		: void
//      
//      Return value 		:unsigned char	FLASH_SUCCESS		Success
//						FLASH_PAR_ERR		parameter error
//						FLASH_ERASE_ERR		erase error							
//	Global variable 	:void	
//--------------------------------------------------------------------------------- 
unsigned char  fnFlshErase( unsigned long ulCtrlReg, unsigned long ulBlockBgn, unsigned long ulBlockEnd ){
	
	unsigned short	Cnt;
	unsigned char   RetVal;
	unsigned short	ulEnd,ulBeg;
	unsigned long	 TempAddr;
	
	
	#ifdef	DEBUG
		if( ulBlockBgn >= MAX_BLK_NUM )	/*start block parameter is NG */
			return FLASH_PAR_ERR;
		else if(( ulBlockEnd<ulBlockBgn ) || ( ulBlockEnd >MAX_BLK_NUM ))	/*end block parameter is NG*/
			return FLASH_PAR_ERR;
	#endif
	
	if( (long)ulBlockBgn == -2){
		TempAddr=ulStAddr+page_cnt*PG_SIZE;

		RetVal=DOWNLOAD_FUN(TempAddr & 0xfffffe00,(unsigned char*)write_buf);
		if( RetVal == FLASH_SUCCESS )
			RetVal = FLASH_BUF_FLUSH;
		databuf_cnt=0;
		fls_ldcnt=0;
		page_cnt++;
		return RetVal;
	}

	/* area 6 for internal access , other external area, little endian*/
	*(volatile unsigned short*)0x48132=0x0200;
	/* area 6 1 wait cycle, area5 0 wait cycle*/
	*(volatile unsigned short*)0x4812a=0x0100;
	*(volatile unsigned char*)0x48131=0x04;
	Flash_Load_Init();
	ulStAddr=ulCtrlReg;
	FLASH_INIT();


	//for (Cnt=0;Cnt<1024;Cnt++)	//for test 
	//	tmp_buf[Cnt]=0;
	//p=0;
	//parameter check
	if( !ulBlockBgn ){
		ulEnd=MAX_BLK_NUM;
		ulBeg=1;
	}
	else {
		ulEnd=ulBlockEnd;
		ulBeg=ulBlockBgn;
	}
	for (Cnt=ulBeg-1;Cnt<ulEnd; Cnt++){
		RetVal=ERASE_FUN(Cnt*BLK_SIZE);
		if (RetVal!=FLASH_SUCCESS)
			return RetVal;
	}
				
	return FLASH_SUCCESS;
	
}
	

⌨️ 快捷键说明

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