内核启动后main()的线程上下文 [英] Thread Context of main() after Kernel start

查看:126
本文介绍了内核启动后main()的线程上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个具有main()的代码库.调用内核启动函数后,我们就可以运行操作系统了.

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

推荐答案

对于RTOS,除非发生错误,否则启动内核或调度程序的函数通常不会返回到main.对于FreeRTOS,除非没有足够的RAM,否则不会返回 vTaskStartScheduler().对于uC/OS-III,不会返回 OSStart().这只是两个例子.

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.

启动内核/调度程序将使调度程序处于控制状态.然后,调度程序将确定已准备好运行的最高优先级任务,并允许运行该任务的上下文,直到下一次进行上下文切换的机会为止.对于嵌入式系统,调度程序通常会永久重复此过程(即,直到断电).因此,RTOS启动功能永远不会返回.

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.

main()函数不是一项任务,它仅在RTOS启动之前运行.通常,main()应该在调用RTOS启动函数之前创建一个或多个任务.除非启动RTOS时出现错误,否则调用RTOS启动函数后main中的任何代码通常都不会执行.

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.

这篇关于内核启动后main()的线程上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆