Environment for Configuring Model Data and Functions for Code Generation

When you generate code from a model, the code includes:

  • Entry-point functions such as model_step, which your application code calls to execute the model algorithm.

  • Data such as signals, states, and parameters, which your application code can read from and write to.

To control the names and representation of the data and functions in the code, follow the iterative paradigm shown in this diagram.

In this paradigm:

  • A software engineer directly interacts with and generates code from production models.

  • A system architect helps multiple engineers and multiple projects generate code that conforms to the standards of a department or organization. The architect achieves this standardization by customizing the Simulink® development environment that engineers use.

Software Engineer: Configure Default Settings

For each category of data and functions in a model, such as root-level input, parameters, and execution functions, you can specify default code generation settings. For example, you can configure the generated code to conform to these objectives by default:

  • Read root-level input data from global variables defined by external code.

  • Store state data in structures whose placement in memory you can control.

  • Name functions according to a rule that you specify.

The default settings can help you to reduce manual data entry.

  • As you add blocks and signals to a model, the new data elements and functions inherit the default settings.

  • To change code generation settings for many data elements or functions at once, you make the changes in one place—the default settings.

  • You can use naming rules to avoid additional effort as you make changes elsewhere in the model.

For some categories of data, code generation optimizations can eliminate the data from the code. For your default settings to apply, you must identify individual data elements that you want to preserve against the optimizations. For more information, see Elimination of Parameters and Other Internal Data by Optimizations.

To configure default settings, use the Code Mappings editor.

Software Engineer: Override Default Settings

After using the Code Mappings editor to configure model-wide default settings, you can override the defaults for individual data elements and functions.

Override DefaultsAction
DataUse the Model Data Editor Code view. Apply a setting in the Storage Class column. See Configure Data Properties by Using the Model Data Editor (Simulink).
Entry-point functionsIn the Code Mappings editor, use the Functions tab. For an individual function, you can override the function customization template, function name, and memory section. For the base rate step (execution) function of a rate-based model and the step functions generated from Simulink Function blocks, you can override the default interface (name and arguments) through the Configure C Step Function Interface dialog box. See Customize Generated C Function Interfaces and Customize Entry-Point Function Interfaces for Simulink Function and Function Caller Blocks.

System Architect: Create Code Generation Definitions

Using the Code Mappings editor and the Model Data Editor, application developers apply code generation definitions, such as the built-in storage class ExportedGlobal, to model data elements and functions. To standardize the code that you and your users generate from multiple models, you can create and share custom definitions that have meaningful names. Creating custom definitions also enables you to achieve code generation objectives that built-in definitions cannot satisfy.

  • To create definitions that you want to appear in the Code Mappings editor, use the Embedded Coder Dictionary. See Embedded Coder Dictionary.

    If you plan to use your Embedded Coder Dictionary definitions in one model, you can store the definitions in the model file. Alternatively, to share the definitions between models and projects, store the definitions in a Simulink data dictionary. With a data dictionary, to modify a shared definition, you change a definition in one place—the dictionary.

  • To create definitions that you want to appear in other tools, such as the Model Data Editor, use the Custom Storage Class Designer. See Create Storage Classes by Using the Custom Storage Class Designer.

    For some definitions that you create by using the Custom Storage Class Designer, you can make the definitions appear in the Code Mappings editor by configuring an Embedded Coder Dictionary to refer to them.

See Also

| |

Related Topics