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

📄 main.c

📁 移植好的UCOS2.86版
💻 C
📖 第 1 页 / 共 2 页
字号:
  			rEP3_DMA_TTC_M=0xff;
  			rEP3_DMA_TTC_H=0xf;
  		}
			}	
 		else
 		{
 			rDIDST2=(downloadAddress+0x80000-8);  //for 1st autoreload.
	  			rDIDSTC2=(1<<2)|(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("\n(%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	  

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

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


	if(download_run==1)
	{
		register void(*run)(void);	//hzh,使用寄存器变量以防止禁止DCACHE后数据不一致!!!
		rINTMSK=BIT_ALLMSK;
		run=(void (*)(void))downloadAddress;	//使用DCACHE且RW区也在CACHE区间downloadAddress会在cache中
		{	//hzh
			MMU_DisableDCache();	//download program must be in 
    		MMU_DisableICache();	//non-cache area
    		MMU_InvalidateDCache();	//使所有DCACHE失效,本程序的MMU_Init中将会刷新DCACHE到存储器,
    								//为使应用此MMU_Init方式的程序能被正确运行必须先使DCACHE失效!!!
    		MMU_DisableMMU();
    		//call_linux(0, 193, downloadAddress);	//或不用上面3个函数而直接使用call_linux
		}
	run();
	}
}

//*****[Interrupt Service Routines initial/中断服务程序初始化]*****
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(所有中断为IRQ模式)
	rINTMSK     = BIT_ALLMSK;	             // All interrupt is masked.(屏蔽所有中断程序)

//******************************by xm
#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);
	//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);
}


void delay (U32 time)
{
   U32 j;
   while(time--)
   for(j=0;j<100000;j++);   
}

//***************************[Hardware_init]*************************
void hardware_init(void)
{
    char *mode;
	int i,j;
	U8 key=0;
	
    delay(1);   
    Led_Display(1);  
	delay(1);   
    Led_Display(0);
     
    #if ADS10   
 	__rt_lib_init(NULL,NULL);                      //for ADS 1.0
	#endif
	
	Port_Init();

	ChangeClockDivider(13,12);      //HCLK==133M,PCLK==66.5M
	cal_cpu_bus_clk();
	
 	MMU_EnableICache();  
 	  
//	Uart_Init(0,115200);   //设置串口波特率
//	Uart_Select(1);            //选择串口
    consoleNum=boot_params.serial_sel.val&1;	// Uart 1 select for debug.
	Uart_Init(0,boot_params.serial_baud.val);
	Uart_Select(consoleNum); 	
	Isr_Init();
	Uart_Printf("\nPCLK=%dHz,HCLK=%dHz,FCLK=%dHz,UCLK=%dHz",PCLK,HCLK,cpu_freq,UCLK);
	/*
	// 从nand flash里面读取配置信息
	// don't use 100M!
	i = search_params();  //返回0表示找到启动参数(Nand or Nor)没有出错	
	
	if(!i)
		Uart_Printf("Found boot params\n"); 
	else if(i==-1) {
		Uart_Printf("Fail to found boot params!\n");
		save_params();
	} else if(i==-2)
			Uart_Printf("Fail to read EEPROM!\n");
    Uart_Printf("boot_delay=%d",boot_params.boot_delay.val);

    Uart_Printf("\nPCLK=%dHz,HCLK=%dHz,FCLK=%dHz,UCLK=%dHz",PCLK,HCLK,cpu_freq,UCLK);
    Uart_Printf("\nrMPLLCON=%x,rUPLLCON=%x,rCLKDIVN=%x,rCAMDIVN=%x",rMPLLCON,rUPLLCON,rCLKDIVN,rCAMDIVN);

    // USB device detection control
	rGPGCON &= ~(3<<24);
	rGPGCON |=  (1<<24); // output
	rGPGUP  |=  (1<<12); // pullup disable
	rGPGDAT |=  (1<<12); // 输出为1(使能)	    
     // USBH1 Device 初始化
	rMISCCR=rMISCCR&~(1<<3);    // USBH1  配置为device
	rMISCCR=rMISCCR&~(1<<13);   // USB 1  端口配置.
	isUsbdSetConfiguration = 0; // USB 是否连接标志初始化为0
   	rDSC0 = 0x2aa;    //设置端口驱动能力
	rDSC1 = 0x2aaaaaaa;  
	UsbdMain();   
    */
    MMU_Init();
    Delay(0); 
   	download_run=1; //The default menu is the Download & Run mode.
	
}
//***************************[主函数]*************************
int Main(void)
{   
    //初始化目标板
	hardware_init();
		
	//初始化uC/OS   
   	OSInit ();	 
   	
   	//初始化系统时基
   	//OSTimeSet(0);
   	
   	//创建系统初始任务
   	OSTaskCreate (MainTask,(void *)0, &MainTaskStk[MainTaskStkLengh - 1], MainTaskPrio);																										
	
	OSStart ();
	
	return 0;
}

/*-----------------------------------------------------------------------
* 开始任务:
*	   建立其它任务和任务的通信方式;打开系统的时钟,以及所有的中断,,
*
*/
void MainTask(void *Id )
{
    OSTaskCreate (Task0,(void *)0, &Task0Stk[Task0StkLengh - 1], Task0Prio);	
	OSTaskCreate (Task1,(void *)0, &Task1Stk[Task1StkLengh - 1], Task1Prio);	
	OSTaskCreate (Task2,(void *)0, &Task2Stk[Task2StkLengh - 1], Task2Prio);	 
	
	Timer0Init();//initial timer0 for ucos time tick
	ISRInit();   //initial interrupt prio or enable or disable
    Uart_Printf("Enter MainTask\n");	    
	OSTaskDel(OS_PRIO_SELF);			 //删除本任务
}


void Task0	(void *pdata)//Init lwip and create task2
{
 
	char i;
	
	for(;;)
	{
    	
    Uart_Printf("Enter Task0\n");	
    //Uart_Printf("CPU Usage: %d%%\n",OSCPUUsage); //cpu usage XX%

    OSTimeDly(OS_TICKS_PER_SEC);
//OSTimeDlyHMSM(0,0,0,500);
	}
}

void Task1	(void *pdata) //task for test
{
	U16 TestCnt=0;
	U16 Version;


	Version=OSVersion();	
	
			
	for(;;)
	{
	
	 TestCnt++;
     Uart_Printf("********************************\n");
     Uart_Printf("Task1 Cnt=%d\n",TestCnt);	
     Uart_Printf("Enter Task1\n");
     Uart_Printf("uC/OS Version:V%4.2f\n",(float)Version*0.01);//ucos version 
     Uart_Printf("********************************\n");
     
     OSTimeDly(1);
//OSTimeDlyHMSM(0,0,0,200);
	}
}


void Task2(void *pdata)
{
    unsigned int i;
         

        
    Uart_Printf("Task LCD Running...\r\n");

    //===========================
    // RTC初始化
    //===========================
    Rtc_Init();
	
	//LCD 初始化
	LcdInit();

    for(;;)
    {
    
    	i++;
    	if(i>99)i=0;

		if(rBCDYEAR==0x99)
			rYear = 1999;
		else
			rYear    = (2000 + rBCDYEAR);
			rMonth   = FROM_BCD(rBCDMON & 0x1f);
			rDay		= FROM_BCD(rBCDDAY & 0x03f);
			rDayOfWeek = rBCDDATE-1;
			rHour    = FROM_BCD(rBCDHOUR & 0x3f);
			rMinute     = FROM_BCD(rBCDMIN & 0x7f);
			rSecond     = FROM_BCD(rBCDSEC & 0x7f);

        
      // OSTimeDly( 5 );
       Uart_Printf("Task LCD.\n");
       //在LCD上打印时间
       Lcd_printf(100,0,RGB( 0xFF,0xFF,0xFF),RGB( 0x00,0x00,0x00),0,"%02d:%02d:%02d\n", rHour, rMinute, rSecond);
       //在LCD上打印日期,星期
       Lcd_printf(0,15,RGB( 0xFF,0xFF,0xFF),RGB( 0x00,0x00,0x00),0,"%4d-%02d-%02d 星期%d      中国移动\n",
        	      rYear, rMonth, rDay,rDayOfWeek);
       
       Lcd_printf(0,230,RGB( 0xFF,0xFF,0xFF),RGB( 0x00,0x00,0x00),0," 友善之臂uC/OS2任务演示中:%02d" , i);
       
OSTimeDly(OS_TICKS_PER_SEC/5);
//OSTimeDlyHMSM(0,0,0,250);
	 //  mydelay(100);
    }
}


   	
/*
	while (1)
	{ 
	  delay(3);
	  //	Led_Display(0xf);   // real ECC Error
	  Led_Display(1); 
	  delay(3);
	  Led_Display(0);
	  
	  if(menuUsed==1)Menu();
	  WaitDownload();	
	} 
	
}*/

⌨️ 快捷键说明

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