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

📄 main.c

📁 建立两个任务
💻 C
字号:
//#include "..\inc\44b.h"
#include "C:\Documents and Settings\Administrator\桌面\inc\44blib.h"
#include "C:\Documents and Settings\Administrator\桌面\inc\option.h"
#include "C:\Documents and Settings\Administrator\桌面\inc\def.h"
#include "C:\Documents and Settings\Administrator\桌面\ucosii\includes.h"
#include "C:\Documents and Settings\Administrator\桌面\ucosii\os_cfg.h"
#include "C:\Documents and Settings\Administrator\桌面\ucosii\os_cpu.h"
#include "C:\Documents and Settings\Administrator\桌面\ucosii\usos_ii.h"



//extern void OSSchedUnlock(void);
//extern void OSSchedLock(void);

#define printf Uart_Printf

//**********************************************************
// THE MAIN FUNCTION BODY
//**********************************************************
#define	N_TASKS			3					// Number of tasks
#define	TASK_STK_SIZE	1024				// Stack size, in sizeof OS_STK, or int 32bit

OS_STK	TaskStk[N_TASKS][TASK_STK_SIZE];	// Tasks stacks

void Task1(void *);
void Task2(void *);
//void Task3(void *);

int main(int argc, char **argv)
{
	int	task_1 = 0, task_2 = 1;//,task_3 = 2;

	sys_init();
	

	Uart_Printf("\n ### Main Starts !\n");

	OSInit();
	OSTaskCreate(Task1, &task_1, &TaskStk[0][TASK_STK_SIZE-1], 1);
	OSTaskCreate(Task2, &task_2, &TaskStk[1][TASK_STK_SIZE-1], 2);
	//OSTaskCreate(Task3, &task_3, &TaskStk[2][TASK_STK_SIZE-1], 3);
	
	OSStart();

	return 0;
}

void Task1(void * pParam)
{
	Uart_Printf(" @@@ Task1 will starts time ticker !\n");

	// enable Ticker, 16 ticks per second
	tick_init(127);
	// why start tick here? see uCOS-II Doc Chapter 8 :
	/* 
	"You MUST enable ticker interrupts AFTER multitasking has started, i.e. after 
	calling OSStart().  In other words, you should initialize and tick interrupts in
	the first task that executes following a call to OSStart().  A common mistake is
	to enable ticker interrupts between calling OSInit() and OSStart() ..."
	*/
	
	while(1)	
	{
		OSSchedLock();
		printf( "@@@\n");
		printf( "@@@  task 1 running ... \n" );
		printf( "@@@     Q__Q    \n" );
		printf( "@@@    /____\\   \n" );
		printf( "@@@    \\____/   \n" );
		printf( "@@@     /\\/\\    \n" );
		printf( "@@@  __(\\\\//)__ \n" );
		printf( "@@@  >__/w w\\__< \n" );
		printf( "@@@\n" );
		printf( "@@@  go to sleep 1 time-ticks\n" );
		printf( "@@@\n" );

		OSSchedUnlock();
		Sleep(1);
	}

}

void Task2(void * pParam)
{	
	
	
	while(1)	
	{
		OSSchedLock();
		printf( "+++ \n" );
		printf( "+++  task 2 running ... \n" );
		printf( "+++  ╭︿︿︿╮ \n" );
		printf( "+++ {/ o o \\} \n" );
		printf( "+++  ( (oo) ) \n" );
		printf( "+++      ︶ \n" );
		printf( "+++ \n" );
		printf( "+++  go to sleep 3 time-ticks\n" );
		printf( "+++ \n" );
			
		OSSchedUnlock();
		Sleep(3);
	}
}















⌨️ 快捷键说明

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