FreeRTOS xTaskStartScheduler

I have a question. If I create a task with xTaskCreate(), and then start the scheduler with xTaskStartScheduler(), can I later on add new tasks? I think I can’t because I have to set the priority in xTaskCreate.. and then it would mess up the priority of others maybe? So If I cant, I have to create ALL tasks before I start the scheduler? And can I later on delete tasks while the scheduler is running?

FreeRTOS xTaskStartScheduler

You can create tasks before or after the scheduler has been started. You can delete tasks after the scheduler has been started. The following rather old (and interestingly still using version 7.x types in places) standard demo does nothing but create and delete tasks while the scheduler is running: https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Demo/Common/Minimal/death.c Note if you delete tasks you must allow the idle task to run occasionally as it performs some clean up. Regards.

FreeRTOS xTaskStartScheduler

Thanks! If I create a task with xTaskCreate() after the scheduler has started, does the new task automatically run? Don’t I have to call startScheduler() again or something alike?

FreeRTOS xTaskStartScheduler

vTaskStartScheduler() should only ever be called once. Any tasks created after the scheduler has started will automatically be added to the pool of tasks that are available to the scheduler, and will in fact run immediately if the task being created is given a priority that is higher than the task that created it. Look at the example in the link already posted above. Regards.

FreeRTOS xTaskStartScheduler

Thanks. Least number is least priority? Highest number is highest priority? Or the other way around? ( i guess least is least priority, because often you don’t know how many threads in the future are created))

FreeRTOS xTaskStartScheduler

Answers to all the questions you have asked so far can be found in the online docs. http://www.freertos.org/RTOS-task-priority.html Regards.

FreeRTOS xTaskStartScheduler

I have another question. For example, I have 1 class called Menu.cpp. The header looks like: – Menu() – void foo() In the contrustor I create 1 task. This task just does random code (it doesn’t matter). Then in the constructor, after the task is created, I call vTaskStartScheduler(). The Main looks like: { Menu menu; menu.foo(); } Will the code get to menu.foo(); ? I don’t know, because I read somewhere the code does not go past vTaskStartScheduler() unless there is a fatal error.

FreeRTOS xTaskStartScheduler

http://www.freertos.org/a00132.html