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

📄 44mon.c

📁 smdk441f monitor program. 用ADS1.2编译
💻 C
字号:
#include <string.h>
#include "option.h"
#include "def.h"
#include "k44.h"
#include "k44lib.h"
#include "iflashl.h"

void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void)=(void (*)(void))DOWNLOAD_ADDRESS;
void (*run2)(void)=(void (*)(void))0x1f00000;

volatile unsigned char *downPt;
volatile U32 uartError;

void Isr_Init(void);
void __irq Uart_RxInt(void);
void __irq Uart_ErrInt(void);


void SramTest(U32 endAddr);
void IsramTest(U32 endAddr);
void SramTestByte(U32 endAddr);

void Main(void)
{
    int i;
    int isFlashProg=0;
    unsigned int fileSize;
    unsigned short int checkSum=0,dnCS;

    Port_Init();

    ChangePllValue(PLL_M,PLL_P,PLL_S);

    //rFMACON=0x81;           //rFMACON is configured properly

    Delay(0);   //calibrate Delay() using the WDT.
    Isr_Init();
    Uart_Init(57600);

    Led_Display(0x0);
    
    pISR_SWI=(_ISR_STARTADDRESS+0x70);	  //dummy for pSOS

    downPt=(unsigned char *)DOWNLOAD_ADDRESS;

    Uart_Printf("\n\nK44MON Ver 1.02 for S3F441FX 5/JUN/2000\n");
    Uart_Printf("COM:57.6kbps,8Bit,NP, <n+6>(4)+(n)+CS(2)\n");
    Uart_Printf("DNADDR:%x ISR_ADDR:%x SYSCFG:%x \n",DOWNLOAD_ADDRESS,_ISR_STARTADDRESS,rSYSCFG );
    Uart_Printf("E-mail:purnnamu@sec.samsung.com\n\n");
    Uart_Printf("History\n");
    Uart_Printf("1.02: Some file can't be downloaded. So,it's fixed.\n");

    Uart_Printf("  r: Branch into 0x1f00000.\n");
    Uart_Printf("  f: Write the downloaded program into the iflash.\n");
    Uart_Printf("  e: Erase the iflash.\n");

        
#if (INTERNAL_SRAM)
    SramTest(0x83ffff);
#else
    SramTest(0x83f000);
#endif

#if (INTERNAL_SRAM)
    IsramTest(0x1ff1000);
#else
    IsramTest(0x1ff1fff);
#endif
   
    i=0;
    *( (U8 *)(DOWNLOAD_ADDRESS+0) )=0x0;
    downPt=(volatile unsigned char *)DOWNLOAD_ADDRESS;
    uartError=0;
    
    while(( (unsigned int)downPt-DOWNLOAD_ADDRESS )<4)
    {
	Led_Display(0xf);
	Delay(1000);
	Led_Display(0x0);
	Delay(1000);
	switch(*( (U8 *)(DOWNLOAD_ADDRESS+0) ))
	{
	case 'r':
	    Delay(1000);
            if((U32)downPt==DOWNLOAD_ADDRESS+1)
	    {
		Uart_Printf("[The code at 1f00000 be executed.]\n");
		run2();  //wait 0.5 sec after 'r' key is pressed.
	    }
	    break;

	case 'f':
	    Delay(1000);
            if((U32)downPt==DOWNLOAD_ADDRESS+1)
	    {
		Uart_Printf(">Flash writing mode is selected.\n");
		isFlashProg=1;
		downPt=(volatile unsigned char *)DOWNLOAD_ADDRESS;
		*( (U8 *)(DOWNLOAD_ADDRESS+0) )=0x0;
	    }
	    break;

	case 'e':
	    Delay(1000);
            if((U32)downPt==DOWNLOAD_ADDRESS+1)
	    {
		Uart_Printf(">Flash Erase:START");
		Iflash_EraseSectors(0,511);
		downPt=(volatile unsigned char *)DOWNLOAD_ADDRESS;
		*( (U8 *)(DOWNLOAD_ADDRESS+0) )=0x0;
		Uart_Printf("\r>Flash Erase:END  \n");
	    }
	    break;
	default:
	    break;
	}
    }

    fileSize=*((unsigned char *)(DOWNLOAD_ADDRESS+0))+
	     (*((unsigned char *)(DOWNLOAD_ADDRESS+1))<<8)+
	     (*((unsigned char *)(DOWNLOAD_ADDRESS+2))<<16)+
	     (*((unsigned char *)(DOWNLOAD_ADDRESS+3))<<24);

    Uart_Printf("\nNow, Downloading... [FILESIZE:%7d]\nSTATUS:",fileSize);

    while(((int)downPt-DOWNLOAD_ADDRESS)<fileSize)
    {
	if((((int)downPt-DOWNLOAD_ADDRESS)%1000)==0)Uart_Printf("#");
	if(uartError!=0){Uart_Printf("E");uartError=0;}
    }
    
    for(i=4;i<(fileSize-2);i++)
    {
	checkSum+=*((unsigned char *)(i+DOWNLOAD_ADDRESS));
    }
    dnCS=*((unsigned char *)(DOWNLOAD_ADDRESS+fileSize-2))+
	 (*( (unsigned char *)(DOWNLOAD_ADDRESS+fileSize-1) )<<8);

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

    Uart_Printf("\nDownload O.K.\n");

    for(i=4;i<(fileSize-2);i++) //Move the program from 0x800004 to 0x800000
    {
	*((unsigned char *)(i+DOWNLOAD_ADDRESS-4))
	    =*((unsigned char *)(i+DOWNLOAD_ADDRESS));
    }

    if(isFlashProg)
    {

	for(i=0;i<fileSize-6;i+=4)
	    Iflash_WrWord( i,*((U32 *)(i+DOWNLOAD_ADDRESS)) );
	Uart_Printf("iflash programming is completed!!!\n");
	while(1);
    }
 	    
    run();
}






void Isr_Init(void)
{
    rINTMODE=0x0;		//all IRQ
    rINTPEND=0x0;		//clear all pending bits
    rINTMASK=BIT_URXD|BIT_UERR;	//URXD is enabled.
    rSYSCON =rSYSCON|0x100; 	//Enable global interrupt control.

    rINTPRI0=0x03020100|((U32)0x7<<29); //to utilize H/W vectored interrupt
    rINTPRI1=0x07060504;
    rINTPRI2=0x0b0a0908;
    rINTPRI3=0x0f0e0d0c;
    rINTPRI4=0x13121110;
   	    
    /*pISR_FIQ,pISR_IRQ must be initialized*/
    pISR_URXD=(unsigned)Uart_RxInt;
    pISR_UERR=(unsigned)Uart_ErrInt;

}


void __irq Uart_RxInt(void)
{
    rINTPEND=~BIT_URXD ;  //clear URXD pending bit
    *downPt++=rRBR;
}

void __irq Uart_ErrInt(void)
{
    rINTPEND=~BIT_UERR ;  //clear UERR pending bit
    uartError=1;
}


void SramTest(U32 endAddr)
{
    int i,j;
    int memError=0;

    Uart_Printf("\n256KB SRAM(nCS1) Test(%xh-%xh):WR",0x800000,endAddr);

    for(i=0x800000;i<endAddr;i+=4)
    {
	*((volatile unsigned *)i)=i;
    }
    Uart_Printf("\b\bRD");

    for(i=0x800000;i<endAddr;i+=4)
    {
	j=*((volatile unsigned *)i);
	if(j!=i){memError=1;break;}
    }
    if(memError==0)Uart_Printf("\b\bO.K.\n");
    else Uart_Printf("\b\bFAIL\n");
}



void IsramTest(U32 endAddr)
{
    int i,j;
    int memError=0;

    Uart_Printf("\nInternal SRAM Test(%xh-%xh):WR",0x1ff0000,endAddr);

    for(i=0x1ff0000;i<endAddr;i+=4)
    {
	*((volatile unsigned *)i)=i;
    }
    Uart_Printf("\b\bRD");

    for(i=0x1ff0000;i<endAddr;i+=4)
    {
	j=*((volatile unsigned *)i);
	if(j!=i)memError=1;
    }
    if(memError==0)Uart_Printf("\b\bO.K.\n");
    else Uart_Printf("\b\bFAIL\n");
}


⌨️ 快捷键说明

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