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

📄 sst39vf1601.c

📁 优龙LPC1788开发板资料
💻 C
📖 第 1 页 / 共 2 页
字号:
/* */
#include "bsp.h"
#include "lpc_types.h"
#include "SST39VF1601.h"
#include "lpc177x_8x_emc.h"
#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_pinsel.h"
#include "lpc177x_8x_timer.h"

uint32_t system_base = 0x90000000;  // 4Guint8_t System Memory Address.
#define sysAddress(offset) ((volatile uint16_t *)(system_base + (offset<<1)))
   	// The user should modify this address accordingly.

/*********************************************************************//**
 * @brief 		Delay
 * @param[in]	delayCnt Delay value
 * @return 		None
 **********************************************************************/
void delay_ns(uint32_t delayCnt)
{
	uint32_t i;

	for ( i = 0; i < delayCnt; i++ );
	return;
}

/*********************************************************************//**
 * @brief 		Initialize external NOR FLASH memory
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void NORFLASHInit( void )
{
//	TIM_TIMERCFG_Type TIM_ConfigStruct;
	/**************************************************************************
	* Initialize EMC for NOR FLASH
	**************************************************************************/
	EMC_Init();
	delay_ns(100);

	EMC_StaMemConfigMW (1,EMC_StaticConfig_MW_16BITS);
	EMC_StaMemConfigPB(1,EMC_StaticConfig_PB);
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITWEN, EMC_StaticWaitWen_WAITWEN(2));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITOEN, EMC_StaticWaitOen_WAITOEN(2));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITRD, EMC_StaticWaitRd_WAITRD(0x1f));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITPAGE, EMC_StaticwaitPage_WAITPAGE(0x1f));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITWR, EMC_StaticWaitwr_WAITWR(0x1f));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITTURN, EMC_StaticWaitTurn_WAITTURN(0x1f));

	//delay time
 //	TIM_Waitms(10);
	delay_ns(150);

  	return;
}
/************************************************************************/
/* PROCEDURE:   Check_SST_39VF160X                                      */
/*                                                                      */
/* This procedure decides whether a physical hardware device has a      */
/* SST39VF160X 16 Mbit MPF+ Device installed or not.         		*/
/*                                                                      */
/* Input:                                                               */
/*          None                                                        */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates a SST39VF160X                       */
/*          return FALSE: indicates not a SST39VF160X                   */
/************************************************************************/
int Check_SST_39VF160X(void)
{
    uint16_t SST_id1;
    uint16_t SST_id2;
    int  ReturnStatus;

    //  Issue the Software Product ID code to 39VF160X
    *sysAddress(0x5555) = 0x00AA;  // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055;  // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x0090;  // write data 0x0090 to device addr 0x5555
	delay_ns(100);

    // Read the product ID from 39VF160X
    SST_id1  = *sysAddress(0x0000);   // get first ID uint8_t
    SST_id2  = *sysAddress(0x0001);   // get second ID uint8_t

    // ------------------------------------------------------------
    // Determine whether there is a SST 39VF1601 installed or not
    // use the following code:

    if (((SST_id1 == SST_ID) && (SST_id2 == SST_39VF1601))||((SST_id1 == SST_ID) && (SST_id2 == SST_39VF1602)))
            ReturnStatus = TRUE;
    else
            ReturnStatus = FALSE;

    // ------------------------------------------------------------

    // Issue the Software Product ID Exit code, thus returning the
    // 39VF160X to the normal operation.
    *sysAddress(0x5555) = 0x00AA;  // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055;  // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x00F0;  // write data 0x00F0 to device addr 0x5555
    delay_ns(100);   // Tida Max 150ns for 39VF160X
                                    
    return (ReturnStatus);
}


/************************************************************************/
/* PROCEDURE:   CFI_Query                                               */
/*                                                                      */
/* This procedure should be used to query for CFI information           */
/*                                                                      */
/* Input:                                                               */
/*          Src	Source address to store CFI_Query data string		*/
/*                                                                      */
/* Output:                                                              */
/*          None                                                        */
/************************************************************************/
void CFI_Query(uint16_t *Src)
{ 
	uint16_t index;
    //  Issue the CFI Query entry code to 39VF160X
    *sysAddress(0x5555) = 0x00AA;  // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055;  // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x0098;  // write data 0x0098 to device addr 0x5555
    Delay(1);     // insert delay time = Tida

    // ----------------------------------------------------------
    //  Perform all CFI operations here:
    //  CFI_Query_address is from 0010H--0034H

    for (index = 0x0010; index <= 0x0034; index++)
    {
     	 *Src = *sysAddress(index);
         ++Src;
	// CFI query data is stored in user-defined memory space.
    }
    // ----------------------------------------------------------

        // Issue the CFI Exit code thus returning the 39VF160X
        // to the read operating mode

    *sysAddress(0x5555) = 0x00AA;  // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055;  // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x00F0;  // write data 0x00F0 to device addr 0x5555
    Delay(1);     // insert delay time = Tida
}


/************************************************************************/
/* PROCEDURE:   SecID_Query                                             */
/*                                                                      */
/* This procedure should be used to query for Security ID information.  */
/*                                                                      */
/* Input:                                                               */
/*          SST_SecID	Source address to store SST SecID string	*/
/*          User_SecID	Source address to store User SecID string	*/
/*                                                                      */
/* Output:                                                              */
/*          None                                                        */
/************************************************************************/
void SecID_Query(uint16_t *SST_SecID, uint16_t *User_SecID)
{
     uint16_t index;
	     //  Issue the SecID Entry code to 39VF160X
    *sysAddress(0x5555) = 0x00AA;  // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055;  // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x0088;  // write data 0x0088 to device addr 0x5555
    Delay(1);      // insert delay time = Tida

    	//  Perform all Security ID operations here:
    	//  	SST programmed segment is from address 000000H--000007H,
    	//  	User programmed segment is from address 000010H--000017H.

    for (index = 0x0000; index <= 0x0007; index++)
    {
    	 *SST_SecID = *sysAddress(index);
         ++SST_SecID;
         *User_SecID = *sysAddress(index+0x0010);
         ++User_SecID;
	// Security query data is stored in user-defined memory space.
    }
        // Issue the Sec ID Exit code thus returning the 39VF160X
        // to the read operating mode
    *sysAddress(0x5555) = 0x00AA;  // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055;  // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x00F0;  // write data 0x00F0 to device addr 0x5555
    Delay(1);      // insert delay time = Tida
}


/************************************************************************/
/* PROCEDURE:   Erase_One_Sector                                        */
/*                                                                      */
/* This procedure can be used to erase a total of 2048 uint16_ts.           */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address where the erase operation starts    */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates success in sector-erase             */
/*          return FALSE: indicates failure in sector-erase             */
/************************************************************************/
int Erase_One_Sector(uint32_t Dst)
{
	uint32_t DestBuf = Dst;
   int  ReturnStatus;

	//  Issue the Sector Erase command to 39VF160X
	*sysAddress(0x5555) = 0x00AA;     // write data 0x00AA to device addr 0x5555
	*sysAddress(0x2AAA) = 0x0055;     // write data 0x0055 to device addr 0x2AAA
	*sysAddress(0x5555) = 0x0080;     // write data 0x0080 to device addr 0x5555
	*sysAddress(0x5555) = 0x00AA;     // write data 0x00AA to device addr 0x5555
	*sysAddress(0x2AAA) = 0x0055;     // write data 0x0055 to device addr 0x2AAA
	*sysAddress(DestBuf) = 0x0030;    // write data 0x0030 to device sector addr

   ReturnStatus = Check_Toggle_Ready(DestBuf);	// wait for TOGGLE bit ready

   return ReturnStatus;
}


/************************************************************************/
/* PROCEDURE:   Erase_One_Block                                         */
/*                                                                      */
/* This procedure can be used to erase a total of 32K uint16_ts.            */
/*                                                                      */
/* Input:                                                               */
/*      Dst     DESTINATION address where the erase operation starts    */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates success in block-erase              */
/*          return FALSE: indicates failure in block-erase              */
/************************************************************************/
int Erase_One_Block (uint32_t Dst)
{
   uint32_t DestBuf = Dst;
   int ReturnStatus;

    //  Issue the Block Erase command to 39VF160X
	*sysAddress(0x5555) = 0x00AA;     // write data 0x00AA to device addr 0x5555
	*sysAddress(0x2AAA) = 0x0055;     // write data 0x0055 to device addr 0x2AAA
	*sysAddress(0x5555) = 0x0080;     // write data 0x0080 to device addr 0x5555
	*sysAddress(0x5555) = 0x00AA;     // write data 0x00AA to device addr 0x5555
	*sysAddress(0x2AAA) = 0x0055;     // write data 0x0055 to device addr 0x2AAA
	*sysAddress(DestBuf) = 0x0050;    // write data 0x0050 to device sector addr

   ReturnStatus = Check_Toggle_Ready(DestBuf);	  	// wait for TOGGLE bit ready

   return ReturnStatus;
}


/************************************************************************/
/* PROCEDURE:   Erase_Entire_Chip                                       */
/*                                                                      */
/* This procedure can be used to erase the entire chip.                 */
/*                                                                      */
/* Input:                                                               */
/*      NONE                                                            */
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/
void Erase_Entire_Chip(void)
{
   //  Issue the Chip Erase command to 39VF160X
	*sysAddress(0x5555) = 0x00AA;     // write data 0x00AA to device addr 0x5555
	*sysAddress(0x2AAA) = 0x0055;     // write data 0x0055 to device addr 0x2AAA
	*sysAddress(0x5555) = 0x0080;     // write data 0x0080 to device addr 0x5555
	*sysAddress(0x5555) = 0x00AA;     // write data 0x00AA to device addr 0x5555
	*sysAddress(0x2AAA) = 0x0055;     // write data 0x0055 to device addr 0x2AAA
	*sysAddress(0x5555) = 0x0010;     // write data 0x0010 to device addr 0x5555

   delay_ns(100);       	// Delay Tsce time
}


/************************************************************************/
/* PROCEDURE:   Program_One_uint16_t                                        */
/*                                                                      */
/* This procedure can be used to program ONE uint16_t of data to the        */
/* 39VF160X.                                                            */
/*                                                                      */
/* NOTE:  It is necessary to first erase the sector containing the      */
/*        uint16_t to be programmed.                                	*/
/*                                                                      */
/* Input:                                                               */
/*           Srcuint16_t The uint16_t which will be written to the 39VF160X     */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates success in uint16_t-program             */
/*          return FALSE: indicates failure in uint16_t-program             */
/************************************************************************/
int Program_One_uint16_t (uint16_t *Srcuint16_t,   uint32_t Dst)
{
    uint32_t DestBuf = Dst;
    uint16_t *SourceBuf = Srcuint16_t;
    int ReturnStatus;

    *sysAddress(0x5555) = 0x00AA; // write data 0x00AA to device addr 0x5555
    *sysAddress(0x2AAA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
    *sysAddress(0x5555) = 0x00A0; // write data 0x00A0 to device addr 0x5555
    *sysAddress(DestBuf) = *SourceBuf; // transfer the uint16_t to destination

    ReturnStatus = Check_Toggle_Ready(DestBuf); // wait for TOGGLE bit ready

    return ReturnStatus;
}


/************************************************************************/
/* PROCEDURE:   Program_One_Sector                                      */
/*                                                                      */
/* This procedure can be used to program a total of 2048 uint16_ts of data  */
/* to the SST39VF160X.                                                  */

⌨️ 快捷键说明

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