Considering a code base where we have a main(). After calling the kernel start function, we have the OS running.
Now in the context of which thread does the code snippet after the kernel start function call runs?
int main()
{
/* DO SOMETHING */
/* Start scheduler */
osKernelStart();
/* Infinite loop */
while (1)
{
/* USER CODE */
}
}
In the give code snippet, what is the context of "USER CODE" Thanks in Advance
For RTOSs, it's typical that the function that starts the Kernel or Scheduler does not return to main unless an error occurs. For FreeRTOS, vTaskStartScheduler() does not return unless there is insufficient RAM. For uC/OS-III, OSStart() does not return. These are just two examples.
Starting the Kernel/Scheduler puts the Scheduler in control. The scheduler will then determine the highest priority task that is ready to run and allow that task's context to run until the next opportunity for a context switch. For embedded systems, the scheduler typically repeats this process forever (i.e., until power is removed). So the RTOS Start function never returns.
The main() function is not a task and it only runs before the RTOS is started. Typically main() should create one or more tasks before calling the RTOS start function. Any code in main after calling the RTOS start function would typically never execute unless there were an error when starting the RTOS.