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

📄 u241mon.c

📁 USBONs3c2410.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
    U16 cs;
    U32 temp;
    U16 dnCS;
    int first=1;
    float time;
    U8 tempMem[16];
    U8 key;
    
    checkSum=0;
    downloadAddress=(U32)tempMem; //_RAM_STARTADDRESS; 
    downPt=(unsigned char *)downloadAddress;
	//This address is used for receiving first 8 byte.
    downloadFileSize=0;
    
#if 0
    MMU_DisableICache(); 
        //For multi-ICE. 
        //If ICache is not turned-off, debugging is started with ICache-on.
#endif
#if 1
    /*******************************/
    /*    Test program download    */
    /*******************************/
    j=0;

    if(isUsbdSetConfiguration==0)
    {
	Uart_Printf("USB host is not connected yet.\n");
    }

    while(downloadFileSize==0)
    {
        if(first==1 && isUsbdSetConfiguration!=0)
        {
            Uart_Printf("USB host is connected. Waiting a download.\n");
            first=0;
        }

		if(j%0x50000==0)Led_Display(0x6);
		if(j%0x50000==0x28000)Led_Display(0x9);
		j++;

		key=Uart_GetKey();
		if(key!=0)
		{
	    	Menu();
            first=1; //To display the message,"USB host ...."
		}

    }
#endif
    Timer_InitEx();      
    Timer_StartEx();  

#if USBDMA    

    rINTMSK&=~(BIT_DMA2);  

    ClearEp3OutPktReady(); 
    	// indicate the first packit is processed.
    	// has been delayed for DMA2 cofiguration.

    if(downloadFileSize>EP3_PKT_SIZE)
    {
        if(downloadFileSize<=(0x80000))
        {
      	    ConfigEp3DmaMode(downloadAddress+EP3_PKT_SIZE-8,downloadFileSize-EP3_PKT_SIZE);	
  	    	//wait until DMA reload occurs.
	    	while((rDSTAT2&0xfffff)==0)
	    		;
      	    //will not be used.
       	    rDIDST2=(downloadAddress+downloadFileSize-EP3_PKT_SIZE);  
       	    rDIDSTC2=(0<<1)|(0<<0);  
	    	rDCON2=rDCON2&~(0xfffff)|(0);        	    
		}
      	else
      	{
      	    ConfigEp3DmaMode(downloadAddress+EP3_PKT_SIZE-8,0x80000-EP3_PKT_SIZE);
  	    	//wait until DMA reload occurs.
	   		while((rDSTAT2&0xfffff)==0);
      	    
    	    if(downloadFileSize>(0x80000*2))//for 1st autoreload
    	    {
        		rDIDST2=(downloadAddress+0x80000-8);  //for 1st autoreload.
        		rDIDSTC2=(0<<1)|(0<<0);  
    	 		rDCON2=rDCON2&~(0xfffff)|(0x80000);        	  

  				while(rEP3_DMA_TTC<0xfffff)
  				{
  		   	 		rEP3_DMA_TTC_L=0xff; 
  		    		rEP3_DMA_TTC_M=0xff;
  		   	 		rEP3_DMA_TTC_H=0xf;
  				}
   			}		
 	    	else
 	    	{
 	       		rDIDST2=(downloadAddress+0x80000-8);  //for 1st autoreload.
      	        rDIDSTC2=(0<<1)|(0<<0);  
 	        	rDCON2=rDCON2&~(0xfffff)|(downloadFileSize-0x80000); 		

  				while(rEP3_DMA_TTC<0xfffff)
  				{
  		    		rEP3_DMA_TTC_L=0xff; 
  		    		rEP3_DMA_TTC_M=0xff;
  		    		rEP3_DMA_TTC_H=0xf;
  				}
	    	}
		}
 		totalDmaCount=0;
    }
    else
    {
		totalDmaCount=downloadFileSize;
    }
#endif

    Uart_Printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
    		downloadAddress,downloadFileSize);
    Uart_Printf("RECEIVED FILE SIZE:%8d",0);

#if USBDMA    
    j=0x10000;

    while(1)
    {
    	if( (rDCDST2-(U32)downloadAddress+8)>=j)
		{
	    	Uart_Printf("\b\b\b\b\b\b\b\b%8d",j);
   	    	j+=0x10000;
		}
		if(totalDmaCount>=downloadFileSize)break;
    }

#else
    j=0x10000;

    while(((U32)downPt-downloadAddress)<(downloadFileSize-8))
    {
		if( ((U32)downPt-downloadAddress)>=j)
		{
	    	Uart_Printf("\b\b\b\b\b\b\b\b%8d",j);
   	    	j+=0x10000;
		}
    }
#endif
    time=Timer_StopEx();
    Uart_Printf("\b\b\b\b\b\b\b\b%8d",downloadFileSize);	
    Uart_Printf("(%5.1fKB/S,%3.1fS)\n",(float)(downloadFileSize/time/1000.),time);
    
#if USBDMA    
    /*******************************/
    /*     Verify check sum        */
    /*******************************/

    Uart_Printf("Now, Checksum calculation\n");

    cs=0;    
    i=(downloadAddress);
    j=(downloadAddress+downloadFileSize-10)&0xfffffffc;
    while(i<j)
    {
    	temp=*((U32 *)i);
    	i+=4;
    	cs+=(U16)(temp&0xff);
    	cs+=(U16)((temp&0xff00)>>8);
    	cs+=(U16)((temp&0xff0000)>>16);
    	cs+=(U16)((temp&0xff000000)>>24);
    }

    i=(downloadAddress+downloadFileSize-10)&0xfffffffc;
    j=(downloadAddress+downloadFileSize-10);
    while(i<j)
    {
  		cs+=*((U8 *)i++);
    }
    
    checkSum=cs;
#else
    //checkSum was calculated including dnCS. So, dnCS should be subtracted.
    checkSum=checkSum - *((unsigned char *)(downloadAddress+downloadFileSize-8-2))
	     - *( (unsigned char *)(downloadAddress+downloadFileSize-8-1) );	
#endif	  
#if 0
    dnCS=*((unsigned char *)(downloadAddress+downloadFileSize-8-2))+
	(*( (unsigned char *)(downloadAddress+downloadFileSize-8-1) )<<8);

    if(checkSum!=dnCS)
    {
		Uart_Printf("Checksum Error!!! MEM:%x DN:%x\n",checkSum,dnCS);
		return;
    }
#endif
    Uart_Printf("Download O.K.\n\n");
#if 0
	Cmd_Receive((unsigned char *)downloadAddress,downloadFileSize-8-2);
	usb_cmd_parse(cmd_ext);
	usb_wd_flag=0;
#endif
#if 0
	Uart_Printf("the Download data is:");
	for(i=0; i<(downloadFileSize-8-2); i++)
	{
		Uart_Printf("%c",*(((unsigned char *)downloadAddress)+i));
		
	}
	Uart_Printf("\n");
#endif
	downloadFileSize==0;
	//Uart_TxEmpty(consoleNum);
#if 0
    if(download_run==1)
    {
        rINTMSK=BIT_ALLMSK;
    	run=(void (*)(void))downloadAddress;
		run();
    }
#endif
}




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
    rINTMSK=BIT_ALLMSK;	  // All interrupt is masked.

    //pISR_URXD0=(unsigned)Uart0_RxInt;	
    //rINTMSK=~(BIT_URXD0);   //enable UART0 RX Default value=0xffffffff

#if 1
    pISR_USBD =(unsigned)IsrUsbd;
    pISR_DMA2 =(unsigned)IsrDma2; 
#else
    pISR_IRQ =(unsigned)IsrUsbd;	
    	//Why doesn't it receive the big file if use this. (???)
    	//It always stops when 327680 bytes are received.
#endif    
    ClearPending(BIT_DMA2);
    ClearPending(BIT_USBD);
    //rINTMSK&=~(BIT_USBD);  
   
    //pISR_FIQ,pISR_IRQ must be initialized
}


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

int rdfile(const char *path)
{
	int fd;
	char buf[1024];
	int i;
	char c;
	int ret;
	fd=yaffs_open(path,O_RDWR, S_IREAD | S_IWRITE);
	if(fd<0)
	{
		Uart_Printf("Cannot read file %s\n",path);
		return 0;
	}
	ret=yaffs_read(fd,buf,256);
	while(ret > 0)
	{
		for(i=0; i<ret; i++)
		{
			Uart_Printf("%c",buf[i]);
			
		}
		ret=yaffs_read(fd,buf,256);
	}
	yaffs_close(fd);
	
}
int crtFile(const char * path,int s)
{
	int fd;
	char buf[999];
	int i;
	char c;
	int ret;

	c='a';
	for (i=0;i<256 ;i++ )
	{
		buf[i]=c;
		c++;
		if(c>'z')c='a';
	}
	
	fd=yaffs_open(path,O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	if (fd<0)
	{
		Uart_Printf("Cannot create file %s\n",path);
		return 0;
	}
	Uart_Printf("file %s created\n",path);
	for(i=0;i<s;i++)ret=yaffs_write(fd,buf,256);
	Uart_Printf("write %d bytes to /boot/test_b\n",ret);
	yaffs_close(fd);

}

int dumpDir(const char * path)
{
	//dump dir
	int fd;
	char buf[1024];
	int ret;
	int i;
	struct yaffs_stat stat;
	yaffs_DIR * ydir;
	struct yaffs_dirent * ydrent;

	ydir=yaffs_opendir(path);

	Uart_Printf("DumpDir %s\n",path);
	ydrent=yaffs_readdir(ydir);
	while(ydrent)
	{
		sprintf(buf,"%s/%s",path,ydrent->d_name);

		yaffs_lstat(buf,&stat);

		Uart_Printf("  %s Length:%d  Mode:%X  ",ydrent->d_name,stat.st_size,stat.st_mode);
		switch (stat.st_mode&S_IFMT)
		{
			case S_IFREG: Uart_Printf("boot file"); break;
			case S_IFDIR: Uart_Printf("directory"); break;
			case S_IFLNK: Uart_Printf("symlink -->");
						  if(yaffs_readlink(buf,buf,100) < 0)
						  	Uart_Printf("no alias");
						  else
							Uart_Printf("\"%s\"",buf);	 
						  break;
			default: Uart_Printf("unknown"); break;
		}
		Uart_Printf("\n");
		ydrent=yaffs_readdir(ydir);
	}
	yaffs_closedir(ydir);
}


⌨️ 快捷键说明

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