Handling pooled constants in C code generated by Embedded Coder?

26 views (last 30 days)
Hi,
can you please guide me to the part of the documentation relevant to pooling of constants in the code generated by Embedded Coder? I could not find anyhting neither in the Getting started guide, nor in the reference.
We may be facing issues when generating code for two separate models and integrating them into a common framework.
Is there a rule in the naming for the pooled constants/ constant parameters (in const_params.c)? How can this pooling be switched off? Can collissions occur?
Kind regards,
Matthias

Answers (2)

goerk
goerk on 4 Jul 2018
I had a similar problem and found a solution in the "Simulink Coder User's Guide"
Excerpt from the "Simulik Coder User's Guide":
Suppress Shared Constants in the Generated Code
You can choose whether or not the code generator produces shared constants and shared functions. You may want to be able to keep the code and data separate between subsystems, or you may find that sharing constants results in a memory shortage during code generation.
You can change this parameter programmatically using the parameter GenerateSharedConstants with set_param and get_param
>> set_param('rtwdemo_throttlecntrl','GenerateSharedConstants','off')
  2 Comments
ThomasZ
ThomasZ on 6 Mar 2020
Hello,
this command can not be used, when using a configuration set (conf data in .mat).
Strange thing is, I can not find an equivalent setting in the configuration parameters.
Is the setting named differently there?
goerk
goerk on 6 Mar 2020
In the .mat file there has to be a variable of type 'Simulink.ConfigSet'.
Lets asume this variable has the name 'cs';
You have to load the .mat file and change the parameter.
load('config.mat')
set_param(cs,'GenerateSharedConstants','off')

Sign in to comment.


Soren
Soren on 4 Jul 2018
Edited: Soren on 4 Jul 2018
Hi.
I have had the same problem. Code generating two independent models and include them into legacy code. The generated code compiled individualy fine, but when linked together the same error came.
It is proberbly because you have enabled inline optimazationa and are using a lookup table.
A solution is to post-process the generated code and give the const in const_params.c, that gives the linker error new names, because I do not think the name can be set anywhere in the configuration.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!