Simulink embedded coder: How to generate C code from model and use already generated code of subsystems inside?
1 次查看(过去 30 天)
显示 更早的评论
Lets say that I want to generate C code from a simulink model called A, then include the model A in another model called ABC as a subsystem (or linked library) and then generate code again from model ABC while ensuring that the generated C code of ABC just calls the already generated code from A. Is it even possible?
One of sufficient outcomes would be to ensure that the generated C files from ABC would contain some files that are exactly the same as all the C files generated from model A.
In general, generated .c files from ABC should look someting like this:
A.c:
#defines...
#include "A.h"
#include "A_private.h"
...input/output structure definitions
void A_step(void){
...math of the simulink blocks inside subsystem A. Names of the inputs and outputs corresponds to those in subsystem A.
}
ABC.c:
#defines...
#include "A.h"
#include "ABC.h"
#include "ABC_private.h"
...input/output structure definitions
void ABC_step(void){
A_step();
...some other calls or math. Names of the inputs and outputs corresponds to those in model ABC.
}
So far after many settings tweaks I managed to get to something like this:
A.c:
#defines...
#include "A.h"
/* Include model header file for global data */
#include "ABC.h"
#include "ABC_private.h"
...input/output structure definitions
void ABC_A(void){
...math of the simulink blocks inside subsystem A. Names of the inputs and outputs corresponds to those in model ABC.
}
ABC.c:
#defines...
#include "ABC.h"
#include "ABC_private.h"
...input/output structure definitions
void ABC_step(void){
ABC_A();
...some other calls or math. Names of the inputs and outputs corresponds to those in model ABC.
}
As you can see, in my case, its kind of other way around. The child (subsystem A) includes ABC. I need it to by like in the first example.
Also, the 'step function' of model A in my case is not the same as the desired one. It uses input/output structure from ABC model. I need it to use its own input/ouput structure (as if it was generated just from model A).
Things I have done:
- Set the subsystem and model to be treated as atomic unit
- Tried all the function packaging settings (nonreusable, reusable, etc.)
- Function with separate data on/off
- Function interface: void_void
- System target: ert.tlc
- Tried all sorts of things in Code Generation->Interface section in simulink settings
I know it should be possible somehow, because I have seen a generated source files like this. I dont really understands how the TLC templates work, so maybe that is the way to go? Any answer or suggestion will be much appreciated.
1 个评论
Vit Valek
2019-7-30
编辑:Vit Valek
2019-7-30
Hi,
If I understand your issue, one of the approach may be to create S-function by using Legacy code tool.
You will generate code from A (A.h, A.c, ...). After that, you create S-function from files you generated from A. Now you have S-function and TLC file. This files you can use for simulate or generate code. I know it's not exemplary method, but I think it's working.
Vit
回答(1 个)
Lars Rosqvist
2019-10-30
It is not clear to me if you have tried to include model A, model B and model C as referenced models in model ABC.
This is the official way of making sure that model ABC includes function calls to the generated step and initialize functions from model A, B and C.
Thanks,
Lars
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!