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

📄 c2188.c

📁 Flash Low Level Driver Code
💻 C
📖 第 1 页 / 共 4 页
字号:

/******************************************************************************
                  NAND_DataInput

Function:       void NAND_DataInput(dataWidth ubData)
Arguments:      ubData - is the data to be issued to the NAND.
Return Value:   na 			
Description:    This function issues an input to the flash and control the
                specific hardware signals

******************************************************************************/
void NAND_DataInput(dataWidth ubData) {
 
    /*to be implemented */  
    
}

/******************************************************************************
                  NAND_DataOutput

Function:       ubyte NAND_DataOutput()
Arguments:      na
Return Value: 	return the data readed from the flash		
Description:    This function get a data from the flash and control the
                specific hardware signals
******************************************************************************/
dataWidth NAND_DataOutput() {
 
    /*to be implemented */  
}

/**************  NAND_DataOutput ***************/


/******************************************************************************
                  NAND_Close

Function:       void NAND_Close()
Arguments:      na
Return Value:   na
Description:    This function is called after an operation on the NAND is 
                completed.               
******************************************************************************/
void NAND_Close() {
 
    /*to be implemented */  
    
}
/**************  NAND_Close ***************/








/****************************************************************************

		   /////////////////////////////////////////////
		   /////// HARDWARE INDEPENDENT FUNCTION ///////
		   /////////////////////////////////////////////
		   			
****************************************************************************/



/******************************************************************************
                    NAND_ReadStatusRegister

Function:         ubyte NAND_ReadStatusRegister()
Arguments:        na
Return Value:     the status register readed 			
Description:      The PageProgram operation issue a Read Status Register Command 
                  as explained in the datasheet of the 528 byte/264 word page 
                  family.
******************************************************************************/
ubyte NAND_ReadStatusRegister()  {
   ubyte ret;
      
   NAND_Open();
   
   /* Issue Read Status Register command */ 
   NAND_CommandInput((ubyte)0x70);
   
   ret = (ubyte) NAND_DataOutput();
   
   NAND_Close();
   
   /* Return the Status Register */ 
   return ret;
}                        

/**************  NAND_ReadStatusRegister ***************/ 






/******************************************************************************
                  NAND_BlockErase

Function:         NAND_Ret NAND_BlockErase(udword udAddress)
Arguments:       udAddress
                   The address inside the block to erase.
Return Value: 	
                 NAND_FLASH_SIZE_OVERFLOW:
                   The address is not within the flash
                 NAND_PASS
                   The operation are successfully executed
                 NAND_FAIL 
                   The operation are not successfully executed,
Description:     This function issue a Block Erase Command as explained in the
                 datasheet of the 2112 byte/1056 word page family.

******************************************************************************/
NAND_Ret NAND_BlockErase(udword udAddress)
 {
                

    ubyte ubStatus;
    
               
   if ( udAddress >= FLASH_SIZE )
     return NAND_FLASH_SIZE_OVERFLOW;
   
   NAND_Open();
   
   /* Issue Sequential data input command */                          
   NAND_CommandInput((ubyte)0x60);
                                                    

   /* Block Address Insertion */ 
   InsertBlockAddress(udAddress);
   

   /* Issue confirm code command */                          
   NAND_CommandInput((ubyte)0xD0);

   /* wait for ready*/
   ubStatus=waitForReady();
   
  
  NAND_Close();
  if( (ubStatus&(0x80))==0)
  	return ubStatus&(0x80);

  return ubStatus&(0x01);
     
}
/**************  NAND_BlockErase ***************/




/******************************************************************************
                  NAND_PageRead

Function:       NAND_Ret NAND_PageRead(udword *udAddresses, dataWidth *Buffer,
                                            uword numOfChunks, udword *udlength) 

Arguments:      udAddresses:
                  The addresses in the page where read.
                Buffer:
                  Contains the destination buffer to store the data.
                numOfChunks:
                  number of the addresses contained into udAddresses parameter
                udLength:
                  lengths of the data pieces to read
Return Value:   NAND_FLASH_SIZE_OVERFLOW:
                   The address is not within the flash
                NAND_PAGE_OVERFLOW
                   the address is not in the page required
                NAND_PASS
                   The operation are successfully executed
                NAND_FAIL 
                   The operation are not successfully execute			
Description:    The PageRead operation issue a PageRead Command as explained in 
                the datasheet of the 2112bytes/1056 word page family.
                It can execute page read with random data output.

******************************************************************************/                                                            
NAND_Ret NAND_PageRead(udword *udAddresses, dataWidth *Buffer,uword numOfChunks, uword *udLength) 
{
   
   volatile udword udIndex=0;
   ubyte ubStatus;
   uword  i;
	
   
   uword index_next;

   
   /* Control if the address is within the flash */
  for(i=0;i<numOfChunks;i++)
   {
 	   if ( udAddresses[i] >= FLASH_SIZE )
	    return NAND_FLASH_SIZE_OVERFLOW;
	
	   /* check if there is an overflow in main or spare */
	   if ((udLength[i] & 0x8000) != 0) { /* IN SPARE */
          if (( (udAddresses[i] & (0x000003FF<<SHIFT_A8)) + (udLength[i]&0x7FFF) ) > PAGE_SPARE_SIZE) return NAND_FAIL;
       } else /* IN MAIN */
		  if ( ( (udAddresses[i] & (0x000003FF<<SHIFT_A8)) + udLength[i]) > PAGE_SIZE) return NAND_FAIL;

	   /* check if there is an overlapping */
	   for (index_next=i+1; index_next<numOfChunks; index_next++)        
   			
   		    	
		   if (  ((udLength[i] & 0x8000) != 0) && ((udLength[index_next] & 0x8000) != 0)  ) {
   			   	
   			   	if ( ((udAddresses[i] & (0x000003FF<<SHIFT_A8))+(udLength[i]&0x7FFF) ) > (udAddresses[index_next] & (0x000003FF<<SHIFT_A8)) ) return NAND_FAIL;        			

   			} else {
   			   
   			   if (  ((udLength[i] & 0x8000) == 0) && ((udLength[index_next] & 0x8000) == 0)  ) {
   			 		  
   			   		if ( ((udAddresses[i] & (0x000003FF<<SHIFT_A8))+udLength[i]) > (udAddresses[index_next] & (0x000003FF<<SHIFT_A8)) ) return NAND_FAIL;
   			   } else {
   			   
				   if ( ((udLength[i] & 0x8000) == 0) && ((udLength[index_next] & 0x8000) != 0) ){
   			       
   			         if ( ((udAddresses[i] & (0x000003FF<<SHIFT_A8))+udLength[i]) > (udAddresses[index_next] & (0x000003FF<<SHIFT_A8))+PAGE_DATA_SIZE ) return NAND_FAIL;			             
				   } else
					 if ( ((udAddresses[index_next] & (0x000003FF<<SHIFT_A8))+udLength[index_next]) > (udAddresses[i] & (0x000003FF<<SHIFT_A8))+PAGE_DATA_SIZE ) return NAND_FAIL;			             
   			      
   			   }
   			}     
       
		/* check if the addresses refer to the same page */
	   if( (udAddresses[i]&(0x0000FC00 << SHIFT_A8))!=(udAddresses[0]&(0x0000FC00 << SHIFT_A8)))
   			return NAND_DIFFERENT_PAGES;	  
  }

   
   NAND_Open();
   
   	/* page read command */
   NAND_CommandInput((ubyte)0x00);  
   
     
   if((udLength[0]&0x8000)==0x8000){
	   	 InsertSpareAddress(udAddresses[0]);
   }else {
	   	 InsertAddress(udAddresses[0]);
   }
                           
   
   /* Leave Read Status Register mode */
   NAND_CommandInput((ubyte)0x30);

   /* Wait for ready */
   ubStatus=waitForReady();
   
   /* return read mode */
   NAND_CommandInput((ubyte)0x00);
   
   
   
   
   #ifdef DMA_ENABLE

		/* to be implemented */
		
   #endif
   
   
   /* read data */
   #ifndef DMA_ENABLE
   for(i=0;i<((0x7FFF)&udLength[0]);i++)
   {
   		Buffer[udIndex++] = NAND_DataOutput(); 
   }
   #endif
   
   
   
   for(i=1;i<numOfChunks;i++)
   {
	   
       uword count=0;
	  
	   
	   #ifdef DMA_ENABLE
       
       /* to be implemented */ 
       /* wait for availability of DMA channel */
       
       #endif
  
	   /*issue random data output command*/
	   NAND_CommandInput((ubyte)0x05);
	  
		/* insert column address*/  
	    if((udLength[i]&0x8000)==0x8000){
	   	 InsertColumnAddressSpare(udAddresses[i]);
	    }else
	    {
	   	 InsertColumnAddress(udAddresses[i]);
	    }


	   NAND_CommandInput((ubyte)0xE0);
	   
	   /*output the data*/
	   
	   #ifndef DMA_ENABLE
	   for(count=0;count<((0x7FFF)&udLength[i]);count++)
	   {
 
	   	  Buffer[udIndex++] = NAND_DataOutput(); 

	   }
	   #endif
	   
	   #ifdef DMA_ENABLE

			/* to be implemented */
			
	   #endif
    
    }
    
    #ifdef DMA_ENABLE
    {
		/* to be implemented */ 
        /* wait for availability of DMA channel */
       
    #endif
    
    ubStatus=waitForReady();
     
  	NAND_Close();
  
	/* Return Pass or Fail */   
   return (ubStatus&(0x01));

}





/**********************************************************************
					NAND_Terminate_CacheRead					  

                  NAND_PageRead

Function:       void NAND_Terminate_CacheRead(void)

Arguments:      na

Return Value:   na
			
Description:    The terminate cahe read issue the command able to
				terminate the pending cache read asexplained in the
                datasheet of the 2112bytes/1056 word page family.
     

**********************************************************************/
void NAND_Terminate_CacheRead(void)
{
   
	#ifdef DMA_ENABLE
		/* to be implemented */ 
       /* wait for availability of DMA channel */
  	#endif
	NAND_CommandInput((ubyte)0x34);
	SetCacheReadMode(CACHE_READ_NOT_PENDING);
	SetLastAddressInCacheRead(0);
	NAND_Close();
}

/************************NAND_Terminate_CacheRead*********************/




/*******************************************************************************
                  NAND_CacheRead

Function:       NAND_Ret NAND_CacheRead(udword udAddress, dataWidth *Buffer,
                                                                  udword length) 

Arguments:      udAddresses:
                  The addresses of the page where start the cache read.
                Buffer:
                  Contains the destination buffer to store the read data
                length:
                  the length
Return Value:   NAND_FLASH_SIZE_OVERFLOW:
                   The address is not within the flash
                NAND_WRONG_ADDRESS
                   The address is not at the start of a page
                NAND_PASS
                   The operation are successfully executed
                NAND_FAIL 
                   The operation are not successfully execute			
Description:    The CacheRead operation issue a cache read Command as explained 
                in the datasheet of the 2112bytes/1056 word page family.
                This function leav the flash in cache read mode

******************************************************************************/  
NAND_Ret NAND_CacheRead(udword udAddress, dataWidth *Buffer,udword length) 
{
   
   volatile udword udIndex=0;
   ubyte ubStatus; 
   
   

   /* Control if the address is within the flash*/
   if (( udAddress >= FLASH_SIZE )||(udAddress+length>=FLASH_SIZE))
   		 return NAND_FLASH_SIZE_OVERFLOW;
   
   /*test that the address is at the page start*/
   if((udAddress&(0x7FF))>0)
   		return NAND_WRONG_ADDRESS;
   		
   if(GetCacheReadMode()==CACHE_READ_PENDING)
   	NAND_Terminate_CacheRead();

   SetCacheReadMode(CACHE_READ_PENDING);
   SetLastAddressInCacheRead(udAddress);
   
   
   NAND_Open();
   
   	/* page read command */
   NAND_CommandInput((ubyte)0x00);  
   
   InsertAddress(udAddress);                                            
                           
   /*cache read command*/
   NAND_CommandInput((ubyte)0x31);


   /* Wait for ready */
   ubStatus=waitForReady();
   
   /* page read command */
   NAND_CommandInput((ubyte)0x00);  
   
    #ifdef DMA_ENABLE

	   /* to be implemented */ 

   #endif
   
   #ifndef DMA_ENABLE
   /*read data 2112 bytes*/
   for(udIndex=0;udIndex<length;udIndex++)
   {
   		Buffer[udIndex] = NAND_DataOutput(); 
   }
   #endif
   
   SetLastAddressInCacheRead(GetLastAddressInCacheRead()+length);
   return NAND_PASS;
}


/*********************************************************************
                  NAND_CacheReadDataOutput

Function:     NAND_Ret NAND_CacheReadDataOutput(dataWidth* Buffer,udword length)

Arguments:      Buffer:
                  Contains the destination buffer to store the read data
                length:
                  the length
Return Value:   NAND_FLASH_SIZE_OVERFLOW:
                   The address is not within the flash
                CACHE_READ_NOT_POSSIBLE
                   The device had not started the caher read previously
                NAND_PASS
                   The operation are successfully executed
                NAND_FAIL 
                   The operation are not successfully execute			
Description:    The CacheReadDataOutput operation continue to read data duringa 
                cache read as explained in datasheet of the 2112bytes/1056 word 
                page family.
******************************************************************************/ 
NAND_Ret NAND_CacheReadDataOutput(dataWidth* Buffer,udword length)
{
	udword i;
	if(GetCacheReadMode()==CACHE_READ_NOT_PENDING)
		return CACHE_READ_NOT_POSSIBLE;
	
	 /* Control if the address is within the flash*/
   if((GetLastAddressInCacheRead()+length)>=FLASH_SIZE)
   {
   		NAND_Terminate_CacheRead();
   		return NAND_FLASH_SIZE_OVERFLOW;
   }

⌨️ 快捷键说明

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