Simulink Library Code Generation

3 Ansichten (letzte 30 Tage)
Davide Frey
Davide Frey am 12 Apr. 2019
Kommentiert: Davide Frey am 24 Apr. 2019
Good morning,
I have various models in Simulink which refers to the same custom made library. When I generate the code for one of these models, the library blocks are generated in a separated file and the functions take the following name:
modelName_libraryBlockName(...)
As I need to generated the code separately for any of my models, I was wondering if it is possible to build a single file for all the library blocks, which uses as function names only the library block name, without including the name of the model itself. The goal would be to have two single .cpp and .h files for all the different models.
Best,
Davide

Akzeptierte Antwort

Mark McBroom
Mark McBroom am 15 Apr. 2019
Yes this is possible, but only if you ahve an Embedded Coder license. You must first configure the library blocks as follows:
Enable code reuse for the library block:
  1. In the library, right-click the MATLAB Function block my_conv_filter and select Block Parameters (Subsystem) from the context menu.
  2. In the Function Block Parameters dialog box, set these parameters:
  • Select the Treat as atomic unit check box.
  • In the Function packaging field, select Reusable function from the drop-down menu.
The, you must configure your model to place the generated code in a "shared" location that all models can access:
  • Select "Simulink" from Simulink menu
  • Select "Model Configuration Parameters"
  • Select the "Code Generation" tab on left hand side
  • Set System Target file to "ert.tlc"
  • Select "Interface" on left hand side
  • Set Shared Code Placement to "Shared Location"
Now, when you generate code, the .c and .h file will be in the directory /slprj/ert/_sharesutils
Thanks.
Mark.
  1 Kommentar
Davide Frey
Davide Frey am 24 Apr. 2019
Not exactly the complete solution to my problem. This allows me to generate the library functions in a separated code, though the naming of the functions is the problem. Indeed the functions take the name of the builded model plus the name of the subsystem (as I mentioned before), something like this:
modelNr1_functionName()
But in order to use this generated code also with other models (modelNr2, modelNr3, ...), I need to generate a function in a shared location with the following name:
functionName()
without any referencing to the original model.
Nevertheless given your inputs, I managed to solve my problem also by setting both "Function name options" and "File name options" to "User specified" (under Block Parameters > Code Generation). This allowed me to hard type the name of the functions.
Thank you very much for your help!
Davide

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Deployment, Integration, and Supported Hardware finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by