1
votes

I use m file which initialize parameters in MATLAB workspace.

It is example of file:

Pconstant=Simulink.Parameter;
Pconstant.Value=3;
Pconstant.CoderInfo.StorageClass = 'exportedGlobal';

Pgain=Simulink.Parameter;
Pgain.Value=10;
Pgain.CoderInfo.StorageClass = 'exportedGlobal';

These parameters are used as value in 'Gain' and 'Constant' blocks. I generate c source code for this model and received following structure in model_data.c file:

/* Block parameters (auto storage) */
P_ParameterTest_T ParameterTest_P = {
  10.0,                                /* Expression: Pgain
                                        * Referenced by: '<Root>/Gain'
                                        */
  3.0,                                 /* Expression: Pconstant
                                        * Referenced by: '<Root>/Constant'
                                        */
};

Model.h file contains following code:

/* Parameters (auto storage) */
struct P_ParameterTest_T_ {
  real_T Gain_Gain;                    /* Expression: Pgain
                                        * Referenced by: '<Root>/Gain'
                                        */
  real_T Constant_Value;               /* Expression: Pconstant
                                        * Referenced by: '<Root>/Constant'
                                        */
};

Model source code compiling into model.a lib file which is used in other programs. I can change value of constant in external c code:

parameters = (BLOCK_PARAMETERS*)rtmGetDefaultParam(model);
parameters->Constant_Value = 1;

But this solution is not good for me. Because I do not know where are used these parameters and I do not know fields names of structure.

Can I write code which will be set value in all fields of structure where are used Pconstant parameter? Something like this:

Pconstant = 1; //instead of parameters->Constant_Value = 1;

Thanks for help.

1

1 Answers

1
votes

You say you have defined the storage class as ExportedGlobal but in the generated code, it appears as "auto storage", so something's not quite right there.

To achieve what you want, I think you need to turn "Inline parameters" on in the optimization pane (see documentation), and then click on the "Configure..." button to define which parameters you do not want inlined, i.e. Pconstant and Pgain (see the bit in the doc about inlining parameters). The structure construction you have in your code is normally used when "inline parameters" is turned off.

I'm guessing you have Simulink Coder, so you should also have a look in the Simulink Coder doc about how it generates code for parameters in different conditions. From memory, it's generally pretty thorough.