Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture
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 service interfaces, 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.
Create Code Definitions for Use in the Code Mappings Editor
To control the appearance of model elements in the generated code, you apply code definitions to the elements by using the Code Mappings editor. To create code definitions that you and other users can use in the Code Mappings editor, use a code interface configuration in an Embedded Coder Dictionary. Decide what type of code interface configuration to use by considering what type of code you want to generate from your model and how you want to deploy the code in the target execution environment.
Data interface configuration — The code generator creates a program intended to run on the target device. The generated code uses the data interfaces that you define.
Service interface configuration — The code generator creates an algorithm that you intend to deploy within a larger application for a target platform. The platform middleware calls the algorithm code and provides the services for the target device. The generated code calls the services according to your definitions in the service interface configuration. To create a service interface configuration, you must use an Embedded Coder Dictionary that is saved in a SLDD file.
When you create definitions in an Embedded Coder Dictionary, decide where to save the definitions by considering how you intend to use the definitions and the type of code interface configuration. This table lists where to store the code definitions.
|Code Interface Configuration Type||Usage of Definitions||Location for Embedded Coder Dictionary|
|Service interface configuration||Multiple models or one model||SLDD file that all of the models are configured to use for the coder dictionary|
|Data interface configuration||Multiple models — sharing a set of code definitions to standardize code||SLDD file that all of the models are configured to use for the coder dictionary|
|Data interface configuration||One model — prototyping generated code by using one model||Local Embedded Coder Dictionary of the model.|
To use an Embedded Coder Dictionary and for its limitations with respect to code generation definitions, see Embedded Coder Dictionary.
Create Code Definitions for External Data Objects
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.
Use Package Code Definitions in Embedded Coder Dictionaries
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.
Constrain Use of Storage Class 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
Deploy Code Generation Definitions to Users
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.
Interact with Code Definitions in Data Interface Configuration Programmatically
When you use a data interface configuration, you can create and interact with code definitions by using the Embedded Coder Dictionary API.
Represent the Embedded Coder Dictionary by using a
coder.Dictionaryobject. 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.Dictionaryobject to load and refresh the package in the dictionary.
Represent a section of the dictionary by using a
coder.dictionary.Sectionobject. Use the section to access code definitions.
Represent a code definition by using a
coder.dictionary.Entryobject. 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 Data Interface Configuration Programmatically.
- C Code Generation Configuration for Model Interface Elements
- Create Storage Classes by Using the Custom Storage Class Designer
- Generate Code to Conform to Software Architecture by Sharing and Copying Default Settings Between Models
- Control Data and Function Placement in Memory by Inserting Pragmas
- Configure Default C Code Generation for Categories of Data Elements and Functions