用taskInit 创建任务要注意堆栈的生长方向问题,程序例子如下:
int ret;
char *memArea;
/* initialize TCB and stack space */
memArea = (char *) malloc (STACK_ROUND_UP(STACK_SIZE) + sizeof (WIND_TCB) + 16);
/* initialize task */
ret = taskInit ((WIND_TCB *) (memArea + 16), NULL, 150, VX_NO_STACK_FILL,
#if (_STACK_DIR == _STACK_GROWS_DOWN)
(char *) (memArea + STACK_SIZE + sizeof (WIND_TCB)),
#else
memArea + STACK_ROUND_UP (sizeof (WIND_TCB) + 16),
#endif
STACK_SIZE, (FUNCPTR) function,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0); /* args */
if (ret == ERROR)
{
perror ("taskInit");
return(0);
}
else
{
taskActivate ((int) memArea);
}
WIND_TCB tMonitorTcb;
char tMonitorStack[STACK_SIZE];
或静态内存
status = taskInit(&tMonitorTcb, /* TCB Address */
"tMonitorMethod04", /* Task/Thread Name */
240, /* Priority 0=Highest */
VX_NO_STACK_FILL, /* Options */
/*
Determine which way stack grows and
adjust address if necessary
*/
#if (_STACK_DIR == _STACK_GROWS_DOWN)
tMonitorStack+STACK_SIZE, /* Stack base address */
#else
tMontiorStack, /* Stack base address */
#endif
STACK_SIZE, /* Stack size in bytes*/
(FUNCPTR) monitor, /* Task entry point */
0, 0, 0, 0, 0, 0, 0, 0, 0 ,0); /* VxW Req 10 parms */
/*
Task exists but is not running at this point. The debugger can now attach to the task
and set breakpoints provided the user does not detach or attach to some other task
*/
if (status == OK) /* Only activate if init ok */
status = taskActivate((int)&tMonitorTcb);/* Actually start task */
用户1378541 2006-11-20 22:00