在freertos的其他任务中创建任务 [英] creating task inside other task in freertos

查看:423
本文介绍了在freertos的其他任务中创建任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是RTOS新手,我正在为汽车创建一个简单的实时系统

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 );
}

当我调试该代码时,它挂在xTaskCreate上而不执行新任务 然后我在手册和互联网上搜索了有关此内容的信息,但没有找到任何内容.

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.

有人会告诉我这是否可以在RTOS中进行或者我做错了吗?

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

推荐答案

可以在启动调度程序之前(从main)创建任务,也可以在启动调度程序之后(从另一个任务)创建任务. xTaskCreate()API文档在这里: http://www.freertos.org/a00125.html .您还将在FreeRTOS .zip主文件下载中找到一组演示任务,这些演示任务演示了如何从另一个任务创建和删除任务.查看FreeRTOS/Demo/Common/Minimal/death.c文件(自杀任务死亡,因为它们在创建后会自动删除).

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).

如果xTaskCreate()返回NULL,则您可能已经用完了堆空间.参见 http://www.freertos.org/a00111.html .我认为zip文件下载中提供的数百个或预先配置的示例中,大多数都对此有注释.

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.

这篇关于在freertos的其他任务中创建任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆