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

📄 main.c

📁 UCOS S3C2440 移植源代码 ADS1.2 可以直接跑在开发板上
💻 C
字号:
/*=============================================================================
--------------------------------- Copy Left -----------------------------------
						    EMA2440     Project
						
					http://www.ema-tech.com.cn/home/products.php
						
----------------------------- File Description --------------------------------
 Filename:	Main.c
 Date:		2008.10.28
 Version:	0.0.1
 Description: something about interrupt

----------------------------- Version History ---------------------------------
 0.0.1: First release
=============================================================================*/
#include <stdlib.h>
#include <string.h>

#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
//#include "nand.h"
#include "320240_lcd.h"
#include "includes.h"

extern U32 touch_screen_x;
extern U32 touch_screen_y;
extern U32 touch_occur;
extern U32 touch=0;

extern U8 *Font16x16=(U8 *)0x31000000;
extern U8 *Font8x16=(U8 *)0x32000000;
U8 Font16x16buf[0x40000];
extern unsigned short LCD_BUFER[SCR_YSIZE_TFT_320240][SCR_XSIZE_TFT_320240];
extern unsigned char girl10_240_320[];	//240x320

extern void Nand_Read(U32 blockD,U8 *Save_Address,U32 ReadSize);
extern void InitNandFlash(void);
extern void ReadPage(U32 addr, U8 *buf);



#define	MainTaskStkLengh	1024*2   	// Define the MainTask stack length 
#define	Task0StkLengh		1024     	// Define the Task0 stack length 
#define	Task1StkLengh		1024*2   	// Define the Task1 stack length 
#define	Task2StkLengh		1024*2   	// Define the Task2 stack length 
#define	TaskUartStkLengh	1024    	// Define the TaskUart stack length 

//Task Prio
#define NormalTaskPrio       5
#define MainTaskPrio 	NormalTaskPrio
#define Task0Prio 		NormalTaskPrio+1
#define Task1Prio  		NormalTaskPrio+2
#define Task2Prio  		NormalTaskPrio+3
#define TaskUartPrio  	NormalTaskPrio+4


//任务说明
OS_STK  MainTaskStk[MainTaskStkLengh];
OS_STK	Task0Stk [Task0StkLengh];       // Define the Task0 stack 
OS_STK	Task1Stk [Task1StkLengh];       // Define the Task1 stack 
OS_STK	Task2Stk [Task2StkLengh];       // Define the Task1 stack 

//RTC相关变量
int rYear, rMonth,rDay,rDayOfWeek,rHour,rMinute,rSecond;

//任务3打印需要用
#define RGB(r,g,b)   (unsigned int)( (r << 16) + (g << 8) + b )
#define FROM_BCD(n)	 ((((n) >> 4) * 10) + ((n) & 0xf))


void Rtc_Init(void);


OS_EVENT *Semp;                         //Creat semp
U8 err;

void TEAM_infromation()
{
    Uart_Printf("\n");
	Uart_Printf("**************************************************\n");
	Uart_Printf("*                                                *\n");
	Uart_Printf("*        DEVILLE TEAM FOR UCOS_II                *\n");
	Uart_Printf("*        Version:0.0.1  2008/10/28               *\n");
	Uart_Printf("*                                                *\n");	
	Uart_Printf("**************************************************\n");
}


void TargetInit()
{
    Port_Init();
	Uart_Init(0, 115200);
	TEAM_infromation();
	Lcd_Tft_240X320_Init();
	Touch_Screen_Init();
	InitNandFlash();
	Nand_Read(3072,Font16x16,0x40000);
	Nand_Read(4000,Font8x16,0x4000);
}

static void StartTimeTick(void)
{
	INT32U ticf;				// Timer input clock Freauency
	
	
	Uart_Printf("\r\nstarttimetick() start!");
	
	rTCFG0 &= ~(0xff<<8);		// Prescaler1[15: 8]=0x00  (prescaler value=0)
	rTCFG1 &= ~(0xf<<16);		//       MUX4[19:16]=0000b (divider   value=2)

	// Timer input clock Freauency = PCLK / (prescaler value+1) / divider value
	ticf = PCLK / (0+1) / 2;		
	
	rTCNTB4 = ticf / OS_TICKS_PER_SEC;
	
	rTCON |=  (1<<22) | (1<<21);
	rTCON &= ~(1<<21);
	
	rTCON |=  (1<<20);			// Start for Timer4

	// TimeTick 
	pISR_TIMER4  = (unsigned)OSTickISR;		
	rINTMSK     &= ~(BIT_TIMER4);
	
	Uart_Printf("\r\nstarttimetick() end!");
}


void Task0	(void *pdata)  //Init lwip and create task2
{
 
	char *s="msg";
	char i;
	
	pdata = pdata; 
	
	while (1)
	{

       Uart_Printf("Enter Task0\n");	
       Uart_Printf("CPU Usage: %d%%\n",OSCPUUsage); //cpu usage XX%

       OSTimeDly(OS_TICKS_PER_SEC);
	}
}

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

    pdata = pdata; 

	Version=OSVersion();	
	
			
	while (1)
	{
	
	 TestCnt++;

     Uart_Printf("Enter Task1,Version is %d\n",Version);
     
    	
     OSTimeDly(OS_TICKS_PER_SEC*10);

	}
}


void Task2(void *pdata)
{
    unsigned int i, x, m, n, k, y;
    int tmp,key;         

    int width = 10;
    int height = 100;

    while(1)
    {
       Uart_Printf(" ENTER Task2\n");
       
       Lcd_Tft_240X320();
       Lcd_printf(LCD_BUFER,0,0,0x3f,0xffff,"中国");
        
 	   OSTimeDly(OS_TICKS_PER_SEC*10);
    }
}

void MainTask(void *pdata) //Main Task create taks0 and task1
{
   
   #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
   OS_CPU_SR  cpu_sr;
   #endif
   
    StartTimeTick();
	
	OSStatInit();
	OSTaskCreate (Task0,(void *)0, &Task0Stk[Task0StkLengh - 1], Task0Prio);	
	OSTaskCreate (Task1,(void *)0, &Task1Stk[Task1StkLengh - 1], Task1Prio);	
	OSTaskCreate (Task2,(void *)0, &Task2Stk[Task2StkLengh - 1], Task2Prio);	
	 
	 while(1)
	 {
	 
	    OSTimeDly(OS_TICKS_PER_SEC*10);
	    Uart_Printf("Enter Main Task\n");	 	 
	 }

}

int Main(int argc, char **argv)
{
	
	TargetInit(); 
	
	//初始化uC/OS   
   	OSInit ();	 
   	
   	//初始化系统时基
   	OSTimeSet(0);
   	
   	//创建系统初始任务
   	OSTaskCreate (MainTask,(void *)0, &MainTaskStk[MainTaskStkLengh - 1], MainTaskPrio);																										
	
	OSStart ();
	
	return 0;
}

⌨️ 快捷键说明

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