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

📄 flash6303.c

📁 M3355的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    tmpval=getfrom_flash(0x0001);

    if(tmpval!=devid)
    {
        *(volatile unsigned char *)(0xb8000054)=0x07;
        return -2;
    }

    return 1;
}

static void resetflash()
{
    sendcmd(0x5555,0xaa);
    sendcmd(0x2aaa,0x55);
    sendcmd(0x5555,0xf0);
}


static int erasector(unsigned long flashaddr,unsigned long size)
{
    int k;
    unsigned long offset,i;
    unsigned char check;
    unsigned long sector=0x4000,sector1=0x2000,sector2=0x2000,sector3=0x8000,sector4=0x10000;
    unsigned char count=0;
    unsigned short comp_size=0;
    unsigned long check_gpio;

#ifdef hynix

    offset=flashaddr&0xfffff;
    size=(size+0x3ff)/1024;

    if(offset==0x0)
    {
        count=0;
    }
    else if(offset==0x4000)
    {
        count=1;
    }
    else if(offset==0x6000)
    {
        count=2;
    }
    else if(offset==0x8000)
    {
        count=3;
    }
    else
    {
        count=4;
    }

    do
    {
        sendcmd(0xaaa,0xaa);
        sendcmd(0x555,0x55);
        sendcmd(0xaaa,0x80);
        sendcmd(0xaaa,0xaa);
        sendcmd(0x555,0x55);
        sendcmd(offset,0x30);

        while(1)
        {
            check_gpio=*(volatile unsigned long *)(0xb8000050);
            if(check_gpio&0x100)
                break;
        }

        if(count==0)
        {
            offset=offset+sector;
            comp_size+=16;
        }
        else if(count==1)
        {
            offset=offset+sector1;
            comp_size+=8;
        }
        else if(count==2)
        {
            offset=offset+sector2;
            comp_size+=8;
        }
        else if(count==3)
        {
            offset=offset+sector3;
            comp_size+=32;
        }
        else
        {
            offset=offset+sector4;
            comp_size+=64;
        }

        count++;

    }
    while(comp_size<size);


#endif

#ifdef sst

    offset=flashaddr&0x3fffff;
    for(i=0;i<((size+0xfff)/0x1000);i++)
    {
        sendcmd(0x5555,0xaa);
        sendcmd(0x2aaa,0x55);
        sendcmd(0x5555,0x80);
        sendcmd(0x5555,0xaa);
        sendcmd(0x2aaa,0x55);
        sendcmd(offset,0x30);
        for(k=0;k<2;k++)
        {
            check=getfrom_flash(0x0);
            if(!(check&0x80))
                k=0;
        }
        offset=offset+0x1000;
    }
#endif
    return 1;
}

#ifdef sst
static int eraseblock(unsigned long flashaddr,unsigned short size)
{
    int i,k;
    unsigned long offset;
    unsigned char check;

    offset=flashaddr&0x3fffff;

    for(i=0;i<((size+0xffff)/0x10000);i++)
    {
        sendcmd(0x5555,0xaa);
        sendcmd(0x2aaa,0x55);
        sendcmd(0x5555,0x80);
        sendcmd(0x5555,0xaa);
        sendcmd(0x2aaa,0x55);
        sendcmd(offset,0x30);
        for(k=0;k<2;k++)
        {
            check=getfrom_flash(0x0);
            if(!(check&0x80))
                k=0;
        }

        offset=offset+0x10000;
    }

    return 1;
}
#endif

static int erasechip()
{
    unsigned char check;
    unsigned long check_gpio;
    int k;

#ifdef sst

    sendcmd(0x5555,0xaa);
    sendcmd(0x2aaa,0x55);
    sendcmd(0x5555,0x80);
    sendcmd(0x5555,0xaa);
    sendcmd(0x2aaa,0x55);
    sendcmd(0x5555,0x10);
    for(k=0;k<2;k++)
    {
        check=getfrom_flash(0x0);
        if(!(check&0x80))
            k=0;
    }
#endif

#ifdef hynix
    sendcmd(0xaaa,0xaa);
    sendcmd(0x555,0x55);
    sendcmd(0xaaa,0x80);
    sendcmd(0xaaa,0xaa);
    sendcmd(0x555,0x55);
    sendcmd(0xaaa,0x10);

    while(1)
    {
        check_gpio=*(volatile unsigned long *)(0xb8000050);
        if(check_gpio&0x100)
            break;
    }
#endif

    return 1;
}

static int programflash(unsigned long sdramaddr, unsigned long flashaddr, unsigned long size)
{
    int k,j;
    unsigned long offset;
    unsigned char trsval,trsval1;
    unsigned char check;
    unsigned long check_gpio;
    unsigned long i,tmp;
    unsigned int count=0;
    int x,y,step,tcnt;
    int progress=0;

    step=size/165;

#ifdef sst
    //		soc_printf("begin program flash\n");

    offset=flashaddr&0x3fffff;

    for(i=0;i<(size);i++)
    {
        sendcmd(0x5555,0xaa);
        sendcmd(0x2aaa,0x55);
        sendcmd(0x5555,0xa0);
        trsval=*(volatile unsigned char *)(sdramaddr);
        tmp=(trsval&0x80);
        storeto_flash(offset,trsval);

        for(k=0;k<2;k++)
        {
            check=getfrom_flash(offset);
            check&=0x80;
            if(check!=tmp)
                k=0;
        }

        /*			count++;
        if(updata_flag)
        {
        if(!(count%step))
        {
        for(x=79;x<progress+79;x++) //progress/13 for 4M
        for(y=143;y<154;y++)
        *(volatile unsigned short*)(0xa0500000+(y*320+x)*2)=0xf800;
        progress++;
        }
        }*/

        sdramaddr++;
        offset++;
    }
#endif

#ifdef hynix

    offset=flashaddr&0xfffff;

    for(i=0;i<size;i++)
    {
        sendcmd(0xaaa,0xaa);
        sendcmd(0x555,0x55);
        sendcmd(0xaaa,0xa0);
        trsval=*(volatile unsigned char *)(sdramaddr);
        storeto_flash(offset,trsval);
        for(j = 0;j < 2000;j++)
            ;
        /*			while(1)
        {
        check_gpio=*(volatile unsigned long *)(0xb8000050);
        if(check_gpio&0x100)
        break;
        }*/

        /*			count++;
        if(updata_flag)
        {
        if(!(count%step))
        {
        for(x=79;x<progress+79;x++) //progress/13 for 4M
        for(y=143;y<154;y++)
        *(volatile unsigned short*)(0xa0500000+(y*320+x)*2)=0xf800;
        progress++;
        }
        }*/
        sdramaddr++;
        offset++;
    }

#endif
    return 1;
}

void format_card(unsigned char slot)
{
    long bytes,frames;

    //Fill data to the first frame,this is memcard ID frame
    for(bytes=0;bytes<CARD_SIZE;bytes++)
        memCard[slot*CARD_SIZE+bytes] = 0;

    memCard[slot*CARD_SIZE] = 0x4d;	//'M'
    memCard[slot*CARD_SIZE+1] = 0x43;	//'C'
    memCard[slot*CARD_SIZE+0x7f] = 0x0e;	//XOR byte

    //Fill data to the 0xf directory frames
    for(frames=1;frames<0x10;frames++)
    {
        memCard[slot*CARD_SIZE+frames*0x80] = 0xa0;
        memCard[slot*CARD_SIZE+frames*0x80+8] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+9] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+0x7f] = 0xa0;	//XOR byte
    }

    //Fill data to the 0x14 reserve frames
    for(frames=0x10;frames<0x24;frames++)
    {
        memCard[slot*CARD_SIZE+frames*0x80+0] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+1] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+2] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+3] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+8] = 0xff;
        memCard[slot*CARD_SIZE+frames*0x80+9] = 0xff;
    }
    //	soc_printf("format card %d\n",slot);
    //	memcpy(((unsigned long)(CARD_FLASHROM_BASE)+slot*CARD_SIZE),((unsigned long)memCard+slot*CARD_SIZE),CARD_SIZE);
    flash(((unsigned long)memCard+slot*CARD_SIZE),((unsigned long)(CARD_FLASHROM_BASE)+slot*CARD_SIZE),CARD_SIZE);
}



#endif

⌨️ 快捷键说明

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