FreeRTOS Lecture 24 – FreeRTOS behind the scene Task Creation

 

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.

Figure 1. RAM memory space reserved for the heap purpose.
Figure 1. RAM memory space reserved for the heap purpose.

 

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.

Memory allocated for the control block and stack of the Task 1
Figure 2. Memory allocated for the control block and stack of the Task 1.

 

Memory allocated for the control block and stack of the Task 2
Figure 3. Memory allocated for the control block and stack of the Task 2.

 

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.

Creation of semaphore control block
Figure 4. Creation of semaphore control block.

 

Creation of queue control block and queue item list
Figure 5. Creation of queue control block and queue item list.

 

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.

Dynamically created kernel objects
Figure 6. Dynamically created kernel objects.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.