Filter löschen
Filter löschen

Embedded Coder: Generate and integrate shared library for SIL-like approach?

5 Ansichten (letzte 30 Tage)
Hi,
we are using the Embedded Coder toolbox for code generation. The generated code will then be integrated into larger high-level systems. One of those larger system will be used for simulation and both code generation for the target.
We've been using ert.tlc to generate code. To use it in a larger system we also build a shared library from it and want to use it in different other situations, including the larger system I've mentioned before. I've tried to build a shared library for the host based on different methods. The straightforward approach seems to be, to use the ert_shrlib.tlc instead of ert.tlc.
Question 1: What really is the difference between ert.tlc and ert_shrlib.tlc? Does the later only include an additional call to the archiver? Or is it more?
For our environment, using the ert_shrlib.tlc creates a win64 .dll and .lib file.
In the next step I want to use the .dll and/or .lib file in another project, which works fine. Furthermore, I'd also like to use the shared library in larger systems. One of those larger systems shall include the shared library as a C MEX S-function. This can be done by using the Legacy Code Tool (LCT).
Question 2: Is it possible to automatically define the function specification based on code generation info from Embedded Coder?
I can get the function prototype names by loading the 'codeInfo.mat' file and using fields like codeInfo.OutputFunctions(1).Prototype(1).Name. It seems to be more difficult to get a list of parameters. Is there an easy way to transform from build information to LCT function specification? This would allow to fully automate the generation of the S-function.
The generated code includes the "rtwtypes.h" header file. However, when compiling with the MEX utility, it comes to errors due to redefinitions of data types by "simstruc.h". My current workaround is to replace
#include "rtwtypes.h"
by
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simstruc.h"
#else
#include "rtwtypes.h"
#endif
Question 3: Is this a tolerable workaround? Could this already be considered during code generation? (Note: the code will be used for both host and target.)
Question 4: How could I automate this? I think of a search-and-replace mechanism.
Kind regards,
Matthias
  2 Kommentare
Matthias Weber
Matthias Weber am 23 Jul. 2018
I've even found another approach called "CreateSILPILBlock". This will directly compile and build a MEX S-Function block (without creating a shared library, at least not visible to the end user). Advantage: no need to use the LCT to generate a shared library for the host - especially no need to define the function specification manually.
However, this will not allow me to generate calling code from a top model:
Error evaluating 'InitFcn' callback of S-Function block (mask) 'untitled/<modelname>'.
Callback string is 'rtw.pil.SILPILBlock.initFcnCallback(gcb);'
Caused by:
Code generation or simulation modes other than 'Normal' and 'Accelerator' (top-model only) are not supported when the model includes a SIL/PIL block ('untitled/UniversalBeatDetector'). Check that the model's simulation mode is 'Normal' or 'Accelerator' (top-model only).
As a workaround I tried to create a new model which uses the MEX function just as if it was any other "normal" MEX function by including it in an S-function block - and optionally including a custom TLC file for code generation.
Though, the MEX function seems to incorporate meta data about being built for a SIL/PIL block:
The PIL Block is not correctly configured. Please open the PIL Block, then build and download the PIL Application.
Question: Is there a way to use the generated MEX function for simulation and code generation?
ujwala pagar
ujwala pagar am 30 Nov. 2023
The PIL Block is not correctly configured. Please open the PIL Block, then build and download the PIL Application

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by