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. To create and deploy an Embedded Coder Dictionary, see Create an Embedded Coder Dictionary and Deploy Code Generation Definitions.
Share Available Code Definitions with New Models
If you share code definitions in an Embedded Coder 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
does not have a shared coder dictionary attached to it by default, and the new model
cannot access code generation definitions.
To make code definitions available to a new model automatically, write callbacks and other code that immediately configures the model to use the shared coder dictionary that contains the definitions.
For a simple example that shows how to attach a shared coder dictionary to a model programmatically and for information about configuring Embedded Coder Dictionaries programmatically, see Create Data Interface Configuration Programmatically.
If you use a project, consider creating a project shortcut that creates a model and immediately configures the new model to use the shared coder dictionary. For information about projects and project shortcuts, see What Are Projects?.
Consider using a shared configuration set for the models. Define the configuration set you want to share inside an Embedded Coder Dictionary. When you create a new model, open the Model Configuration Parameters dialog box and click on Code Generation. Then, set the parameter Shared coder dictionary to the name of the Embedded Coder Dictionary. For more information, see Share a Configuration with Multiple Models.
To manually share the definitions with a new model, see Share Code Interface Configuration 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 a shared coder dictionary is attached to the model, Simulink uses the shared coder 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:
Use the Embedded Coder Dictionary tool, as described in Embedded Coder Dictionary.
Use a script, as described in Create Data Interface Configuration Programmatically. You can write a script to automatically make a change to many code definitions in an Embedded Coder Dictionary.
If you store the Embedded Coder Dictionary in a shared SLDD file, save the file after you update the code definitions. If you store the Embedded Coder Dictionary in a model, save the model 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 Changes | Storage Location | Updates |
---|---|---|
Change the name of a definition | Package | For 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 Dictionary | None | |
Change properties of a definition | Package | In Embedded Coder Dictionaries that reference the package, refresh the package. |
Embedded Coder Dictionary | None | |
Delete a definition | Package | For 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 Dictionary | For 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 definition | Package | In Embedded Coder Dictionaries that reference the package, refresh the package. |
Embedded Coder Dictionary | None |