Board logo

标题: FreeRTOS中有关任务Task使用的疑惑 [打印本页]

作者: cuicaifeng    时间: 2013-11-8 14:41     标题: FreeRTOS中有关任务Task使用的疑惑

最近在学习FreeRTOS,找到一些例子,在一个外国的例子中,有关任务的建立和定义,我觉得不太理解,上代码:

int main( void )
{
    /* Create one of the two tasks. */
   
xTaskCreate( vTaskFunction,   /* Pointer to the function thatimplements the task. */
                   "Task 1",    /* Text name for thetask.  This is to facilitate debugging only. */
                   1000,     /* Stack depth - most smallmicrocontrollers will use much less stack than this. */
                   (void*)pcTextForTask1, /* Pass the text to be printed in asthe task parameter. */
                   1,      /* This task will run at priority1. */
                   NULL );     /* We are not using the taskhandle. */

    /* Create the other task in exactly the same way.  Notethis time that we
    are creating the SAME task, but passing in a differentparameter.  We are
    creating two instances of a single task implementation. */
   
xTaskCreate( vTaskFunction, "Task 2", 1000, (void*)pcTextForTask2, 1,NULL );
    /* Start the scheduler so our tasks start executing. */
    vTaskStartScheduler();
    /* If all is well we will never reach here as the scheduler willnow be
    running.  If we do reach here then it is likely thatthere was insufficient
    heap available for the idle task to be created. */
    for( ;; );
    return 0;
}
/*-----------------------------------------------------------*/
void vTaskFunction( void *pvParameters )
{
    char *pcTaskName;
    volatile unsigned long ul;
    /* The string to print out is passed in via theparameter.  Cast this to a
    character pointer. */
    pcTaskName = ( char * ) pvParameters;
    /* As per most tasks, this task is implemented in an infiniteloop. */
    for( ;; )
    {
        /* Print out the name of this task. */
        vPrintString( pcTaskName );
        /* Delay for a period. */
        for( ul = 0; ul <mainDELAY_LOOP_COUNT; ul++ )
        {
            /* This loop is just a verycrude delay implementation.  There is
            nothing to do inhere.  Later exercises will replace this crude
            loop with a properdelay/sleep function. */
        }
    }
}



正如诸位所看到的,main函数里有两个xTaskCreate,建立了两个任务,而入口地址均为vTaskFunction,编译后没问题,不知大侠们如何解释这个啊??谢谢!




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0