 FreeR2S booting process, let's spend a while on a boot sequence and timing while we are executing the code with FreeR2S. So after there is set, we've got this hardware part, hardware dependent, and we are starting from configuration of the CPU clocks. Then we are infilizing the static and global variables that contains only the zero value, so this is the BSS section. Then there is an initialization of the variables that contains a value other than zero, so initialized variables. And there is a part to configure the hardware which is used within the system. After this, there is a FreeR2S related part, what you can see here below. It is based on some calculations present on the FreeR2S FAQs based on Cortex-M3 devices. At the beginning FreeR2S is creating the application queues, semaphores, and mutexes. It is taking more or less 500 CPU clock cycles per object. Then it is creating the application tasks. It is a bit bigger part, so it's more or less 1100 CPU clock cycles per task. And it is starting the RTS scheduler, which is more or less 1200 CPU clock cycles. Idle task. Idle task is a task which is generated automatically, created automatically by the scheduler after it is started. This task is executed always when the ready task list is empty. Its code is stored within task C file, within the macro port task function. The idle task is performing the following list of operations in endless loop. At the beginning it is checking the list of the deleted tasks, and it is cleaning the memory. It is an important point, because while we decide to delete the task, it is not deleted automatically from the RAM, but it will be deleted in the first execution of the idle task after this operation. Then the second role of idle task is execution of the task yield function, if we are not using preemption. So task yield means that we are immediately exiting the idle task code, and we are giving the chance for other tasks to be executed. Then if there is another task waiting, the idle task is immediately exiting the running state and going to the ready one. And if it is not the case, so if it is the only one which is executed at the moment, and we have enabled the idle hook, so if we send the config use idle hook to one, there would be the application idle hook called execution. And this code is used for some debug purposes, just to check how much time is spent within the idle task. It can be used for this way on the startup, on the development phase. One of the most important roles of the idle task is performing the low power entrance. If we configure the config use tick less idle to any value, to one order two, we can enter into the selected low power mode. By default it would be a sleep mode, but as you can see from the next sections of this training, we can use here as well the stop modes, which are limiting the current consumption of the application quite heavily, and which are still allowing us to wake up from the low power mode and continue the freeRTOS operations after wake up. Let's have a look at how freeRTOS starts step by step. We are starting freeRTOS by calling OS kernel start function, usually from main.c file. This is using the cmcsOS API. This function is calling vtask start scheduler within cmcs underscore sc file. This function, as you can see, this is the freeRTOS API 1. And this function is creating the idle task using the function xtask create. Then it is disabling the operating system interrupts by calling the file that the macro ported table interrupt to be sure that no tick will happen before we will start the scheduler. So after disabling operating system related interrupts, we are starting the scheduler by calling the function export start scheduler. This function within ported.c file is configuring the lowest priority level for cistik and pentasv, so the interrupts which are responsible for the task switching, the context switching within the operating system. Then it is starting the timer that generates the tick, so the time slice for each task. In Cortex-M architecture, it is usually the cistik. And this is the time when fpu self-loading point unit is enabled if we are working with Cortex-M4 or M7 devices. After this, there is, let's say, the call which is starting the first task that is done by calling the function prv port start first task function. So prv port start first task function from port.c file, usually it is written in assembler. It is locating the stack and setting the main stack pointer MSP used by the OS at the beginning of this stack. Of this stack I mean of the heap booked for the free R2S. Then it is enabling all the interrupts and it is triggering by software svc system call interrupt, which is the software interrupt and within this interrupt there is a handler called vport svc handler located again in port.c file and this handler is restoring the context. It's loading the task control block of the first task with highest priority from the ready list and it's starting execution of this task. From this moment operating system is fully operational and is starting executing the first task. Thank you for watching this video.