FreeRTOS API for running external file

naumanahmedkhan wrote on Thursday, July 21, 2011:

I have to design a API or use the API to execute a a file.c which contain functions and datatypes .I have to provide the platform for this file.c to execute as a Task of the FreeRTOS.

edwards3 wrote on Thursday, July 21, 2011:

Thanks for telling us. I hope your project goes well.

naumanahmedkhan wrote on Thursday, July 21, 2011:

unfortunately its not working well.i have not been able to make a interface for the file.c to execute.i need some help from you people. it is my first project on FreeRTOS  so i will be looking for your help.

sven-de wrote on Thursday, July 21, 2011:

Maybe you can clarify your aim. I’m certainly not the only one who doesn’t understand what you mean by API or interface, that can be everything. My current understanding is that you want to write a C-interpreter for a FreeRTOS-environment - which would be a VERY ambitious project for a beginner.

Maybe you can give an example of the expected behaviour or describe what you’ve tried so far. What is not working well?

richard_damon wrote on Friday, July 22, 2011:

As others have commented, you can’t load a “file.c” file into a machine (unless you are writing an interpreter, which is a major task). You also can’t easily compile that “file.c” and load that into a running program. The closest operations to what you are describing is either build a dynamically linked library and dynamically loading it at run time, or the building of a second independent program that is loaded into memory in free space, which then runs, and when done returns back to the “executive” program.

The first operation is probably what you are really asking for, but this sort of operation is in the domain of major operating systems (like Windows or Unix), not real time kernels like FreeRTOS. I suppose you could build this on your own built on FreeRTOS, but it is a major undertaking. It may be possible to do a limited version if you can live with some constraints:
1) You will only load a single extra program at a time (or able to divide them into 1 from column A and 1 from column B), and you reserve the space in your main program.

2) You can define a fixed and limited number of entry points into the loaded module that the main program will interact with (this might be just an init function, that will setup the desired tasks), and assign fixed locations to place jumps to these entry points (likely at the beginning of the reserved memory block)

3) You can define a fixed and limited number of routines/data members that the loaded program needs to be able to call from the main program.  This will probably include the set of FreeRTOS routines that the loaded program needs to be able to call, as well as some routines from the C library that you don’t want duplicated (like malloc and free). You need to get your system to build a jump table for these functions at a fixed location in memory, and create a stub library that the loaded program is linked with the points calls to those routines to that jump table.

This is doable, but is a significant project, and requires you to understand a lot of details about your implementation to make sure that you make the list in part 3 complete.

naumanahmedkhan wrote on Friday, July 22, 2011:

Thnx for your replies.
Here is the thing which i will like to do.Like when we have to create a task we simply include the task file and call the task create() function with the function to be executed as its parameter.Now i have a file.c and there are functions in it to execute .What i want to do is create an intermediate function or interpreter which will help to execute the funtions using the Task API provided by FreeRTOS.

I hope i have explained it well so that you all can understand it.

richard_damon wrote on Friday, July 22, 2011:

If your goal is to be able to, at program compile time, just add the file.c to your program and compile it in, we basically have that already, there isn’t much need for an intermediate function (unless there are other requirements not yet stated). I regularly have programs that to add features I add a new source file, and than add a call to an init function in main() to set up the task and any queues it needs.  Since standard C has no way to force actions before main starts, you are going to need to edit main, or at least some file with some sort of list of init functions (or tasks) to process.