EDN首页   博客首页

日志档案

发表于 2006-11-17 13:08:22

12

标签: vxworks创建任务中堆栈生长方向问题  

vxworks创建任务中堆栈生长方向问题

用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 */

 

系统分类: 嵌入式   |   用户分类: vxowrks任务调度   |   来源: 无分类   |   【推荐给朋友】   |   【添加到收藏夹】

    阅读(1049)    回复(1)  

投一票您将和博主都有获奖机会!