Subsystem Parameters Always Mapped to Global Variables in Code Generated by Matlab/Simulink Embedded Coder

812 views Asked by At

For a simple test setup, we want to generate C code from a Simulink subsystem, which has several configuration parameters defined in its block mask. The environment shall be able to modify these parameters and the input signals, and to evaluate the output signals for several instances of the subsystem's code representation.

Expected Outcome

The code generation is expected to provide structure declarations for model, parameters, inputs, and outputs in the generated code, which can be instantiated and initialized (parameters, inputs) by the environment, and passed to the generated functions as pointers. Functions should only depend on these passed arguments.

However, even after several hours of investigation, the generator still puts the configuration parameters into one global variable, which is directly accessed by the generated functions, what makes instance-specific configuration impossible.

Attempts

Only the following Model Settings turned out as useful on the newest release R2022a:

  • Optimization.Default parameter behavior = Tunable
  • Code Generation:
    • Code Interface.Code Interface Packaging = Reusable function
    • Pass root level I/O as = Structure reference

Result

After generating code for subsystem X, declarations for all structures are available; model M, inputs U and outputs Y are passed by reference to the functions, for example:

void X_step (RT_MODEL_X_T *const X_M, ExtU_X_T *X_U, ExtY_X_T *X_Y) {
  ... 
  ... X_P.X_someParam ...
  }

However, the parameter structure is still accessed as a global variable X_P. Instead, the parameter structure should be also passed as a pointer either explicitly or as part of the model structure, so that it can be used as X_P->someParam.

Is there any way to achieve this behavior?

History

Years ago, in Release 2013b, this already worked smoothly: The model structure contained a substructure called ModelData which in turn contained the field P_X_T defaultParam. These parameters were passed to the functions as part of the model structure and thus could be made instance-specific. This worked out of the box with a few standard settings (no storage classes or other sophisticated configurations). Is this feature removed or just hidden?

0

There are 0 answers