Main Content

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.

Code DefinitionPurpose
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:

  • Initialize and terminate functions

  • Periodic and aperiodic functions including model step functions

Service interface

Defines properties such as the name and data communication method for model elements that use platform services. Service interfaces include:

  • Receiver service interfaces

  • Sender service interfaces

  • Data transfer service interfaces

  • Timer service interfaces

  • Parameter tuning service interfaces

  • Parameter argument tuning service interfaces

  • Measurement service interfaces

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:

  • Subcomponent functions

  • Shared utility functions

Memory

Define the appearance, placement, and storage of the data and functions in generated code.

  • Storage class — You apply a storage class to receiver, sender, parameter, and measurement interfaces.

  • Memory section — Controls the placement of data and function definitions in memory by using pragmas and other code decorations. You apply a memory section to storage classes and function templates.

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.

  1. Open the Model Explorer.

  2. Click File > New > Embedded Coder Dictionary.

  3. 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.

  4. 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.

  1. In the Embedded Coder Dictionary, on the left pane, click Execution.

  2. For the Periodic and Aperiodic Functions list, click Create.

  3. On the right pane, set these properties:

    • NameStepFunctions

    • Function Naming Rule$R$N_func

    Confirm the appearance of the generated function declaration and definition in the Pseudocode Preview pane.

  4. 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:

  • Receiver

  • Sender

  • Data transfer

  • Timer

  • Parameter tuning

  • Parameter argument tuning

  • Measurement

For this example, define a sender service interface that communicates outside of function execution.

  1. On the left pane, click Service Interfaces.

  2. In the Sender section, click Create.

  3. On the right pane, set these properties:

    • NameMySender

    • Data Communication MethodOutside Execution

    • Function Naming Rule$R_set_$X$N

    Confirm the appearance of the generated sender declaration and definition in the Pseudocode Preview pane.

  4. 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.

  1. Open the model from which you want to generate code using the service interface configuration.

  2. Open the configuration parameters. on the Modeling tab, click Settings.

  3. 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.

  1. Link the models to the shared coder dictionary that contains the interface configuration, as shown in the previous section.

  2. Configure the deployment type of each model. See Deploy Code Generation Definitions.

  3. 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.

See Also

|

Related Topics