本帖最后由 wdliming 于 2013-10-27 19:12 编辑
最近在学习FreeRTOS,找到一些例子,在一个外国的例子中,有关任务的建立和定义,我觉得不太理解,上代码:
int main( void )
{
/* Create one of the two tasks. */
xTaskCreate( vTaskFunction, /* Pointer to the function that implements the task. */
"Task 1", /* Text name for the task. This is to facilitate debugging only. */
1000, /* Stack depth - most small microcontrollers will use much less stack than this. */
(void*)pcTextForTask1, /* Pass the text to be printed in as the task parameter. */
1, /* This task will run at priority 1. */
NULL ); /* We are not using the task handle. */
/* Create the other task in exactly the same way. Note this time that we
are creating the SAME task, but passing in a different parameter. 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 will now be
running. If we do reach here then it is likely that there 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 the parameter. Cast this to a
character pointer. */
pcTaskName = ( char * ) pvParameters;
/* As per most tasks, this task is implemented in an infinite loop. */
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 very crude delay implementation. There is
nothing to do in here. Later exercises will replace this crude
loop with a proper delay/sleep function. */
}
}
}
正如诸位所看到的,main函数里有两个xTaskCreate,建立了两个任务,而入口地址均为vTaskFunction,编译后没问题,不知大侠们如何解释这个啊??谢谢!
|