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

📄 sst39vf160.c

📁 基于如何开发MPC860处理器系统的核心业务模块QMC的开发程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                                                                      */
/* Output:                                                              */
/*      NONE                                                            */
/************************************************************************/

STATUS Erase_One_Block (UINT32 *Dst)
{
	STATUS retVal = OK;
    UINT32 *Temp;    
    /*  Issue the Sector Erase command to 39VF160  */
	*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
	*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
	*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_BLOCK;
	*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FOURTH;
	*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_FIFTH;
	
    Temp  = Dst;
    *Temp = SST_CMD_BLOCK;
    Delay_Milli_Seconds(25000);       /* Delay time = Tbe */

    return retVal;
}

/************************************************************************/
/* PROCEDURE:   Program_One_Word                                        */
/*                                                                      */
/* This procedure can be used to program ONE word of date to the        */
/* 39VF160.                                                             */
/*                                                                      */
/* NOTE:  It is VERY important the sector containing the word to be     */
/*        programmed was ERASED first.                                  */
/*                                                                      */
/* Input:                                                               */
/*           Src     The WORD which will be written to the 39VF160      */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Program_One_Word (UINT32 *Src, UINT32 *Dst)
{
    VUINT32 *s, *d;

    s = Src;
    d = Dst;
    
	*(UINT32 *)SST_FIRST_CYCLE = SST_CMD_FIRST;
	*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_SECOND;
	*(UINT32 *)SST_SECOND_CYCLE = SST_CMD_PROGRAM;

    *d = *s;
    Check_Toggle_Ready(d);
}

/************************************************************************/
/* PROCEDURE:   Program_One_Sector                                      */
/*                                                                      */
/* This procedure can be used to program a total of 2048 words of data  */
/* to the SST39VF160.                                                   */
/*                                                                      */
/* Input:                                                               */
/*           Src     SOURCE address containing the data which will be   */
/*                   written to the 39VF160                             */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Program_One_Sector (UINT32 *Src, UINT32 *Dst)
{
	int Index;
	VUINT32 *s, *d;

	s = Src;
	d = Dst;
	
    Erase_One_Sector(Dst);          /* erase the sector first */

    for (Index = 0; Index < SECTOR_SIZE; Index++)
    {
        Program_One_Word(s, d);
        s++;
        d++;    
    }
}

/************************************************************************/
/* PROCEDURE:   Program_One_Block                                       */
/*                                                                      */
/* This procedure can be used to program a total of 32k words of data   */
/* to the SST39VF160.                                                   */
/*                                                                      */
/* Input:                                                               */
/*           Src     SOURCE address containing the data which will be   */
/*                   written to the 39VF160                             */
/*           Dst     DESTINATION address which will be written with the */
/*                   data passed in from Src                            */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Program_One_Block (UINT32 *Src, UINT32 *Dst)
{
        int Index;
		UINT32 *s;
		UINT32 *d;

		s = Src;
		d = Dst;
		
	    Erase_One_Block(Dst);    /* erase the sector first */

        for (Index = 0; Index < BLOCK_SIZE; Index++)
        {
			Program_One_Word(s, d);

            s++;
            d++;
        }
}

/************************************************************************/
/* PROCEDURE:    Check_Toggle_Ready                                     */
/*                                                                      */
/* During the internal program cycle, any consecutive read operation    */
/* on DQ6 will produce alternating 0's and 1's (i.e. toggling between   */
/* 0 and 1). When the program cycle is completed, DQ6 of the data will  */
/* stop toggling. After the DQ6 data bit stops toggling, the device is  */
/* ready for next operation.                                            */
/*                                                                      */
/* Input:                                                               */
/*           Dst        must already set-up by the caller               */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Check_Toggle_Ready (UINT32 *Dst)
{
        UINT8 Loop = OK;
        UINT32 PreData;
        UINT32 CurrData;
        unsigned long TimeOut = 0;

        PreData = *Dst;
        PreData = PreData & 0x40404040;
        while ((TimeOut< 0x07FFFFFF) && (Loop))
        {
            CurrData = *Dst;
            CurrData = CurrData & 0x40404040;
            if (PreData == CurrData)
                Loop = ERROR;   /* ready to exit the while loop */
            PreData = CurrData;
            TimeOut++;
        }
}


/************************************************************************/
/* PROCEDURE:   Check_Data_Polling                                      */
/*                                                                      */
/* During the internal program cycle, any attempt to read DQ7 of the    */
/* last byte loaded during the page/byte-load cycle will receive the    */
/* complement of the true data.  Once the program cycle is completed,   */
/* DQ7 will show true data.                                             */
/*                                                                      */
/* Input:                                                               */
/*           Dst        must already set-up by the caller               */
/*           True       Data is the original (true) data                */
/*                                                                      */
/* Output:                                                              */
/*           None                                                       */
/************************************************************************/

void Check_Data_Polling (UINT32 *Dst, UINT32 TrueData)
{
    UINT8 Loop = OK;
    UINT32 CurrData;
    unsigned long TimeOut = 0;

    TrueData = TrueData &  0x80808080;
    while ((TimeOut< 0x07FFFFFF) && (Loop))
    {
        CurrData = *Dst;
        CurrData = CurrData & 0x80808080;
        if (TrueData == CurrData)
           Loop = ERROR;
        TimeOut++;
    }
}

⌨️ 快捷键说明

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