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

📄 c2194.c

📁 Flash MLC Low Level Driver Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************** Header File ********************************

   Filename:    AN2194.c
   Description: LLD (Low Level Driver)  for the NAND flash (528 byte/264 word)
                small page family

   Author: STMicroelectronics
   Copyright:(C)STMicroelectronics
   Version:  Release 1.0
  
   You have a license to reproduce, display,perform,produce derivative works of,
   and distribute (in original or modified form) the Program, provided that you
   explicitly agree to the following disclaimer:

   THIS PROGRAM IS PROVIDED "AS IT IS" WITHOUT WARRANTY OF ANY KIND, EITHER
   EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTY
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
   AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
   PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
   REPAIR OR CORRECTION.
********************************************************************************
********************************************************************************

   Version History.

   Ver.		No	Date     Comments
   
   Alpha	1.0	10/2003  Initial Alpha Release of the driver
   Beta   	1.0	07/2004  Not all Tests performed.
   Release	1.0	07/2005  First release of Software - all bugs fixed 

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

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

#include "C2194.h"

                       


/*******************************************************************************
                           HARDWARE DEPENDENT LAYER
		                       Basic functions
*******************************************************************************/




/******************************************************************************
                  NAND_Open

Function:      void NAND_Open()

Arguments:     None

Return Value:  na

Description:   This function is called before a new operation on the NAND starts.
               It assert the E of the NAND device. After any operations (such as
               NAND_BlockErase, NAND_PageProgram, etc.) ends the NAND_close
               function must be called to deassert the E.
               This function must be implemented when E don't care option and
               can be not implemented otherwise.

******************************************************************************/
void NAND_Open() {
 /* to do*/
}

/*******************************  NAND_Open   *********************************/


/*******************************************************************************
                          NAND_CommandInput

Function:       void NAND_CommandInput(ubyte ubCommand)

Arguments:      ubCommand: is the command to be issued to the NAND.

Return Value:   na

Description:    This function issues a command to the flash and control the
                specific hardware signals between the MCU and the device.
                
*******************************************************************************/
void NAND_CommandInput(ubyte ubCommand) {
 
 /* to do */
}

/************************ NAND_CommandInput ***********************************/




/******************************************************************************
                  NAND_AddressInput

Function:       void NAND_AddressInput(ubyte ubAddress)

Arguments:      ubAddress: is the address to be issued to the NAND.

Return Value:   na

Description:    This function issues an address byte to the flash and control
                the specific hardware signals between the MCU and the device

*******************************************************************************/
void NAND_AddressInput(ubyte ubAddress) {
 
/* to do*/
}
/*************************  NAND_AddressInput *********************************/



/******************************************************************************
                    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 do */
}

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



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

Function:       dataWidth 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 do */

}
/****************************  NAND_DataOutput ********************************/



/******************************************************************************
                  InsertAddress

Function:       void InsertAddress(udword address)

Arguments:      udAaddress:   the address that we want to issue

Return Value: 	na		

Description:    This function perform the data insertion in 4 cycles
                (row & column address) or 3 cycle for (128,256 mbit device)
******************************************************************************/
void InsertAddress(udword udAddress) {
/* to do */
}


/******************************************************************************
                  InsertColumnAddress

Function:       void InsertColumnAddress(udword udAddress)

Arguments:      udAddress:  the address that we want to issue

Return Value: 	na		

Description:    This function perform the address insertion of bytes 
				that represent the column in the page
******************************************************************************/
void InsertColumnAddress(udword udAddress) {
 /*to do*/
}

/************************** InsertColumnAddress *******************************/




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

Function:       void NAND_Close()

Arguments:      na

Return Value:   na

Description:    This function is called after an operation on the NAND is completed.
                It deassert the E of the NAND device.
                This function must be implemented when E don't care option and
                can be not implemented otherwise.
******************************************************************************/
void NAND_Close() {
  /* to do */
}

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




/*******************************************************************************
                waitForReady

Function:       ubyte waitForReady()

Arguments:      na

Return Value:   Return the value of the status register

Description:    This function is called after an operation on the NAND is asserted.
		        The function wait until the NAND is ready.
		        NOTE: after return the NAND is lived in status register mode
               
*******************************************************************************/

ubyte waitForReady(){

   /* to do */
}



/******************************************************************************
                           HARDWARE INDIPENDENT LAYER
                            Nand operation functions
******************************************************************************/                             
      



/******************************************************************************
                  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 is successfully executed
                 NAND_FAIL: The operation is not successfully executed,

Description:     This function issue a Block Erase Command as explained in the
                 datasheet of the 528 byte/264 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);

  InsertColumnAddress(udAddress);

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

   /* wait for ready*/
  ubStatus=waitForReady();

  NAND_Close();
  return ubStatus&(0x01);

}
/*********************************  NAND_BlockErase ***************************/




/******************************************************************************
                  NAND_CopyBack

Function:       NAND_Ret NAND_CopyBack(udword udSourceAddr, udword udDestinationAddr)

Arguments:      udSourceAddr: The address of the source page to copy.
                udDestinationAddr: The address of the destination page.

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.
                NAND_WRONG_ADDRESS : The pages are not in the same half of the
                                     flash.

Description:    This function issue a CopyBack Command as explained in the
                datasheet of the 528 byte/264 word page family. 
                The Copy Back Program operation is used to copy the data stored 
                in one page and reprogram it in another page. The operation does 
                not require external memory, so it is faster and more efficient
                than the standard operations because the time consuming phases 
                of reading out the data and then reloading the data to be programmed
                are not required. The operation is particularly useful in garbage
                collection routine .

*******************************************************************************/
NAND_Ret NAND_CopyBack(udword udSourceAddr, udword udDestinationAddr){
   
 ubyte ubStatus;
   
   NAND_Open();

   /* Control if the address is within the flash*/
   if ((udSourceAddr  >= FLASH_SIZE) ||(udDestinationAddr  >= FLASH_SIZE))
      return NAND_FLASH_SIZE_OVERFLOW;
   
   #ifdef NAND512RW3A
      /* Check if A25 is the same for the two addresses */
   if ( (udSourceAddr >> (24 + HALF_PAGE_POINTER)) !=
        (udDestinationAddr >> (24 + HALF_PAGE_POINTER)) )
      return NAND_WRONG_ADDRESS;
   #endif
  
  #ifdef NAND256W3A
    /* Check if A24 is the same for the two addresses */
   if((udSourceAddr&(0x01000000))!=(udDestinationAddr&(0x01000000)))
   	return NAND_WRONG_ADDRESS;
   #endif

   #ifdef NAND256W4A
   /* Check if A23 is the same for the two addresses */
   if((udSourceAddr&(0x800000))!=(udDestinationAddr&(0x800000)))
   	return NAND_WRONG_ADDRESS;
   #endif

   #ifdef NAND128W3A
   /* Check if A23 is the same for the two addresses */
   if((udSourceAddr&(0x800000))!=(udDestinationAddr&(0x800000)))
   	return NAND_WRONG_ADDRESS;
   #endif

   #ifdef NAND128W4A
   /* Check if A22 is the same for the two addresses */
   if((udSourceAddr&(0x400000))!=(udDestinationAddr&(0x400000)))
   	return NAND_WRONG_ADDRESS;
   #endif


   #ifdef NAND01GRW3A
   /* Check if A25 A26 is the same for the two addresses */
   if((udSourceAddr&(0x06000000))!=(udDestinationAddr&(0x06000000)))
   	return NAND_WRONG_ADDRESS;
   #endif
   
   #ifdef NAND512Stacked
   /* Check if A24 A25 is the same for the two addresses */
   if((udSourceAddr&(0x03000000))!=(udDestinationAddr&(0x03000000)))
   	return NAND_WRONG_ADDRESS;
   #endif            
   
   /* Set the address pointer to 1st half page*/                          
   NAND_CommandInput((ubyte)0x00);         
   
   /*insert the source address*/                                                                                  
   InsertAddress(udSourceAddr);
   
   /* Wait for ready */
   NAND_CommandInput((ubyte)0x70);
   ubStatus = NAND_DataOutput();
   while ( (ubStatus&(0x40)) != 0x40 )
    ubStatus = NAND_DataOutput();

   /* Issue Copy-Back Data Input Command*/
   NAND_CommandInput((ubyte)0x8A);

   /*send the address*/
   InsertAddress(udDestinationAddr);
                                         
   /* Issue the Program Command*/
   NAND_CommandInput((ubyte)0x10);
                                            
                                                                               
   /* Wait for ready */
   NAND_CommandInput((ubyte)0x70);
   ubStatus = NAND_DataOutput();
   while ( (ubStatus&(0x40)) != 0x40 )
    ubStatus = NAND_DataOutput();
     
  
   NAND_Close();
   
   /* Return Pass or Fail */
   return (ubStatus&(0x01)); 
}
/*****************************  NAND_CopyBack *********************************/
                                                                   

⌨️ 快捷键说明

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