Migration of Memory Section and Shared Utility Settings from Configuration Parameters to Code Mappings
For a model created in a release before R2018a, when you open the Embedded Coder app
or use the coder.mapping.create
function for C code generation, Simulink® migrates memory section and shared utility model configuration parameter
settings to the model code mappings. As part of the migration, Simulink configures the Embedded Coder Dictionary that the model uses:
To refer to the package that defines the memory sections, as described in Use Package Code Definitions in Embedded Coder Dictionaries.
To contain a function customization template that specifies the naming rule and, if applicable, memory section settings that you specified for shared utilities.
Effects of Migration
The migration process makes changes to the model file, which you must save. The changes include:
Migration of model configuration parameter settings to settings in the model Embedded Coder Dictionary and code mappings.
Graphical Interface Migration
Parameter in Model Configuration Parameter Dialog Box Embedded Coder Dictionary and Code Mappings Editor Package In the Embedded Coder Dictionary navigation pane, click Memory Section. Then, in the center pane under Memory Sections, click Manage Packages. Initialize/Terminate In the Code Mappings editor, click the Function Defaults tab and select the Initialize/Terminate category. Then, set the Memory Section property to the name of a defined memory section. Execution In the Code Mappings editor, click the Function Defaults tab and select the Execution category. Then, set the Memory Section property to the name of a defined memory section. Shared utility In the Code Mappings editor, click the Function Defaults tab and select the Shared utility category. Then, set the Memory Section property to the name of a defined memory section. Constants In the Code Mappings editor, click the Data Defaults tab and under the Parameters category, select subcategory Constants. Then, set the Memory Section property to the name of a defined memory section. Inputs/Outputs In the Code Mappings editor, click the Data Defaults tab and under the Inports/Outports category, select subcategory Inports or Outports. Then, set the Memory Section property to the name of a defined memory section.
Internal data In the Code Mappings editor, click the Data Defaults tab and under the Inports/Outports category, select subcategory Signals, states, and internal data. Then, set the Memory Section property to the name of a defined memory section. Parameters In the Code Mappings editor, click the Data Defaults tab and under the Parameters category, select subcategory Model parameters or External parameters. Then, set the Memory Section property to the name of a defined memory section.
Programming Interface Migration
Configuration Set Interface Embedded Coder Dictionary and Code Mappings Interface set_param(bdroot,"MemSecPackage", "package-name")
loadPackage
(coderDictionaryObj, "package-name")set_param(bdroot,'MemSecFuncInitTerm', 'memory-section-name')
setFunctionDefault
(codeDictionaryObj,'InitializeTerminate', 'MemorySection','memory-section-name')set_param(bdroot,"MemSecFuncExecute", "memory-section-name")
setFunctionDefault
(coderDictionaryObj,"Execution", "MemorySection","memory-section-name")set_param(bdroot,"MemSecFuncSharedUtil", "memory-section-name")
setFunctionDefault
(coderDictionaryObj,"SharedUtility", "MemorySection", "memory-section-name")set_param(bdroot,"MemSecDataConstants", "memory-section-name")
setDataDefault
(coderDictionaryObj,"Constants", "MemorySection","memory-section-name")set_param(bdroot,"MemSecDataIO", "memory-section-name")
setDataDefault
(coderDictionaryObj,"Inports", "MemorySection","memory-section-name")setDataDefault
(coderDictionaryObj,"Outports", "MemorySection","memory-section-name")set_param(bdroot,"MemSecDataInternal", "memory-section-name")
setDataDefault
(coderDictionaryObj,"InternalData", "MemorySection","memory-section-name")set_param(bdroot,"MemSecDataParameters", "MemSecName")
setDataDefault
(coderDictionaryObj,"ModelParameters", "MemorySection","memory-section-name")setDataDefault
(coderDictionaryObj,"ExternalParameters", "MemorySection","memory-section-name")If a shared Embedded Coder Dictionary is not attached to the model, the model-owned Embedded Coder Dictionary refers to the memory section package and contains a default function customization template.
If a shared Embedded Coder Dictionary is attached to the model, the migration process makes changes to the dictionary, which you must save. The changes include:
If the configuration parameters are stored in the model file (the model does not refer to a
Simulink.ConfigSet
object), the dictionary refers to the memory section package and contains a default function customization template.If the Embedded Coder Dictionary is in a data dictionary that references other dictionaries, the migration process configures the Embedded Coder Dictionary at the bottom of the reference hierarchy so that other models and dictionaries in the hierarchy can use the memory section and function template definitions.
If the model refers to a
Simulink.ConfigSet
object, the migration process configures the Embedded Coder Dictionary in the data dictionary that stores the object.
Starting in R2022b, you can configure the shared Embedded Coder Dictionary that is attached to a model by using model configuration parameter Shared coder dictionary.
Considerations Before Migrating
When the Embedded Coder app opens for a model (for example, after you initiate code generation or open the app explicitly), Simulink executes the migration process. Do not open the Embedded Coder app unless you are ready to migrate memory section and shared utility naming parameter settings.
If a model has multiple configuration sets (one active and one or more inactive) or refers to a
Simulink.ConfigSet
object, the Embedded Coder app displays an informational message indicating that information from the referenced configuration set has been imported into the Embedded Coder Dictionary and code mappings.If you use Simulink data dictionaries, before you or other users open the Embedded Coder app for a model, consider creating and configuring the dictionaries first.
In a hierarchy of referenced data dictionaries (for example, a dictionary hierarchy that parallels a model hierarchy), only one dictionary can contain an Embedded Coder Dictionary. Setting up data dictionaries before migrating associated models enables you to control where the Embedded Coder Dictionary resides in the dictionary hierarchy. Create or identify an Embedded Coder Dictionary at the bottom of the hierarchy so that models in the hierarchy can access the memory section and function template definitions. Then, when you initiate migration by opening Embedded Coder app for a model, Simulink configures that data dictionary.
For information about sharing an Embedded Coder Dictionary between models by using referenced dictionaries, see Share Code Interface Configuration Between Models.
The migration process makes changes based on the active configuration set of the model (see Manage Configuration Sets for a Model). Before you open the model in the Embedded Coder app, activate the configuration set whose settings you want the migration process to use.
The process ignores settings in inactive configuration sets. If different configuration sets of the model specify different settings, you must choose one set to migrate.
Considerations After Migrating
In a branching hierarchy of referenced models and referenced data dictionaries, after you or other users migrate referenced models in different branches, opening the Embedded Coder app in a parent model can generate an error due to the presence of multiple Embedded Coder Dictionaries in the data dictionary hierarchy. To resolve these errors, use
coder.dictionary.move
andcoder.dictionary.remove
to transfer and delete Embedded Coder Dictionaries until only one dictionary remains. Place the remaining Embedded Coder Dictionary in a data dictionary at the bottom of the hierarchy so that the models in the hierarchy can access the memory section and function template definitions.For information about sharing an Embedded Coder Dictionary between models by using referenced dictionaries, see Share Code Interface Configuration Between Models.
After you migrate a model, memory section and shared utility model configuration parameters are not accessible. If you use
set_param
orget_param
to access these configuration parameter settings programmatically, the functions generate errors. To change these settings, use the Code Mappings editor or the programmatic interface as described in C Data and Function Interfaces.If a model contains atomic subsystems that have nondefault memory section settings, you can select the memory sections from built-in packages that are loaded into the Embedded Coder Dictionary. See Override Default Memory Placement for Individual Data Elements and Override Default Memory Placement for Subsystem Functions and Data.
If a model refers to a
Simulink.ConfigSet
object, after migration, the model does not use the memory section and shared utility settings in the object. If you used the object to set the configuration parameters of multiple models:Changing memory section and shared utility settings in the object affects only models that you have not migrated.
Migrated models do not acquire memory section and shared utility settings from a single location (the
Simulink.ConfigSet
object). To change the settings for these models, use the Code Mappings editor of each model.
See Also
Embedded Coder Dictionary | Code Mappings Editor – C
Related Topics
- C Data Code Interface Configuration for Model Interface Elements
- Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture
- Configure Default C Code Generation for Categories of Data Elements and Functions
- Control Data and Function Placement in Memory by Inserting Pragmas
- Generate Shared Utility Code
- C++ Data and Function Interfaces