Create a Service Interface Configuration
When you generate component code for deployment in a target execution environment, you can configure the generated code to use the services that the target execution environment provides. To describe the services to the code generator, you create a service interface configuration in an Embedded Coder Dictionary. To generate code for the target environment, you share the dictionary among your models and apply the service interface configuration to the models. Separating your models from the service interface configuration in this manner enables you to:
Develop large and complex embedded systems using a scalable approach.
Easily deploy the same service interface configuration to many models simultaneously.
Quickly change the service interface configuration for a system without editing the individual models.
After you create a service interface configuration, you share it with the models from which you want to generate code for the target execution environment. By default, the generated code interacts with the platform middleware, which is the set of services provided by the target execution environment. You can further configure individual models to suit your code generation objectives by mapping model elements to specific interface definitions from the configuration..
Identify Software Platform Requirements
This table lists the code definitions that you can create for a service interface configuration. Consider how your code interacts with the platform middleware and identify the code definitions that you need to create to specify that behavior.
|Execution function customization template|
Controls the naming of model entry-point functions and optionally applies memory sections. Execution function templates for a service interface configuration include:
Defines properties such as the name and data communication method for model elements that use platform services. Service interfaces include:
|Internal function customization template|
Controls the naming of functions that the component calls and optionally applies memory sections. Internal function templates for a service interface configuration include:
Define the appearance, placement, and storage of the data and functions in generated code.
Create a Service Interface Configuration in a Standalone Embedded Coder Dictionary
To create a service interface configuration, you must create a standalone Embedded Coder Dictionary that contains the configuration. Storing the service interface configuration in a standalone Embedded Coder Dictionary enables you to share the configuration with multiple models.
Open the Model Explorer.
Click File > New > Embedded Coder Dictionary.
Specify a name for the Embedded Coder Dictionary. For this example, name the dictionary
InterfaceCoderDictionary. The dictionary is created in the current folder. You can optionally select the location to create the dictionary by clicking Browse. Click Next.
Select the Service Interface configuration option. Click Create.
The Embedded Coder Dictionary opens and shows the service interface configuration.
Create Code Definitions for the Service Interface Configuration
Define the interfaces of the generated code by creating code definitions in the service interface configuration. For this example, create a function customization template and a sender service interface definition.
Define Prototypes for Callable Functions
To control the naming of functions in the generated code, define function
customization templates. For this example, define a function template named
StepFunctions for model step functions and define the
naming rule for the functions.
In the Embedded Coder Dictionary, on the left pane, click Execution.
For the Periodic and Aperiodic Functions list, click Create.
On the right pane, set these properties:
Function Naming Rule —
Confirm the appearance of the generated function declaration and definition in the Pseudocode Preview pane.
In the table, select the new function template as the dictionary default.
For models that use the service interface configuration, the code generator creates the periodic and aperiodic functions by using the template that you created by default. The other function templates are available for use in the Code Mappings editor.
Define Services for a Service Interface Configuration
Specify how the generated code calls the services of the platform middleware by creating service interface definitions. You can define these types of service interfaces:
Parameter argument tuning
For this example, define a sender service interface that communicates outside of function execution.
On the left pane, click Service Interfaces.
In the Sender section, click Create.
On the right pane, set these properties:
Data Communication Method —
Function Naming Rule —
Confirm the appearance of the generated sender declaration and definition in the Pseudocode Preview pane.
In the table, select the new sender service interface as the dictionary default.
Configure Default Settings
For each category of definitions in a service interface configuration, there is one default definition that the generated code uses when you apply the configuration to a model. The full list of definitions for each category appears in the code mapping for the models that use the configuration. For an individual model, you can override the default definition by applying a different definition to the category or to an individual model element.
To specify the dictionary default, navigate to the interface category in the dictionary. On the row for the interface that you want to select, click the circle in the Dictionary Default column.
Test the Service Interface Configuration
To see how the data and functions appear in the generated code, apply the service interface configuration to the model and generate code.
Open the model from which you want to generate code using the service interface configuration.
Open the configuration parameters. on the Modeling tab, click Settings.
Set the parameter Shared coder dictionary to the name of the data dictionary that contains the service interface configuration. For this example, use the dictionary
InterfaceCoderDictionary.sldd. Click OK.
Click Generate Code. Confirm that the generated code shows the service interfaces that you defined in the dictionary.
Deploy Code Interface Configuration Definition to Models
To configure the code interface for a large system with many models, share the code interface configuration with the models and configure them to use the platform.
Attach the shared coder dictionary that contains the interface configuration to the models, as shown in the previous section.
Configure the deployment type of each model. See Deploy Code Generation Definitions.
Apply model-specific configurations by using the Code Mappings table in each model. See C Code Generation Configuration for Model Interface Elements.
For more information about sharing the code interface configuration among your models, see Deploy Code Generation Definitions.
Embedded Coder Dictionary | Code Mappings Editor – C