In a team or large organization, to enable multiple users to generate code that conforms to a standard architecture, you can create and share code generation definitions, such as storage classes, with those users. When configuring code generation settings for different models, the users can apply the definitions to data and function elements in the models, generating standardized code.
To control the appearance of model elements in the generated code, you apply code definitions to the elements by using the Code Mappings editor. Configure the default code generation behavior for a category of model elements by selecting a code definition in the default mapping for the category. Configure individual data elements by mapping them to code definitions in the Code Mappings editor.
To create code definitions that you and other users can use in the Code Mappings editor, use an Embedded Coder Dictionary.
When you create definitions in an Embedded Coder Dictionary, decide where to store the definitions by considering how you intend to use them. This table lists where to store the code definitions and how to use Simulink® data dictionaries.
|Usage of Definitions||Location for Code Definitions||Data Dictionary Use|
|Multiple models — sharing a set of code definitions to standardize code||Simulink data dictionary that is referenced by all of the models, either directly or through intermediate referenced dictionaries||Link each model to a data dictionary that defines the code definitions, either directly or through an intermediate dictionary reference.|
|One model — prototyping generated code by using one model||Local Embedded Coder Dictionary of the model||You can optionally link the model to a data dictionary that contains other data. If you link the model to a dictionary that contains other code definitions, the model can also use those code definitions.|
To use an Embedded Coder Dictionary and for its limitations with respect to code generation definitions, see Embedded Coder Dictionary.
To create definitions for data objects that you store in the base workspace or in a Simulink data dictionary, use the Custom Storage Class designer to create a definition in a package. For these data objects, you apply code generation settings to the data object instead of applying them in the mapping of a model. When an item in a model uses the data object and its code generation settings, the code mapping for the item reflects the specification of the data object. For more information, see Create Storage Classes by Using the Custom Storage Class Designer and Control Data and Function Placement in Memory by Inserting Pragmas.
If you want to use the same code generation definition in the Code Mappings editor and in data objects, you do not need to store one copy of the definition in an Embedded Coder Dictionary and another copy in a package. Instead, store the definition in a package (by using the Custom Storage Class Designer). Then, configure one or more Embedded Coder Dictionaries to refer to the definition in the package. With this technique, when you want to make changes to the definition, you make the changes in only one place, the package.
To create a code generation definition in a package by using the Custom Storage Class Designer, see Create Storage Classes by Using the Custom Storage Class Designer. Then, to configure an Embedded Coder Dictionary to refer to the package, see Refer to Code Generation Definitions in a Package.
For more information about maintaining definitions in packages and dictionaries, see Migrate Package Definitions to Embedded Coder Dictionary to Use in Code Mappings.
When defining a
storage class in the Embedded Coder Dictionary, you can specify whether users can
map the storage class to parameters, signals, or parameters and signals. To
constrain the use of a storage class, the Data Initialization
property must be set to
None. Then, in the Property
Inspector, under Allowed Usage, select
Parameters, Signals, or
Parameters and Signals. For more
information, see Embedded Coder
In a large organization with multiple models and users, you can share code generation definitions by storing them in a mutually accessible location. The process of sharing code definitions is called deployment. For more information, see Deploy Code Generation Definitions.
You can create and interact with code definitions by using the Embedded Coder Dictionary API.
Represent the Embedded Coder Dictionary by using a
coder.Dictionary object. Use the object to access
the sections of the dictionary: Storage Classes, Memory Sections, and
Function Customization Templates. If you have a package of code
definitions, use the
coder.Dictionary object to load
and refresh the package in the dictionary.
Represent a section of the dictionary by using a
coder.dictionary.Section object. Use the section
to access code definitions.
Represent a code definition by using a
coder.dictionary.Entry object. Use the entry to
interact with the code definition and its properties.
You can also use functions such as
coder.dictionary.move to perform operations on Embedded Coder
Dictionaries. For more information, see Create Code Definitions Programmatically.