How to avoid duplicate functions in generated code with embedded coder?
7 views (last 30 days)
The simulink model control_model has a certain library lib_i_boolean which is set to by a reusable function (subsystem properties -> treat as atomic unit, code generation function packaging -> reusable function). This library is used dozens of times in control_model.
Now, the embedded coder generates the following files:
We want to avoid these duplicate files, so only have
The internet provided a half answer, see: https://nl.mathworks.com/help/coder/ug/avoid-duplicate-functions-in-the-generated-code.html , which seems to be applicable for matlab code only?
We already did the following:
- Checked number of input or output variables --> always 6 inputs and 5 outputs, although some outputs are connected to terminators
- Checked type of input or output variables --> always the same datatype (5 boolean inputs, 1 single)
- Checked size of input or output variables --> always the same size (scalar, dimension 1)
- Checked values of input variables --> different constants are connected to the inputs
- Searched the model configuration for an "coder.ignoreConst" parameter
We're suspecting it has to do with using different constants as inputs and/or output terminators, so the compiler wants to optimize the function reuse. We want to tell the compiler to stop doing that, or change the simulink model such that the compiler stops doing this.
We're using embedded coder in R2016b, R2019b and R2020b.
Thanks for the help, much appreciated.
Jesús Zambrano on 4 Aug 2021
Apart from setting the function packaging to 'Reusable function', could you set the Function name option to 'User specified' and then set Function name as you prefer. Set this to all the exact copies of your subsystem in the model.
Hope it helps.