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

📄 main.c

📁 这是很好的s3c44b0经典程序
💻 C
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"

////////////////////////////////////////
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);      
void HaltDabort(void);
////////////////////////////////////////
void ProgramF29LV160(void);

U32 downloadAddress;
U32 downloadProgramSize;

void *flashType[][2]={(void *)ProgramF29LV160, "F29LV160",
			      0,		0 };

void Main(void)
{
    int i=0;
    unsigned char *src, *dst;
    unsigned int memSum;

    rSYSCFG=SYSCFG_8KB;
#if (PLLON==1)
    ChangePllValue(PLL_M,PLL_P,PLL_S);
#endif

    Isr_Init();
    Port_Init();
    Uart_Init(0,115200);
    Uart_Select(0);
    Delay(0);  //calibrate Delay()
    Led_Display(7);
    Delay(1000);  //calibrate Delay()
    Led_Display(0);
    Delay(5000);  //calibrate Delay()
    Led_Display(7);


    Uart_Printf("\n*** NOR Flash Memory writer ver 0.3 ***\n\n");

    downloadAddress=(unsigned)malloc(0x400000);
    if(downloadAddress==0)
	return;

    rNCACHBE0=( (0x2000000>>12)<<16 )|(0>>12); //flash area(Bank0) must be non-cachable area.
    rSYSCFG=rSYSCFG & (~0x8); //write buffer has to be off for proper timing.    

    while(1)
    {   //display menu
        Uart_Printf("%c: %s",'a'+i,flashType[i][1]);
        i++;
        if((int)(flashType[i][0])==0)
	{
	    Uart_Printf("\n");
	    break;
	}
        if((i%4)==0)	//to aligne 4 
	    Uart_Printf("\n");
    }

    Uart_Printf("Select the type of a flash memory? ");
    i=Uart_Getch()-'a';
    Uart_Printf("\n");

    if( i<0 || (i>=(sizeof(flashType)/8)) )
	return;

    if(!DownloadData())
	return;
   
    ( (void (*)(void))(flashType[i][0]) )();

    free((void *)downloadAddress);

    rNCACHBE0=0x0;
}


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

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

    Uart_Printf("Download the plain binary file(.BHC) to be written\n");
    Uart_Printf(".BHC file format: <n+6>(4)+(n)+CS(2)\n");
    Uart_Printf("To transmit .BHC file    : wkocm2 xxx.BHC /1 /g /d:1\n");
    Uart_Printf("Or, 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_GLOBAL;
    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;

    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;
}


/******************************************************************/

void Isr_Init(void)
{
    U32 i;
    
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
    
     for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
    {
	*((volatile unsigned *)i)=0xEA000000+0x1FFE;
    }

    rINTCON=0x5;	  // Non-vectored,IRQ enable,FIQ disable    

    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK|=BIT_GLOBAL|BIT_EINT3;	  // All interrupt is masked.
}


void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception!!!\n");
    while(1);
}

void HaltSwi(void)
{
    Uart_Printf("SWI exception!!!\n");
    while(1);
}

void HaltPabort(void)
{
    Uart_Printf("Pabort exception!!!\n");
    while(1);
}

void HaltDabort(void)
{
    Uart_Printf("Dabort exception!!!\n");
    while(1);
}

⌨️ 快捷键说明

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