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

📄 mvflash.c

📁 此代码为烧制bios程序的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
void mvFlashReset(void)
{ 
 	unsigned char   ucData;
    unsigned short  usData;
    unsigned long    uiData;

    if((mvFlashTypes[FLASH_POINTER_TO_FLASH] == AMD_FLASH) || 
                (mvFlashTypes[FLASH_POINTER_TO_FLASH]) == ST_FLASH || \
       (mvFlashTypes[FLASH_POINTER_TO_FLASH]) == ATMEL_FLASH || \
	    (mvFlashTypes[FLASH_POINTER_TO_FLASH] == SST_FLASH))
    {
        if (FLASH_MODE == X16)
        {
            ucData = 0xf0;  
            usData = 0xf0;
            uiData = 0x00f000f0;
        }
        else /* case of PURE8 or X8 */
        {
            ucData = 0xf0;  
            usData = 0xf0f0;
            uiData = 0xf0f0f0f0;
        }
    }
    else
    {
        if (FLASH_MODE == X16)
        {
            ucData = 0xff;  
            usData = 0x00ff;
            uiData = 0x00ff00ff;
        }
        else /* case of PURE8 or X8 */
        {
            ucData = 0xff;  
            usData = 0xffff;
            uiData = 0xffffffff;
        }
    }
    switch(FLASH_WIDTH)
    {
        case 1:
            MV_WRITE_CHAR(FLASH_BASE_ADDR,0,ucData);
            break;
        case 2:
            MV_WRITE_SHORT(FLASH_BASE_ADDR,0,usData);
            break;
        case 4:
            MV_WRITE_WORD(FLASH_BASE_ADDR,0,uiData);
            break;
        case 8:
            MV_WRITE_WORD(FLASH_BASE_ADDR,0,uiData);
            MV_WRITE_WORD(FLASH_BASE_ADDR, 0x4,uiData);
            break;
    }
}

                    
/*******************************************************************************
* mvFlashWriteWord - Write 32Bit to the FLASH memory
*
* DESCRIPTION:
*       This function Writes 32 bit data to the flash memory at a given offset 
*       from the FLASH base address in all kind of flash widths. The function 
*       takes care of Big/Little endian conversion. 
*
* INPUT:
*       offset - Offset relative to a flash抯 base address.
*       data   - 32 bit data to be written to the flash memory.
*
* OUTPUT:
*       None.
*
* RETURN:
*       true on success, false otherwise.
*
*******************************************************************************/
bool mvFlashWriteWord(unsigned long offset,unsigned long data)
{ 
    unsigned char           c,rc;
    unsigned short          s,rs;
    register unsigned long   rw,count=0;
 	register unsigned long   regValue;
    register unsigned long   FirstAddr,SecondAddr,ThirdAddr;
    register unsigned long   FirstData,SecondData,ThirdData;
    register unsigned long   data10,data20,data70,data80,data50;
    if ( (mvFlashTypes[FLASH_POINTER_TO_FLASH] == AMD_FLASH) ||   \
            (mvFlashTypes[FLASH_POINTER_TO_FLASH] == ST_FLASH) ||  \
            (mvFlashTypes[FLASH_POINTER_TO_FLASH] == ATMEL_FLASH) ||  \
			(mvFlashTypes[FLASH_POINTER_TO_FLASH] == SST_FLASH) )
    {
        switch(FLASH_WIDTH)
        {
            case 1: /* Split the 32 bit write into four 8bit Writings */ 
                                            
                mvFlashReset();
                if( FLASH_MODE == PURE8 ) /* Boot Flash*/
                {
                    FirstAddr  = 0x5555;
                    SecondAddr = 0x2aaa;
                    ThirdAddr  = 0x5555;
                }
                else
                {
                    FirstAddr  = 0xaaaa;
                    SecondAddr = 0x5555;
                    ThirdAddr  = 0xaaaa;
                }
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  FirstAddr,0xaa);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  SecondAddr,0x55);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  ThirdAddr,0xa0);
#ifdef LE
                c = data;
#else
                c = (data >> 24);
#endif
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  offset,c); 
                /* Writing first Byte */
                while(true)
                {
                    MV_READ_CHAR(FLASH_BASE_ADDR, offset,&rc);
                    if( (rc & 0x80) == (c & 0x80) )         /* DQ7 =? DATA */
                        break;                              /* DQ7 =  DATA */
                    if((rc & 0x20) == 0x20)                 /* DQ5 =? '1'  */
                    {
                        MV_READ_CHAR (FLASH_BASE_ADDR, offset,&rc);
                        if((rc & 0x80) == (c & 0x80)) 
                            break;                          /* DQ7 = DATA  */
                        else 

                            return false;                   /* DQ7 != DATA */
                                                }
                }
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  FirstAddr,0xaa);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  SecondAddr,0x55);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  ThirdAddr,0xa0);
#ifdef LE
                c = (data >> 8);
#else
                c = (data >> 16);
#endif
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  offset + 1,c); 
                /* Writing second Byte */
                mvFlashReset();
                while(true)
                {
                    MV_READ_CHAR(FLASH_BASE_ADDR, offset + 1,&rc);
                    if((rc & 0x80) == (c & 0x80))           /* DQ7 =? DATA */
                        break;                              /* DQ7 = DATA  */
                    if((rc & 0x20) == 0x20)                 /* DQ5 =? '1'  */
                    {
                        MV_READ_CHAR(FLASH_BASE_ADDR, offset + 1,&rc);
                        if((rc & 0x80) == (c & 0x80)) 
                            break;                          /* DQ7 = DATA  */
                        else 
                            return false;                   /* DQ7 != DATA */
                    }
                }
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  FirstAddr,0xaa);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  SecondAddr,0x55);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  ThirdAddr,0xa0);
#ifdef LE
                c = (data >> 16);
#else
                c = (data >> 8);
#endif
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  offset + 2,c); 
                /* Writing third Byte */
                mvFlashReset();
                while(true)
                {
                    MV_READ_CHAR(FLASH_BASE_ADDR, offset + 2,&rc);
                    if((rc & 0x80) == (c & 0x80))           /* DQ7 =? DATA */    
                        break;                              /* DQ7 = DATA  */
                    if((rc & 0x20) == 0x20)                 /* DQ5 =? '1'  */
                    {
                        MV_READ_CHAR(FLASH_BASE_ADDR, offset + 2,&rc);
                        if((rc & 0x80) == (c & 0x80)) 
                            break;                          /* DQ7 = DATA  */
                        else                                                 
                            return false;                   /* DQ7 != DATA */
                    }
                }
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  FirstAddr,0xaa);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  SecondAddr,0x55);
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  ThirdAddr,0xa0);
#ifdef LE
                c = (data >> 24);
#else
                c = data;
#endif
                MV_WRITE_CHAR(FLASH_BASE_ADDR,  offset + 3,c); 
                /* Writing fourth Byte */
                mvFlashReset();
                while(true)
                {
                    MV_READ_CHAR(FLASH_BASE_ADDR, offset + 3,&rc);
                    if((rc & 0x80) == (c & 0x80))           /* DQ7 =? DATA */ 
                        break;                              /* DQ7 = DATA  */
                    if((rc & 0x20) == 0x20)                 /* DQ5 =? '1'  */
                    {
                        MV_READ_CHAR(FLASH_BASE_ADDR, offset + 3,&rc);
                        if((rc & 0x80) == (c & 0x80)) 
                            break;                          /* DQ7 = DATA  */
                        else                                                 
                            return false;                   /* DQ7 != DATA */
                    }
                }
                break;
            case 2: /* Split the 32 bit write into two 8/16 bit Writings 
                       (16bit width). */
                if (FLASH_MODE == X16)
                {
                    FirstData  = 0xaa;      /* Data for the First  Cycle    */
                    SecondData = 0x55;      /* Data for the Second Cycle    */
                    ThirdData  = 0xa0;      /* Data for the Third  Cycle    */
                    FirstAddr  = 0x5555;    /* Address for the First  Cycle */
                    SecondAddr = 0x2aaa;    /* Address for the Second Cycle */
                    ThirdAddr  = 0x5555;    /* Address for the Third  Cycle */
                }
                else /* if (FLASH_MODE == 8) */
                {
                    FirstData  = 0xaaaa;     /* Data for the First  Cycle    */
                    SecondData = 0x5555;     /* Data for the Second Cycle    */
                    ThirdData  = 0xa0a0;     /* Data for the Third  Cycle    */
                    FirstAddr  = 0xaaaa;    /* Address for the First  Cycle */
                    SecondAddr = 0x5555;    /* Address for the Second Cycle */
                    ThirdAddr  = 0xaaaa;    /* Address for the Third  Cycle */
                }
                MV_WRITE_SHORT(FLASH_BASE_ADDR, FirstAddr * FLASH_WIDTH,
                                   FirstData);
                MV_WRITE_SHORT(FLASH_BASE_ADDR, SecondAddr * FLASH_WIDTH,
                                   SecondData);
                MV_WRITE_SHORT(FLASH_BASE_ADDR, ThirdAddr * FLASH_WIDTH,
                                   ThirdData);
#ifdef LE
                s = data;
#else
                s = (data >> 16);
#endif
                MV_WRITE_SHORT(FLASH_BASE_ADDR, offset,s); 
                /* Writing Two Bytes */
                if (FLASH_MODE == X16)
                {
                    data80 = 0x80;;
                    data20 = 0x20;;
                }
                else /* if (FLASH_MODE == 8) */
                {
                    data80 = 0x8080;
                    data20 = 0x2020;
                }
                while(true)
                {
                    MV_READ_SHORT(FLASH_BASE_ADDR, offset,&rs);
                    if((rs & data80) == (s & data80))      /* DQ7 =? DATA */
                        break;                             /* DQ7 =  DATA */
                    if((rs & data20) == data20)            /* DQ5 =? DATA */
                    {
                        MV_READ_SHORT(FLASH_BASE_ADDR, offset,&rs);
                        if((rs & data80) == (s & data80)) 
                            break;                         /* DQ7 = DATA  */
                        else
                        {
                            mvFlashReset();
                            return false;                  /* DQ7 != DATA */
                            
                        }
                    }
                }
                MV_WRITE_SHORT(FLASH_BASE_ADDR, FirstAddr * FLASH_WIDTH,
                                   FirstData);
                MV_WRITE_SHORT(FLASH_BASE_ADDR, SecondAddr * FLASH_WIDTH,
                                   SecondData);
                MV_WRITE_SHORT(FLASH_BASE_ADDR, ThirdAddr * FLASH_WIDTH,
                                   ThirdData);
#ifdef LE
                s = (data >> 16);
#else
                s = data;
#endif
                MV_WRITE_SHORT(FLASH_BASE_ADDR, offset + 2,s); 
                /* Writing Two Bytes */
                while(true)
                {
                    MV_READ_SHORT(FLASH_BASE_ADDR, offset + 2,&rs);
                    if((rs & data80) == (s & data80))      /* DQ7 =? DATA */
                        break;                             /* DQ7 =  DATA */
                    if((rs & data20) == data20)            /* DQ5 =? '1'  */
                    {

⌨️ 快捷键说明

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