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

📄 flash.c

📁 瑞泰创新的GX-ARM9-2410EP教学实验系统的所有基础实验源代码,内容齐全,解析清楚,基本上每个实验结果都有图片显示
💻 C
字号:
//====================================================================
// File Name : flash.c
// Function  : S3C2440 Flash Program
// Program   : Kong, In Wook (KIW)
// Date      : May 30, 2002
// Version   : 0.0
// History
//   0.0 : Programming start (May 30,2002) -> KIW
//          Arrangement source code(8/01/2002)-> SOP 
//			Edited for SMDK2440(07/07/2003) -> Junon
//====================================================================

#include <string.h>
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h" 

#include "mmu.h"
#include "strata32.h"
#include "sst39vf800.h"

#include "xmodem.h"


static int DownloadData(void);

U32 downloadAddress; 
U32 downloadProgramSize = 0;

//==========================================================================================
void *flashType[][2]=
{
    (void *)Program28F128J3A,    "28F320J3A        ",    
	//(void *)Erase28F128J3A, 	 "Erase 28F320J3A  ",		// added by junon 10/29    
	(void *)ProgramSST39VF800, 	 "SST39VF800       ",		// added by lzf   1/05    	
};

//==========================================================================================
void ProgramFlash(void)
{
    int i;
    char key;

    Uart_Printf("\n[ NOR Flash Memory Writer Ver 0.1 ]\n");
    Uart_Printf("\nThe program buffer : 0x31000000 ~ 0x31ffffff\n\n");
    
    downloadAddress=0x31000000;
    downloadProgramSize=0x0;

    //ChangeRomCacheStatus(RW_NCNB);


	Uart_Printf("\t\b\b\b\b-------------------------\n");
    for(i=0; i < sizeof(flashType)/sizeof(flashType[i]); i++)
    {   //display menu
        Uart_Printf("\t%c) %s\n", i+'a', flashType[i][1]);
    }

    Uart_Printf("\nSelect the type of a flash memory : ");
    do
    {
		key = Uart_Getch();
		i = key - 'a';
    }while(i<0 || i>=(sizeof(flashType)/sizeof(flashType[i])));
    Uart_Printf("%c\n", key);

    Uart_Printf("Do you want to download through UART0 from 0x%x? [y/n] : ", downloadAddress);
    key = Uart_Getch();
    Uart_Printf("%c\n",key);
    if(key=='y')
    {
        if(!DownloadData())
            return;
    }
    ((void (*)(void))(flashType[i][0]))();
}

//==========================================================================================
/*
static int DownloadData(void)
{
    int i,tmp;
    U16 checkSum=0,dnCS;
    U32 fileSize=10;
    U8 *downPt;

    downPt=(U8 *)downloadAddress;
   
    Uart_Printf("\ndownloadAddress = %x\n",downloadAddress);

    Uart_Printf("Download the plain binary file(.BHC) to be written\n");
    Uart_Printf("The file format : <n+6>(4)+(n)+CS(2)\n");
    Uart_Printf("To transmit .BIN file : wkocm2 xxx.BIN /1 /d:1\n");
    Uart_Printf("Download methods : COM:8Bit,NP,1STOP\n");
 
    Uart_Printf("\nSTATUS : ");
    rINTMSK=BIT_ALLMSK;
    
    tmp=RdURXH0(); //To remove overrun error state.

    i=0;
    while(i<fileSize)
    {
        while(!(rUTRSTAT0&0x1));
            *(downPt+i)=RdURXH0();
        if(i==3)
        {
            fileSize=*((U8 *)(downloadAddress+0))+
            (*((U8 *)(downloadAddress+1))<<8)+
            (*((U8 *)(downloadAddress+2))<<16)+
            (*((U8 *)(downloadAddress+3))<<24);
        }
    
        if((i%1000)==0)
            WrUTXH0('#');
        i++;
    }

    downloadProgramSize=fileSize-6;

    Uart_Printf("\ndownloadProgramSize: %d : ",downloadProgramSize);

    for(i=4;i<(fileSize-2);i++)
    {
        checkSum+=*((U8 *)(i+downloadAddress));
    }

    dnCS=*((U8 *)(downloadAddress+fileSize-2))+
          (*( (U8 *)(downloadAddress+fileSize-1) )<<8);

    if(checkSum!=dnCS)
    {
        Uart_Printf("Checksum Error!!! MEM : %x  DN : %x\n",checkSum,dnCS);
        return 0;
    }

    Uart_Printf("\nDownload O.K.\n");
    return 1;
}*/

static int DownloadData(void)
{
	char *pBuf = (char*)downloadAddress;
	size_t sizeBuf = 1024*1024*4;
	unsigned long nDownloadSize;

	Uart_Printf("\n请使用超级终端(XMODEM)发送文件。");
	Uart_Printf("\n开始下载...");
	nDownloadSize = xmodem_receive(pBuf, sizeBuf);
	if(nDownloadSize > 0)
	{
		downloadProgramSize = (U32)nDownloadSize;
		Uart_Printf("\n下载完成。");
		return 1;
	}
	else
	{
		downloadProgramSize = 0;
		Uart_Printf("\n下载失败。");
		return 0;
	}
}

⌨️ 快捷键说明

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