 In this section, I will shortly present basic information about scheduler within 3-year task. We are using operating systems to manage multiple tasks, many applications within our code. We can call it multitasking. Having one core, we can execute only one task at the moment, so we need some algorithm to manage it and to switch between the tasks. This is the main role of the scheduler. Usually, schedulers can work within cooperative or pre-emptive configuration. Let's start from cooperative multitasking. It requires cooperation of all of the tasks. The context can be switched only when a running task goes to blocked state, for example by call of OS-Delay function, or it goes to ready state, for example by call of OS-Treat yield function, or is pulled into suspend mode by the system or other task. Tasks are not preempted with higher priority tasks. There is no time slice preemption as well. To activate this mode of multitasking, it is needed to define the config use preemption and set it to 0 within 3R2S.h file. The next configuration is a preemptive one. It is a default within 3R2S. Within this configuration, tasks with the same priority share CPU time. Context can be switched when the task slice has passed. Task with higher priority has come. Task goes to blocked state by calling OS-Delay function. Task goes to ready state, for example by call OS-Treat yield function. And to activate this mode, it is needed to set to 1 config use preemption constant within 3R2S.h file. We will use this configuration within our examples during this session. Cooperative with preemption by interrupt multitasking. It is a combination of both cooperative and preemption multitasking modes. In this case, interrupts are used to trigger context switch. It is in fact a preemption system without time slice. To activate it, we need to set to 0 config use preemption within 3R2S.h file. Scheduling. The scheduler is an algorithm determining which task should be executed. As you remember, only one task can be executed at one time if we are considering the single-corm microcontroller like STM32 devices, at least most of them. Common point between schedulers is that they distinguish between the task being ready to be executed, so in ready state. And those being blocked or suspended are not taken into the consideration. The main difference between schedulers is how they distribute the CPU time between the tasks in ready state. Within 3R2S, there is a round-robin mechanism implemented. Round-robin can be used with either preemptive or cooperative multitasking, depending on config use preemption constant set in 3R2S config.h file. It works well if response time is not an issue and all the task has the same priority. The possession of the CPU changes periodically after a predefined execution time called time slice is coming. This time slice is defined with the config tick rate Hertz, which is defined in 3R2S config.h file. We can play as well with the execution time and the number of the tasks to be executed by setting the proper priorities for the tasks. So, in fact, by limiting the number of the tasks which are in a ready state. We will try to touch this topic later in this presentation. Now let's have a look at main functions available for scheduler management within CMC's OS V2 API. To initialize the RTOS kernel, we need to execute OS kernel initialize function. If we are using heap5 memory, this is the place where the heap regions needs to be initialized by calling the vport define heap region function. Then the second function is the function which is giving us information about the kernel. So it's version and ID if set. The function is OS kernel get info. If you would like to have information about the current kernel state, we need to call OS kernel get state function. And as you can see, it can return the values like OS kernel running, OS kernel locked, OS kernel ready or OS kernel inactive. Next group of the functions. The most important one is the first one OS kernel start. It is starting the operating system. It cannot be executed from interrupt. What this function is doing? It is setting the kernel state to OS kernel running. And it is executing vtask start scheduler from freer to SAPI. The second function OS kernel lock is used to freeze the operating system by suspending all of the tasks. The third one OS kernel unlock, it is reversing this process by resuming all of the tasks. To check the current lock state of the kernel, we can use OS kernel restore lock function. At the end, let's have a look on some supportive APA functions on scheduler. To get the RTOS kernel tick frequency, we should use OS kernel get tick frequency function. To get free RTOS kernel system timer count, we need to call OS kernel get system timer count function. And to get the free RTOS kernel system timer frequency, so cystic frequency, we need to call OS kernel cystic. Please have a look that all of those functions can be called as well from the user code and from the interrupt. Here in the table, we can see the comparison among different APIs concerning function on the free RTOS scheduler. In fact, CMC's OS APIs are calling functions from free RTOS API, what you can verify within code inspection of your application. As an example, OS kernel start is in fact calling vtask start scheduler from freer to SAPI, so original one. OS kernel lock is calling vtask suspend all, so suspending all of the tasks. OS kernel unlock is calling xtask resume all function from freer to SAPI. As you can see, CMC's OS API v2, which we are currently using within this training, is much more complete than the previous one, which has not all of the functions implemented. Thank you for watching this video.