简体   繁体   English

从freeRTOS运行应用程序

[英]Running applications from freeRTOS

I am currently in the process of developing the OS for a consumer electronics product my company is developing. 我目前正在开发我公司正在开发的消费电子产品的操作系统。 I have settled on freeRTOS as the backbone for our OS, and am working diligently to implement hardware functionality within the OS. 我已经决定将freeRTOS作为我们操作系统的主干,并且正努力在操作系统中实现硬件功能。 However, I have run into an issue concerning running 3rd-party applications from within freeRTOS. 但是,我遇到了一个关于在freeRTOS中运行第三方应用程序的问题。

Originally I considered a task to be an application, where basically you had "myapplication.c" and "myapplication.h" containing all your applications necessary functions and the code would reside within the for(;;) loop within the task (acting as a main while loop). 最初我认为任务是一个应用程序,基本上你有“myapplication.c”和“myapplication.h”包含所有应用程序必需的函数,代码将驻留在任务中的for(;;)循环中(作为一个主要的while循环)。 Then when the user decides to run that application, a function pointer is passed to a queue, that my app_launcher task then uses to create the new task using the 3rd-party task or application. 然后,当用户决定运行该应用程序时,会将一个函数指针传递给队列,然后我的app_launcher任务会使用第三方任务或应用程序创建新任务。

The problem with this approach however, is the OS will already be compiled and reside on the microcontroller, and applications with be installed and deleted as the user sees fit... So obviously applications need to be compiled and executable from the OS. 然而,这种方法的问题是操作系统已经被编译并驻留在微控制器上,并且可以根据用户的需要安装和删除应用程序......显然,应用程序需要从操作系统进行编译和执行。 On a standard unix machine, I would use something like fork, to select the executable and give it it's own process. 在标准的unix机器上,我会使用fork之类的东西来选择可执行文件并给它自己的进程。 However I cannot find a similar functionality within freeRTOS.. My other idea is approaching a scripting language for app development, but again I'm not sure on how to launch those applications... 但是我在freeRTOS中找不到类似的功能..我的另一个想法是接近应用程序开发的脚本语言,但我不知道如何启动这些应用程序......

So the question is, how do I get freeRTOS to run applications from 3rd party developers that aren't already baked into the OS? 所以问题是,我如何让freeRTOS运行尚未加入操作系统的第三方开发人员的应用程序?

FreeRTOS (and most RTOSes for that matter) do not work like general purpose operating systems (GPOS), they are not generally designed to dynamically load and execute arbitrary user supplied applications. FreeRTOS(以及大多数RTOS)不像通用操作系统(GPOS)那样工作,它们通常不是为了动态加载和执行任意用户提供的应用程序而设计的。 In most case you use an RTOS because you require hard real-time response and the execution of third-party code could compromise that. 在大多数情况下,您使用RTOS是因为您需要硬实时响应,并且执行第三方代码可能会对此造成影响。

Most RTOSes (FreeRTOS included) are no more that static-link libraries, where your entire embedded application is statically linked with the RTOS and executes as a single multi-threaded program. 大多数RTOS(包括FreeRTOS)不再是静态链接库,其中整个嵌入式应用程序与RTOS静态链接并作为单个多线程程序执行。

Again many RTOSes (like FreeRTOS) are not operating systems in the same sense as a GPOS such as Linux. 同样,许多RTOS(如FreeRTOS)的操作系统与Linux等GPOS的操作系统不同。 Typically the RTOS services available are the real-time scheduler, inter-process communication (IPC), thread-synchronisation, and timers. 通常,可用的RTOS服务是实时调度程序,进程间通信(IPC),线程同步和定时器。 Middle-ware such as a file system, and network stack for example are either optional extensions or must be integrated from third-party code. 例如文件系统和网络堆栈等中间件可以是可选扩展,也可以从第三方代码集成。

One problem you will have with FreeRTOS trying to achieve your aim is that a "task" is analogous to a "thread" rather than a "process" in the sense of a GPOS process model. FreeRTOS试图实现目标的一个问题是,“任务”类似于“线程”,而不是GPOS过程模型意义上的“过程”。 A task typically operates in the same memory space as other tasks with no memory protection between tasks. 任务通常在与其他任务相同的内存空间中运行,在任务之间没有内存保护。 Tasks are not separate programs, but threads within a single application. 任务不是单独的程序,而是单个应用程序中的线程。

If your target has no MMU then memory protection may be limited in any case, but you may still want third-party applications to be conceptually independent from the OS. 如果您的目标没有MMU,那么内存保护在任何情况下都可能受到限制,但您可能仍希望第三方应用程序在概念上独立于操作系统。 If your processor does not have an MMU, then running arbitrary third-party dynamically loaded code may be a problem for system integrity, safety and security. 如果您的处理器没有MMU,则运行任意第三方动态加载的代码可能是系统完整性,安全性和安全性的问题。 Even with an MMU a simple RTOS kernel such as FreeRTOS won't use it. 即使使用MMU,FreeRTOS等简单的RTOS内核也不会使用它。

Operating systems with real-time scheduling that can load and run application code dynamically as separate processes include: 具有实时调度的操作系统可以作为单独的进程动态加载和运行应用程序代码,包括:

Also VxWorks has the ability to load partially linked object code and dynamically link it to the already loaded code. 此外, VxWorks还能够加载部分链接的目标代码,并将其动态链接到已加载的代码。 This is not the same at a process model, but is more akin to a dynamic-link library. 这在流程模型中并不相同,但更类似于动态链接库。 What makes it worth mentioning in this context is that the VxWorks shell can invoke any function with external linkage by name. 在此上下文中值得一提的是,VxWorks shell可以通过名称调用具有外部链接的任何函数。 So you can load an object file implementing a function and then run that function. 因此,您可以加载实现函数的目标文件,然后运行该函数。 You could in principle implement the same functionality on FreeRTOS, but it is non trivial. 原则上你可以在FreeRTOS上实现相同的功能,但这并非易事。 The shell is one thing, but dynamic loading and linking requires the application symbol table to be target resident. shell是一回事,但动态加载和链接需要应用程序符号表作为目标驻留。

If you don't need hard real-time (or your real-time requirements are "soft") and your target has sufficient resources, you may be better served deploying Linux or uClinux which are increasingly used in embedded systems. 如果您不需要硬实时(或者您的实时要求是“软”)并且您的目标具有足够的资源,那么部署LinuxuClinux可能会更好地为嵌入式系统中使用的LinuxuClinux提供服务。

If the code your end-users need to run are tightly related to the purpose of your device rather than "general purpose" in nature then another possibility for allowing end-users to run code is to integrate a scripting language interpreter such as Lua . 如果最终用户需要运行的代码与设备的目的紧密相关而不是“通用”本质,则允许最终用户运行代码的另一种可能性是集成脚本语言解释器,例如Lua In this case you would simply load the script from a file system and pass it to the script interpreter. 在这种情况下,您只需从文件系统加载脚本并将其传递给脚本解释器。 For more general purpose requirements a Java VM may be a possibility. 对于更通用的要求, Java VM可能是可能的。

Due to request, here is the work around I found to my problem. 根据要求,这是我找到问题的工作。 The issue was launching other applications from freeRTOS. 问题是从freeRTOS启动其他应用程序。 This was accomplished by utilizing the "System()" function in the newlib library. 这是通过利用newlib库中的“System()”函数完成的。 Thus, I can place an application in flash until it's needed, then launch it using the newlib functions provided. 因此,我可以将应用程序放在flash中直到需要,然后使用提供的newlib函数启动它。 This also allows me to launch programs dynamically, without hard coding the code or name of the application, I just need to provide System() with a string, pointing to the app's location in memory. 这也允许我动态启动程序,而无需硬编码应用程序的代码或名称,我只需要为System()提供一个字符串,指向应用程序在内存中的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM