Configure Packaging of Parameter Arguments in Generated Code - MATLAB & Simulink (original) (raw)

Main Content

When you create a reusable component as a referenced model, configure block parameters to use the same value for instances of the component or a different value for each instance.

To customize the implementation of parameter arguments in the generated code, you can configure the packaging of these parameters in the model where they are defined.

Configure the default mapping for model parameter arguments by using one of these storage classes:

Individually specify the storage class for model parameter arguments by using one of these storage classes:

If you use edit-time checking for code generation, you get an error for an invalid storage class.

For a parameter argument with a non-Auto storage class:

If you do not specify a default or individual storage class for a parameter argument, the code generator applies an internal storage class, InstP, to the parameter. The Instp storage class has these properties:

Code Generation Behavior

For single-instance referenced models, the parameter arguments reside in a standalone global structure. The top model defines the structure. The referenced model declares and uses the structure.

For multi-instance referenced models, the parameter arguments are part of a hierarchically nested structure that the top model declares and defines. The referenced model has access to its parameter values through a pointer in its self structure. The self structure points to a substructure of the structure that the top model defines.

For parameter arguments defined in the top model, if the argument does not have a storage class, it is inlined. If it has a storage class, the resulting code depends on the value of the Code interface packaging parameter:

To understand the behavior of instance-specific parameters in the generated code, consider this referenced model that defines two parameter arguments,gainArg and coeffArg.

Parameters tab of Code Mappings editor. The two Model Workspace Parameter Arguments, coeffArg and gainArg, are highlighted.

First consider the case where this model is configured to support only a single instance and the default mapping for model parameter arguments does not have a storage class. In theex_arg_code_ref.h file, there is a type definition and a declaration for the instance-specific parameters.

Snippet of the code generated from the model showing the definition of a structure that contains the two parameter arguments.

When the top model references this model and supplies values for the instance-specific parameters, the code for the top model defines the instance-specific parameters by using the values provided by the top model.

Snippet from the generated code showing the definition of the parameter arguments buffer with the initial values 1.98 and 3.98.

Now consider if the referenced model is configured to support multiple instances.ex_arg_code_ref.h contains the same type definition as the single-instance, but the self for the model also contains a pointer to an instance of that data structure. There is no pointer declaration to a standalone global variable of that structure.

The top model declares a parent structure, including an instance of this substructure, and initializes the pointer in the self structure for the referenced model.

Limitations

When you configure an instance-specific parameter for code generation, these limitations apply:

See Also

Topics