Simulink Library Code Generation

1 次查看(过去 30 天)
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

采纳的回答

Mark McBroom
Mark McBroom 2019-4-15
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 个评论
Davide Frey
Davide Frey 2019-4-24
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by