Service Interface Configuration for Model Interface Elements
Configure a model to use a service code interface if you are deploying C code as a component. Code generated for component deployment must be integrated with other target environment code, including a scheduler.
Model Code Interfaces lists model elements
that you can use to represent interfaces for interacting with target environment resources.
To configure the modeling elements for code generation, in the Code Mappings
editor or by using the code mappings programming interface (coder.mapping.api.CodeMapping
), you map model interface elements to code
definitions.
When applying a service code interface to a model, you can map a model element to a default service interface or to an alternative interface.
Code Definitions
For a service code interface configuration, code definitions include function customization templates, service interfaces, storage classes, and memory sections. A function customization template defines how the code generator produces code for functions. For a function category, you can define a rule for naming functions and a location in memory for function definitions (memory section). Memory section statements appear in the generated code as function declarations. A service interface defines a data communication method (direct-access, outside-execution, or during-execution) and function naming rules for generated calls to service interface functions. A storage class defines properties, such as appearance and location, that the code generator uses when producing code for the associated data when you specify direct-access communication for a service interface.
Memory sections control the placement of data and function definitions in memory. In some cases, you can select a specific memory section that you want when configuring data elements and functions.
You or someone else defines code interface definitions in a shared Embedded Coder Dictionary. Creating custom definitions enables you to achieve code generation objectives for your specific application. For data elements, you also have the option of creating code definitions created in packages by using the Custom Storage Class Designer.
Code definitions appear in the Code Mappings editor and are accessible by using the code mappings programming interface. For some definitions that you create by using the Custom Storage Class Designer, you can make the definitions appear in the Code Mappings editor by configuring an Embedded Coder Dictionary to refer to them.
For more information, see Define Service Interfaces, Storage Classes, Memory Sections, and Function Templates for Software Architecture and Create Storage Classes by Using the Custom Storage Class Designer.
Service Interface Code Mapping Options
Associate model interface elements with code interface definitions that are defined in the model Embedded Coder Dictionary by using the Code Mappings editor or the code mappings programming interface. The code generator uses the mapped code interface definitions to determine what the generated interface code should look like and how the code should be packaged.
When using a service interface configuration, you can map an individual model element
to a code definition that the Embedded Coder Dictionary identifies as the default
definition for that category of elements or to an alternative definition. In the Code
Mappings editor, definitions that the dictionary specifies as the default appear as
Dictionary default:
. For parameters and
parameter arguments, you also have the option of selecting interface-name
Not
tunable
, which is the default mapping unless the dictionary defines a
default parameter tuning or parameter argument tuning interface. Likewise, for signals
and states, you have the option of selecting Not measured
,
which is the default mapping unless the dictionary defines a default measurement
interface. If default definitions meet your component interface requirements, you do not
need to make code mapping changes.
Configure Functions
Open the Embedded Coder® app.
In the Code Mappings editor or by using the code mappings programming interface, check the default interface settings. If you need to change the interface setting for a function, select the function, and then select an interface. Alternatively, you can specify a function name.
Generate and review code.
For more details and examples, see:
Configure Data
Open the Embedded Coder app.
Identify MATLAB variables that you want to configure individually and store the configurations in the model file. In the Model Explorer, convert the variables to
Simulink.Parameter
objects. The resulting data objects appear in the Code Mappings editor as model parameters.Identify signals representing algorithm data that you want to monitor while the generated code executes and configure those signals individually. For each signal that you identify, add the signal to the code mappings.
Configure individual data elements. In the Code Mappings editor, check the default interface settings. If you need to change the interface setting for an element, click the relevant category tab, select the data element, and select an interface. Optionally, for inports, outports, parameters, signals, and states, you can use the Identifier property to inform the code generator how to represent the element in the code.
Generate and review code.
For more details and examples, see:
See Also
Code Mappings Editor
– C | Embedded Coder
Dictionary | coder.mapping.api.CodeMapping
Related Topics
- Configure Sender and Receiver Service Interfaces for Model Inports and Outports
- Configure Data Transfer Service Interfaces for Data Transfer Signals
- Configure Parameter and Parameter Argument Tuning Service Interfaces for Model Parameters and Model Parameter Arguments
- Configure Measurement Service Interfaces for Signals, States, and Data Stores
- Configure Generated C Function Interface for Model Entry-Point Functions