Main Content

Code Definition and Mapping Limitations and Considerations

Limitations

  • You cannot use code mappings to configure MATLAB® variables that are used as block parameters. Convert the variables to Simulink.Parameter objects in the model workspace. The resulting data objects appear in the Code Mappings editor as model parameters.

  • Use code mappings to configure only one discrete state per block in a model.

  • You cannot individually access or configure states in blocks linked to built-in Simulink® libraries when using the Code Mappings editor (or the equivalent programmatic interface). The code generator generates code from such states according to the Signals, states, and internal data category in the Data Defaults section of the model mappings.

  • If a model contains a tunable, nonfinite parameter, for example, with a value of inf, the code generator does not apply a specified default parameter mapping. The parameter appears as a field in the default parameter data structure rtP (see Real-Time Model Data Structure).:

Default Code Mapping Constraints

Default code mappings for categories External parameters and Global data stores must be the same for models throughout the model reference hierarchy.

Model Editing Operations and Individual Data Element Code Mappings

While editing a model in the context of a coder app, you should be aware of the relationship between Simulink model editing tools, such as copy and undo, and code mappings. In the context of a coder app, when you perform copy-and-paste or cut-and-paste editing operations within a model, the coder app preserves the code mappings for individual data elements. For example, within a model, if you copy and paste the source block of a signal that is configured with a specific storage class, the pasted version of the signal port retains the same storage class.

While you can use undo and redo operations for editing actions on model data elements, they are unavailable while configuring code mappings. For example, if you delete a state block, and then click Undo, the block reappears in the model canvas and the code configuration for the state reappears in the code mappings. In the Code Mappings editor, if you change the storage class setting for a state from Auto to Model default, and then click Undo, the storage class does not revert to Auto. In this case, the change pertains to the code mapping, not to the model data element.

Storage Classes and Reentrant, Multi-Instance Models and Components

The code that you generate from a model or component (referenced model or subsystem) is multi-instance code if it allows your application to maintain multiple independent instances of the component during execution. For example, you can generate reentrant, multi-instance code from an entire model by setting the model configuration parameter Code interface packaging to Reusable function. For general information about multi-instance models and components, see Model Composition and Reuse.

Under some circumstances, applying storage classes can:

  • Prevent you from generating multi-instance code.

  • Cause some data elements to appear in the generated code as singletons, which means that each instance of the model or component directly accesses the same shared, global data, creating dependencies between the instances.

To avoid errors and unexpected generation of single-instance code and singleton data, observe the guidelines and limitations below.

Directly Applied Storage Classes

When you apply a storage class directly to a data element (see C Data Code Interface Configuration for Model Interface Elements):

  • To generate multi-instance code, you must apply the storage class only to parameter objects, global data stores, shared local data stores, and root-level I/O.

  • The storage class yields only singleton data.

Storage Classes Applied by Default

When you apply a default storage class (see C Data Code Interface Configuration for Model Interface Elements):

  • For these data categories, you can generate only singleton data:

    • Model parameters

    • External parameters

    • Global data stores

    • Shared local data stores

  • For Internal data, you can generate only instance-specific data, which means each instance of the model or component operates on a separate copy of the data. For this category, you must use the example storage class SignalStruct, which appears after preparing a model for code generation with the Quick Start tool. Alternatively, you can create and use your own structured storage class by using an Embedded Coder® Dictionary.

For more information, see What Is Reentrant Code? and Choose Storage Class for Controlling Data Representation in Generated Code.

Copy Code Mappings When Converting Subsystems to Referenced Models

You can copy code mappings when you convert a subsystem to a referenced model.

See Also

|

Related Topics