Use a C function in Simulink with the same parameter via legacy code tool

1 view (last 30 days)
Hello community,
I am working to develop some model by using a C function that completely develop in C environment. And then incorporate the same function in the Simulink model. We are trying to develop the model with Model Based Design concept.
Undermentionned is the description of the problem that occur when I try to build the model.
- First of all, I develop a simple function in the "Eclipse for C++ & C IDE". Then, I validate the function by using the deboger of the IDE. In the function, I have a specific parameter of the function. Here is the prototype of the C function :
my_addition_test (configuration conf, input in, output *out);
  • While configuration, input and output is the specific parameter of my C function. These parameters are the typedef struct that contaning some parameter defined in the header file of the function.
- Next, I create the Object in Matlab/Simulink for the parameter of the C fucntion by using "Manage Bus Objects in the Base Workspace" which is the same that I defined in the header file. And then after, I save the object under "my_function_parameter" with ".mat" extension.
- Then, I create a script to generate the SFunction of my C function with legacy code tool. The script run succesfully and generate the SFunction, mex and tlc file. I try the simulation in the Simulink model. It also run succesffully.
- Finnaly, When I try to build the model, I have some error (C2440 : cannot convert from 'configuration *' to 'configuration, 'input *' to 'input'). After trying to understand the error, I found the error occurs when the Sfunction calls the C function.
- I tried to resolve the problem my self and I found the parameter of the C function must be the pointer. when changing it to the pointer, it works properly. Here is the new prototype of the C function
my_addition_test (configuration *conf, input *in, output *out);
- Now my question is how can I incorporate the C function in the Simulink model without changing the parameter of the function. And the second question is, I want to share the Simulink model without source file (the header '.h' and the source file '.c'). After also trying to understand, I found it is possible to do is but you need to share the header file (.h) and an empty c file. Does some one know how to share the model without the two files header and the source code.
Thank you in advance.
Lamine BA
PS : I will after share the code and if I have time I will write a little draft for explaining all the step that I used for doing this.

Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!