Running applications from freeRTOS
Asked Answered
P

2

6

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. However, I have run into an issue concerning running 3rd-party applications from within 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). 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.

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. 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...

So the question is, how do I get freeRTOS to run applications from 3rd party developers that aren't already baked into the OS?

Plucky answered 20/2, 2014 at 21:21 Comment(2)
How is this related to Lua?Weekly
I should have fully explained that. Lua is one of the scripting languages I am looking at to address this problem. Thank you for bringing my lack of explanation to my attention.Plucky
P
0

Due to request, here is the work around I found to my problem. The issue was launching other applications from freeRTOS. This was accomplished by utilizing the "System()" function in the newlib library. Thus, I can place an application in flash until it's needed, then launch it using the newlib functions provided. 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.

Plucky answered 1/3, 2014 at 17:47 Comment(3)
There is something missing in this solution - I cannot see how it can work on a stand-alone FreeRTOS based system. According to the (documentation)[sourceware.org/newlib/] it passes the string to the OS command shell if available, and FreeRTOS does not have a shell. The syscalls that system() calls are empty stubs by default so system() does nothing unless the functionality has been explicitly implemented.Interjection
I now see the issue you are presenting.. However I am at a lose for the proper solution in this case. I know it is possible (Another product, the pebble smartwatch, openly uses freeRTOS and has an app-like interface.) However it seems unclear to me how to pull this off. In reality, I just need to run concurrent programs on my processor, which can be executed by one another.Plucky
The Pebble may well use FreeRTOS as the basis for an OS, but that on its own is not the enabling technology for loadable apps - the developers will have developed that on top of FreeRTOS as a middleware layer. You have to realise that Pebble raised over $10M in crowd funding for the project - with that they could put a lot of effort into the OS beyond simply porting FreeRTOS. Pebble apps are generated using Pebble's own compilation tools, This site suggests to me that Pebble Apps use a proprietary relocatable object format.Interjection
I
12

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. In most case you use an RTOS because you require hard real-time response and the execution of third-party code could compromise that.

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.

Again many RTOSes (like FreeRTOS) are not operating systems in the same sense as a GPOS such as Linux. Typically the RTOS services available are the real-time scheduler, inter-process communication (IPC), thread-synchronisation, and timers. 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. 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. 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. Even with an MMU a simple RTOS kernel such as FreeRTOS won't use it.

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. 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. 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. The shell is one thing, but dynamic loading and linking requires the application symbol table to be target resident.

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.

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. 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.

Interjection answered 20/2, 2014 at 23:5 Comment(5)
I am currently developing this on an ARM Cortex M4, so there is no MMU. We had to choose this processor due to the device needing to be as energy efficient as possible, while still remaining responsive. Thank you for the links to OS alternatives, I'll look into those now.Plucky
We are looking for open source or free for commercial use options. Excluding those from your list, that leaves me with the linux options which also don't appear to be an option, due to a lack of RAM.. I'm looking into it more, but it seems that I am stuck with an OS like freeRTOS to accomplish our needs.Plucky
I'll give you the answer, however I found an alternative solution, using newlib. Thanks for the help!Plucky
@DevenJ: It is entirely legitimate to post an answer to your own question - you should perhaps do that because I am intrigued, Newlib is merely a portable implementation of the standard library so I am unclear how it has helped you solve this problem.Interjection
Hey Deven can you suggest an answer for my problem #21931809Seka
P
0

Due to request, here is the work around I found to my problem. The issue was launching other applications from freeRTOS. This was accomplished by utilizing the "System()" function in the newlib library. Thus, I can place an application in flash until it's needed, then launch it using the newlib functions provided. 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.

Plucky answered 1/3, 2014 at 17:47 Comment(3)
There is something missing in this solution - I cannot see how it can work on a stand-alone FreeRTOS based system. According to the (documentation)[sourceware.org/newlib/] it passes the string to the OS command shell if available, and FreeRTOS does not have a shell. The syscalls that system() calls are empty stubs by default so system() does nothing unless the functionality has been explicitly implemented.Interjection
I now see the issue you are presenting.. However I am at a lose for the proper solution in this case. I know it is possible (Another product, the pebble smartwatch, openly uses freeRTOS and has an app-like interface.) However it seems unclear to me how to pull this off. In reality, I just need to run concurrent programs on my processor, which can be executed by one another.Plucky
The Pebble may well use FreeRTOS as the basis for an OS, but that on its own is not the enabling technology for loadable apps - the developers will have developed that on top of FreeRTOS as a middleware layer. You have to realise that Pebble raised over $10M in crowd funding for the project - with that they could put a lot of effort into the OS beyond simply porting FreeRTOS. Pebble apps are generated using Pebble's own compilation tools, This site suggests to me that Pebble Apps use a proprietary relocatable object format.Interjection

© 2022 - 2024 — McMap. All rights reserved.