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

📄 401mon.c

📁 smdk40100 40mhz monitor code
💻 C
字号:
#include <string.h>
#include "..\include\option.h"
#include "..\include\k401.h"
#include "..\include\k401lib.h"
#include "..\include\def.h"

#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS
    
void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void)=(void (*)(void))DOWNLOAD_ADDRESS;

unsigned int (*frameBuffer)[10];

int error;

volatile unsigned char *downPt;


void Isr_Init(void);
void __irq Uart_RxInt(void);
void __irq Uart_Error(void);


void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);

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

    downPt=(unsigned char *)DOWNLOAD_ADDRESS;

    pISR_SWI=(_ISR_STARTADDRESS+0xf0);	  //for pSOS

    error=0;

    Led_Display(0xf);

    Delay(0);
    Isr_Init();
    Uart_Init(115200);

    Uart_Printf("\n\nK401MON Ver 0.0 for KS17C40100 22/DEC/99\n");
    Uart_Printf("COM:115.2kbps,8Bit,NP,UART0 <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:telecom2@sec.samsung.com\n");

    Uart_Printf("Memory Test(%xh-%xh):WR",_RAM_STARTADDRESS,(_ISR_STARTADDRESS&0xfff0000));

    for(i=_RAM_STARTADDRESS;i<(_ISR_STARTADDRESS&0xfff0000);i+=4)
    {
	*((volatile unsigned *)i)=i;
    }

    Uart_Printf("\b\bRD");
    for(i=_RAM_STARTADDRESS;i<(_ISR_STARTADDRESS&0xfff0000);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");

    Uart_Printf("Download User program to Data Memory\n");

    i=0;
    while(( (unsigned int)downPt-DOWNLOAD_ADDRESS )<4)
    {
	Led_Display(0xf);
        Delay(1000);
	Led_Display(0x0);
	Delay(1000);
    }

    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("Now, Downloading... [FILESIZE:%7d(      0)",fileSize);

    while(((int)downPt-DOWNLOAD_ADDRESS)<fileSize)
    {
	Uart_Printf("\b\b\b\b\b\b\b\b%7d)",(int)downPt-DOWNLOAD_ADDRESS);
    }
    Uart_Printf("\b\b\b\b\b\b\b\b%7d)\n",(int)downPt-DOWNLOAD_ADDRESS);

    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(error!=0)
    {
	Uart_Printf("UART Error!!! CODE:%x\n",error);
        restart();
    }

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

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

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

    run();
}


void Isr_Init(void)
{
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;

    rINTMOD=0x0;		//All=IRQ mode
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=(BIT_URX|BIT_UERR);		// Default value=0x0
	    
    /*pISR_FIQ,pISR_IRQ must be initialized*/
    pISR_URX=(unsigned)Uart_RxInt;
    pISR_UERR=(unsigned)Uart_Error;
}


void __irq Uart_RxInt(void)
{
    rINTPND=~(BIT_URX);		// Clear pending bits
    *downPt++=rURXH;		// is need only when cache=on & write buffer=off
}


void __irq Uart_Error(void)
{
    rINTPND=~(BIT_UERR);		// Clear pending bits
    error=(int)rUSTAT;
}

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 + -