Main Content

Manage an Embedded Coder Dictionary

After you create code definitions for standardization and software architecture conformance and deploy them to your users, keep the definitions and their usage up to date. When you and other users create models for code generation, make your code definitions available to the models. If the standards for your generated code change, you might need to update your code definitions. Consider how these standards changes impact models that use your code definitions and update the models accordingly.

Share Available Code Definitions with New Models

If you share code definitions in a Simulink® data dictionary, make the definitions available to new models that you or your users create for code generation. A model that you create from the Simulink Start Page or by using the new_system function is not linked to a Simulink data dictionary. The new model cannot access code generation definitions that you store in a data dictionary.

To make code definitions available to a new model automatically, write callbacks and other code that immediately links the model to a data dictionary that contains the definitions.

  • For a simple example that shows how to link a model to a data dictionary programmatically and for information about configuring dictionary referencing programmatically, see Store Data in Dictionary Programmatically.

  • If you use a project, consider creating a project shortcut that creates a model and immediately links the new model to a data dictionary. For information about projects and project shortcuts, see What Are Projects?.

To manually share the definitions with a new model, see Share Embedded Coder Dictionary Definition Between Models.

Migrate Package Definitions to Embedded Coder Dictionary to Use in Code Mappings

If you create a storage class in a package and you want to use it in the Code Mappings editor, refer to the package from one or more Embedded Coder Dictionaries. To refer to a package from an Embedded Coder Dictionary, see Refer to Code Generation Definitions in a Package. Then, for models that have access to the Embedded Coder Dictionary, you can apply storage classes from the package by using the Code Mappings editor.

When you want to make changes to the definition, make changes only in the package. To apply the changes to the Embedded Coder Dictionaries, refresh the package. To refresh the package, open each Embedded Coder Dictionary.

To apply a storage class to a model data element that is not resolved to an external data object, use the Code Mappings editor. To make the package definitions appear in the Code Mappings editor, refer to the package from the Embedded Coder Dictionary that the model uses.

These unresolved model elements include:

  • Inport blocks

  • Outport blocks

  • Signal lines

  • Block states

  • Data stores

  • Parameter objects in the model workspace

To map these model elements to a package-based definition, refer to the package from the Embedded Coder Dictionary that the model uses.

Beginning in R2020b, if an existing model includes these model elements and they are configured with package-based definitions, Simulink references the package from the Embedded Coder Dictionary. If the model is linked to a Simulink data dictionary, Simulink uses the Embedded Coder Dictionary in the data dictionary to reference the package.

Change Code Generation Definitions

If the requirements for your generated code change, you might need to update your code definitions to reflect the latest interface standards. Changing or deleting a code definition can affect models that use the code definition. When you make changes to code definitions, assess the impact of the changes. Then, deploy the changes and fix the affected usage points.

To make changes to definitions in a package, use the Custom Storage Class designer. For more information, see Create Storage Classes by Using the Custom Storage Class Designer.

To make changes to definitions in an Embedded Coder Dictionary:

If you store the Embedded Coder Dictionary in a Simulink data dictionary, save the data dictionary after you update the code definitions.

Assess the Impact of Code Definition Changes

Depending on the storage location of the code definition, changing or deleting the definition can break usage points. This table shows the impact of different changes based on the location of the definition. Check if usage points are affected by the change and fix them by making the corresponding updates.

Definition ChangesStorage LocationUpdates
Change the name of a definitionPackageFor a memory section, update other definitions in the package that use the memory section. In the Custom Storage Class designer, specify the new memory section name.
For a storage class, update data objects that use the storage class. Specify the new storage class name for the data object.
In Embedded Coder Dictionaries that reference the package, refresh the package.
In models that use the definition in the Code Mappings, specify the new definition name. Use either the Code Mappings editor or a script that uses the coder.mapping.api.CodeMapping object.
Embedded Coder DictionaryNone
Change properties of a definitionPackageIn Embedded Coder Dictionaries that reference the package, refresh the package.
Embedded Coder DictionaryNone
Delete a definitionPackageFor a memory section, update other definitions in the package that use the memory section. In the Custom Storage Class designer, specify a different memory section or no memory section.
For a storage class, update data objects that use the storage class. Specify a different storage class or no storage class for the data object.
In Embedded Coder Dictionaries that reference the package, refresh the package.
In models that use the definition in the Code Mappings, specify a different storage class or no storage class. Use either the Code Mappings editor or a script.
Embedded Coder DictionaryFor a memory section, update other definitions in the dictionary that use the memory section. Specify a different memory section or no memory section. Use either the Embedded Coder Dictionary or a script.
In models that use the definition in the Code Mappings, specify a different storage class or no storage class. Use either the Code Mappings editor or a script.
Add a definitionPackageIn Embedded Coder Dictionaries that reference the package, refresh the package.
Embedded Coder DictionaryNone

Deploy Changes

See Also

Related Topics