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

📄 flash_mt.h

📁 对于DSP自引导程序的一个实例
💻 H
字号:
/***********************************************************************/                          
/* Copyright Intel Storage Technology, Inc.         */                          
/* Example "C" language Driver of INTEL_28F016 2M X 8                    */                          
/* Multi-Purpose Flash  */                                                                         
/* Zhu Lei Institute of PRAI.                      */                          
/*                                                                     */                          
/* Revision 1.0, Apr. 15, 2005                                         */                       
/*                                                                     */                          
/* This file requires these external "timing"  routines:               */                          
/*                                                                     */                          
/***********************************************************************/     

#include "datatype.h"


#include "EMIF.c"

#define FLASH_READ_ARRAY     0xFF
#define FLASH_LOAD		     0x40
#define FLASH_ERASE_SETUP  	 0x20
#define FLASH_ERASE_CONFIRM	 0xD0
#define FLASH_PROG_SUSPEND	 0xB0
#define FLASH_PROG_RESUME	 0xD0
#define FLASH_ERASE_SUSPEND	 0xB0
#define FLASH_ERASE_RESUME	 0xD0
#define FLASH_READ_STATUS    0x70
#define FLASH_CLEAR_STATUS   0x50
#define FLASH_READ_SID		 0x90
//#define FLASH_START		     (FLASH_START_ADR)

//#define FALSE                   0
//#define TRUE                    1
#define BLOCK_SIZE              8192L
//#define MAIN_BLOCK_SIZE              65536L  /* Must be 64K bytes for 28F016  */

#define INTEL_ID                0x89    /* INTEL Manufacturer's ID code  */
#define INTEL_28F016            0xD1    /* INTEL28F016 device code       */

//typedef unsigned char           BYTE;
//typedef unsigned int            WORD;

int Check_INTEL_28F016();
void Program_One_Block(BYTE   *Src,    BYTE   *Dst);
void Erase_One_Block(BYTE   *Dst);
void Program_One_Byte (BYTE SrcByte,    BYTE   *Dst);
void Program_N_Block(BYTE   *Src,    BYTE   *Dst,	int num);
void Program_N_Byte (BYTE 	*Src,    BYTE   *Dst,	int num) ;

//void delay_msec(short msec);                                                                       

//void delay_20nsec(short nsec);
/************************************************************************/
/* PROCEDURE:   Check_INTEL_28F016                                      */
/*                                                                      */
/* This procedure decides whether a physical hardware device has a      */
/* INTEL28F016 2M X 8 Multi-Purpose Flash installed or not.             */
/*                                                                      */
/* Input:                                                               */
/*          None                                                        */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates a INTEL28F016                       */
/*          return FALSE: indicates not a INTEL28F016                   */
/************************************************************************/


int Check_INTEL_28F016()
{
        char *Temp;
        char Intel_id1;
        char Intel_id2;
        int  ReturnStatus;
                       
        /*  Issue the Software Product ID code to 28F016 */
        Temp = (char *)FLASH_START_ADR;
        *Temp = FLASH_READ_SID;         /* write data 0x90 to the address */

        /* Read the product ID from 28F016 */
        Temp  = (char *)FLASH_START_ADR; 
        Intel_id1  =  *Temp;              /* get first ID byte                */
        Temp  = (char *)FLASH_START_ADR+1; 
        Intel_id2  =  *Temp;              /* get first ID byte                */

        /* Determine whether there is a INTEL 28F016 installed or not */	
        if ((Intel_id1 == (char)INTEL_ID) && (Intel_id2 == (char)INTEL_28F016))
                ReturnStatus = TRUE;
        else
                ReturnStatus = FALSE;
        printf("the Manufacturer ID is %x\n",Intel_id1);
        printf("the Device ID is %x\n",Intel_id2);
        /* Write FFH after last operation to reset device to ready array mode*/
        Temp = (char *)FLASH_START_ADR;
        *Temp = FLASH_READ_ARRAY;         /* write data 0xFF to the address */

        return(ReturnStatus);
}

/************************************************************************/
/* PROCEDURE:   Erase_One_Block                                         */
/*                                                                      */
/* This procedure can be used to erase a total of 65536 bytes.          */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address where the erase operation starts    */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/
void Erase_One_Block(BYTE   *Dst)
{
   char *Temp;
   char INTEL_status;
   volatile char SR_7 = 0;
   
   /*  Issue the Block Erase command to 28F016  */
   	Temp = (char *)FLASH_START_ADR;
    *Temp = FLASH_ERASE_SETUP;         /* write data 0x20 to the address */
    *Dst = FLASH_ERASE_CONFIRM;         /* write data 0xD0 to the address */
    
    /* Read the status register to inquery bit7 */
    *Temp = FLASH_READ_STATUS;         /* write data 0x70 to the address */
    while(SR_7 == 0)
    {
      INTEL_status = *(char *)FLASH_START_ADR;
      SR_7 = INTEL_status & 0x80;
    }

   	/* Write FFH after last operation to reset device to ready array mode*/
    Temp = (char *)FLASH_START_ADR;
    *Temp = FLASH_READ_ARRAY;         /* write data 0xFF to the address */
}

/*************************************************************************/
/* PROCEDURE:   Program_One_Block                                        */
/*                                                                       */
/* This procedure can be used to program a total of 65536 bytes of data  */
/* to the INTEL28F016.                                                    */
/*                                                                       */
/* Input:                                                                */
/*           Src     SOURCE address containing the data which will be    */
/*                   written to the 28F016                              */
/*           Dst     DESTINATION address which will be written with the  */
/*                   data passed in from Src                             */
/*                                                                       */
/* Output:                                                               */
/*           None                                                        */
/*************************************************************************/





void Program_One_Block(BYTE   *Src,    BYTE   *Dst)
{
        unsigned char   *SourceBuf;
        unsigned char   *DestBuf;
        int Index;
        char *Temp;

        SourceBuf = Src;
        DestBuf = Dst;

        Erase_One_Block(Dst);         //erase the block first 
        	
        for (Index = 0; Index < BLOCK_SIZE; Index++)
        {
			Program_One_Byte(*SourceBuf, DestBuf++);
			SourceBuf++;
        }
        
      // Write FFH after last operation to reset device to ready array mode
        Temp = (char *)FLASH_START_ADR;
        *Temp = FLASH_READ_ARRAY;         // write data 0xFF to the address 
}


	void Program_N_Block(BYTE   *Src,    BYTE   *Dst	,int num)
	{
		unsigned char   *SourceBuf;
        unsigned char   *DestBuf;
		int i;
		
		SourceBuf = Src;
        DestBuf = Dst;
        
		for(i=0;i<num;i++)
		
			Program_One_Block((BYTE *)(SourceBuf+i*BLOCK_SIZE), (BYTE *)(DestBuf+i*BLOCK_SIZE));
	}




void Full_Status_Check()
{
        unsigned char *Temp;
       	unsigned char SRD;
       	Temp  = (unsigned char *)FLASH_START_ADR;
       	*Temp = 0x70;                  
       	Temp  = (unsigned char *)FLASH_START_ADR; 
       	SRD = *Temp;
       	
       	if((SRD&0x8)>>3 == 1) 
       		printf("Vpp Range Error\n"); 
		if((SRD&0x18)>>4 == 3) 
       		printf("Command Sequence Error\n");
		if((SRD&0x20)>>5 == 1) 
       		printf("Block Erase Error\n");
       	if((SRD&0x2)>>1 == 1) 
       		printf("Attempted Erase of Locked Block - Aborted\n");        	        		
}

/************************************************************************/
/* PROCEDURE:   Program_One_Byte                                        */
/*                                                                      */
/* This procedure can be used to program ONE byte of data to the        */
/* 28F016.                                                              */
/*                                                                      */
/* NOTE:  It is necessary to first erase the sector containing the      */
/*        byte to be programmed.        	                            */
/*                                                                      */
/* Input:                                                               */
/*           Src     The BYTE which will be written to the 28F016       */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/
void Program_One_Byte (BYTE SrcByte,    BYTE   *Dst)
{   //BYTE Detec;
	unsigned char   *Temp;
//    unsigned char   *DestBuf;
        char INTEL_status;
        volatile char SR_7 = 0;

//        DestBuf = Dst;

         Temp = (unsigned char   *)FLASH_START_ADR; 
        *Temp = FLASH_LOAD;             /* write data 0x40  to the address */
        
        *Dst = SrcByte;             /* transfer the byte to destination*/
//        Detec = *DestBuf;
      /* Read the status register to inquery bit7 */
        *Temp = FLASH_READ_STATUS;         /* write data 0x70 to the address */
        while(SR_7 == 0)
        {
          INTEL_status = *(char *)FLASH_START_ADR;
          SR_7 = INTEL_status & 0x80;
        }
        
//      Full_Status_Check();
}

	void Program_N_Byte (BYTE *Src,    BYTE   *Dst,	int num) 
	{
		unsigned char   *SourceBuf;
        unsigned char   *DestBuf;
		int i;
		
		SourceBuf = Src;
        DestBuf = Dst;
		Erase_One_Block(Dst+num/8192);
		for(i=0;i<num;i++)
		{   
		    Program_One_Byte (*SourceBuf,    DestBuf);
			SourceBuf++;
			DestBuf++;
		}
	} 




⌨️ 快捷键说明

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