creating task inside other task in freertos

对着背影说爱祢 提交于 2019-12-24 10:54:23

问题


I am an RTOS newbie and I am creating a simple real time system for automotive

I am wondering if it possible to create a task inside another task. I tried to do this by the following method but it doesn't work.

 void vTask1 { *pvParameters){
unsigned portBASE_TYPE taskPriority;
taskPriority=uxTaskPriorityGet( NULL );
char x;
while (1){
 x= 5 ;
if (x==5)
xTaskCreate( vTask2 , "task2", 1000, "task2 is running", taskPriority+5 , NULL );
}

when I debug that code it hangs at xTaskCreate without executing the new task and I searched the manual and the internet for something about this but I didn't find any.

would anyone tell me is that possible to do in RTOS or I am doing it in a wrong way?


回答1:


Tasks can be created before the scheduler has been started (from main), or after the scheduler has been started (from another task). The xTaskCreate() API documentation is here: http://www.freertos.org/a00125.html . You will also find a set of demo tasks that demonstrate creating and deleting tasks from another task in the main FreeRTOS .zip file download. Look in the FreeRTOS/Demo/Common/Minimal/death.c file (death for suicidal tasks as they delete themselves after creation).

If xTaskCreate() returns NULL then you will probably have run out of heap space. See http://www.freertos.org/a00111.html. I think most of the hundreds or pre-configured examples that come in the zip file download have comments to this effect.




回答2:


Check the return value of xTaskCreate api.

one more thing the second task which you are creating is vtask2 which is having lower priority than vtask1 the one who is creating . And vtask1 is running in while(1) scheduler will not schedule vtask2. you can delay or suspend the vtask1 after creating vtask2.

then vtask2 may execute.



来源:https://stackoverflow.com/questions/25191990/creating-task-inside-other-task-in-freertos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!