MATLAB: Simulink Library Code Generation

code generatedcustom libraryEmbedded Coderlibrarysharedsimulink

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

Best Answer

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.
Related Question