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

📄 createtask.c

📁 tornado2.0for powerpc.在低优先级任务级中可以创建高优先级任务,通过调试
💻 C
字号:
#include <vxWorks.h>
#include <stdio.h>
#include <stdlib.h>
#include <taskLib.h>
#include <sysLib.h>
#include "cretetask.h"
 
 #ifdef	__cplusplus
extern "C"{
#endif

int nLowId = 0x11;
int nHighId = 0x22;	 
	
 /*任务入口主函数*/ 
int HighTaskMain (void)
{	
	int nx =3;
	int ny = 4;
	int nz = nx + ny;
	printf("high task : ###%d\n",nz);	
	return 0;	
}
/*任务入口主函数*/
int LowTaskMain(void)
{		
	int ni = 1;
	int nj = 2;	
	int nsum;
	
	int nTaskIdH;/*创建高优先级任务*/		
	nHighId = taskSpawn("tHighTask", 40, VX_FP_TASK, 20000,	
	          (FUNCPTR)HighTaskMain, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	          
	/*判断任务是否创建成功*/
	if (ERROR != nHighId  &&  nLowId != nHighId)
	{
	 	printf("high task : nHighId = 0x%0x\n", nHighId);

		nTaskIdH = taskNameToId("tHighTask");//在高任务中 nHighId和nTaskIdH的值是否一样
		if (nTaskIdH == ERROR)
			printf("high task : Don't find tHigh Task!\n");
		else
		{
			printf("nTaskIdH = 0x%x\n", nTaskIdH);
		}	
		printf("high task : test hign priority create ok!\n");
	}
	else
	 {
	 	printf("high task : test hign create fail!\n");
	    return (ERROR);
	}
		
	nsum = ni + nj;	
	printf("low task :!!!%d\n",nsum);	
	DeleteTask ();
	return 0;
}

   
int DeleteTask ()
{/*		taskDelete (nLowId);
		taskDelete (nHighId);
*/
		printf (" low task: task delete finish !\n");	
		return 0;
}

 /*创建任务函数*/
int test(void)
{
	int nTaskId;
    printf("test create begin!\n");
	
	nLowId = taskSpawn("tLowTask", 110, VX_FP_TASK, 20000,	
	          (FUNCPTR)LowTaskMain, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	
	/*判断任务是否创建成功*/
	if ( ERROR != nLowId)
	{		
	 	printf("Low task :nLowId = 0x%0x\n", nLowId);			
		
		nTaskId = taskNameToId("tLowTask");//低任务,比较nLowId和nTaskId的值是否一样。
		if (nTaskId == ERROR)
			printf("Low task :Don't find tLowTask!\n");
		else
			{
				printf(" Low task :nTaskId =0x%x\n", nTaskId);
			}
		printf("Low task :test low priority create ok!\n");		
	}
	else
	{
		 printf("Low task :test low priority create fail!\n");
		 return (ERROR);
	}
	
printf("test create end!\n");

return (0);

}

#ifdef	__cplusplus
}
#endif	/* end of __cplusplus */

⌨️ 快捷键说明

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