FreeRTOS behind the scene Task Creation
Now let’s understand the FreeRTOS behind the scenes task management.
What happens when you create a task?
Let’s say you have a microcontroller RAM memory, and let’s say some amount of space, as shown in Figure 1, is reserved for the heap purpose.
The configTOTAL_HEAP_SIZE determines the amount of RAM that must be utilized for heap space. The rest of the RAM space can be used for global arrays, data, static variables, etc.
When you create a task by using xTaskCreate, it dynamically allocates memory for the task control block, and also, memory is allocated for the stack for Task 1, as shown in Figure 2.
When you create a task, you also mention the stack depth in terms of words.
For example, if the stack depth value is 512 words, then 512 x 4 bytes will be allocated as a stack in the heap memory. When you create another task, again, the task control block and the stack space for task 2 will be allocated in the heap memory, as shown in Figure 3.
After that, in the further course of the program, if you create a semaphore, then the semaphore control block will be created in a heap (Figure 4).
If you use queues, the queue control block and the queue item list will be dynamically created in a heap, as shown in Figure 5.
That’s how all these APIs will consume the heap whenever you create a task, semaphore, or queue. This is what happens behind the scenes when you create a task. All the items marked in Figure 6 are called dynamically created kernel objects.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1