Code Mappings Editor – C
Associate model elements with code interface definitions
Description
The Code Mappings editor is a graphical interface where you can configure data elements in a model for code generation. Each model in a model reference hierarchy has its own code mappings. Associate each category of model data element with a specific storage class throughout a model. Then, override those settings, as needed, for specific data elements.
A storage class defines properties such as appearance and location, which the code generator uses when producing code for associated data.
To configure data elements and functions for code generation, use the tables in the Code Mappings editor display:
Data Defaults
Inports
Outports
Parameters
Data Stores
Signals/States
When there are additional code mapping properties that can be configured for a model
element, you can configure these properties by selecting a row in the active table and
clicking the icon.
Before you can configure a signal for code generation, add the signal to the model code mappings. Add and remove signals from the code mappings by pausing on the ellipsis that appears above or below a signal line to open the action bar. Click the Add Signal or Remove Signal button. These buttons are also available in the Code Mappings editor on the Signals/States tab.
Open the Code Mappings Editor – C
Do one of the following:
Open the Simulink® Coder™ app. On the C Code tab, select Code Interface > Default Code Mappings or Code Interface > Individual Element Code Mappings.
Open the Simulink Coder app. On the C Code tab, in the bottom left corner of the Simulink Editor window, click the Code Mappings tab.
In the model canvas of the Simulink Editor window, click the perspective control in the lower-right corner and select Code. Then, click the Code Mappings tab.
Examples
Configure Code Generation for Root-Level Inport and Outport Blocks
Configure code generation for the root-level Inport and Outport blocks throughout a model. Applying default configurations can save time, especially for large-scale models that use a significant amount of data. After applying default mappings, you can adjust mappings for individual data elements.
Copy external code file
exDblFloat.h
into a writable folder.copyfile(fullfile(matlabroot,'toolbox','rtw','rtwdemos','exDblFloat.h'));
Open model
rtwdemo_configrpinterface
. Save a copy of the model into the same location as fileexDblFloat.h
.Open the Simulink Coder app. The C Code tab includes the Code Mappings editor.
Configure the code generator to declare and define global variables for
inports and outports in generated files
rtwdemo_configrpinterface.h
and
rtwdemo_configrpinterface.c
.
In the C Code tab, select Code Interface > Default Code Mappings.
In the Data Defaults tab, under Inports and Outports, select the row for Inports. Then, set the storage class to
ImportedExternPointer
. Set the storage class for Outports toExportedGlobal
. The editor updates the default storage class setting for the two selected data element categories.
In the Code Mappings editor, click the Inports tab. The storage class for each inport is set to
Auto
, which means that the code generator might eliminate or change the representation of relevant code for optimization purposes. If optimizations are not possible, the code generator applies the model default configuration.Force the code generator to use the default configuration for inports, which is storage class
ImportedExternPointer
. Press the Ctrl key and select the inports. For one of the selected inports, set the storage class toModel default: ImportedExternPointer
. The editor updates the storage class setting for the seleccted inports.Force the code generator to use storage class
ExportedGlobal
for the model root outport. Click the Outports tab. Select the row forOut2
. Then, set the storage class toModel default: ExportedGlobal
.
To configure properties for individual data elements, for example, if you need
to override default configuration settings, use the tabs for the different data
element types. For this example, override the default storage class setting for
Inport block In1
.
By default, the code generator names inport and outport variables based on the
Inport or Outport block name in the model.
When you configure data elements with a storage class setting other than
Auto
, you can override that default setting for
individual elements by setting storage class property
Identifier. This property enables you to specify an
identifier for the code without modifying the model design. For this example,
set Identifier for the Inport and
Outport blocks.
In the Code Mappings editor, click the Inports tab.
For
In1
, set the storage class toImportedExtern
.For each inport, select the row. Then, click the
icon. Set the Identifier property as follows:
Set
In1
toinput1
.Set
In2
toinput2
.Set
In3
toinput3
.Set
In4
toinput4
.
Click Outports.
Select outport
Out1
. Click theicon and set the Identifier property to
output
.
Generate code and verify that the code generated for the Inport and Output blocks appears as you expect. For example:
rtwdemo_configrpinterface_private.h
includes these declarations:/* Exported data declaration */ /* Data with Imported storage */ extern real_T input1; /* '<Root>/In1' */ extern real_T input2; /* '<Root>/In2' */ extern real_T input3; /* '<Root>/In3' */ extern real_T input4; /* '<Root>/In4' */
rtwdemo_configrpinterface.h
listsoutput
as field in output structureExtY_rtwdemo_configrpinterfac_T
./* External outputs (root outports fed by signals with default storage) */ typedef struct { real_T output; /* '<Root>/Out1' */ } ExtY_rtwdemo_configrpinterfac_T;
This code fragment shows the variable that represents
In2
,input2
, being used in the generated entry-point step function for sample rate of 1 second./* Model step function for TID1 */ void rtwdemo_configrpinterface_step1(void) /* Sample time: [1.0s, 0.0s] */ { /* Lookup_n-D: '<Root>/Table1D' incorporates: * Inport: '<Root>/In2' */ rtwdemo_configrpinterface_B.Table1D = look1_binlcpw(input2, rtwdemo_configrpinterfac_ConstP.Table1D_bp01Data, rtwdemo_configrpinterfac_ConstP.Table1D_tableData, 10U); . . .
Related Examples
- C Code Generation Configuration for Model Interface Elements
- Choose Data Configuration Approach
- Choose Storage Class for Controlling Data Representation in Generated Code
- Configure Generated C Function Interface for Model Entry-Point Functions
Parameters
Data DefaultsModel Element Category
— Category of model data elements
character vector
Names a category of Simulink model data elements. The storage class that you set for a category applies to elements in that category throughout the model.
Model Element Category | Description |
---|---|
Inports | Root-level input ports of a model, such as Inport and In Bus Element blocks. |
Outports | Root-level output ports of a model, such as Outport and Out Bus Element blocks. |
Signals, states, and internal data | Data elements that are internal to the model, such as block output signals, discrete block states, data stores, and zero-crossing signals. |
Shared local data stores | Data Store Memory blocks that have the block parameter Share across model instances set. These data stores are accessible only in the model where they are defined. The data store value is shared across instances of the model. |
Global data stores | Data stores that are defined by a signal object in the base workspace or in a
data dictionary. Multiple models in an application can use these data stores. To
view and configure these data stores in the Code Mappings editor, click the
Refresh link to the right of the category name. Clicking
this link updates the model diagram. |
Model parameters | Parameters that are defined within a model, such as parameters in the model workspace. Excludes model arguments. |
External parameters | Parameters that you define as objects in the base workspace or in a data dictionary. Multiple
models in an application can use these parameters. To view and configure these
parameters in the Code Mappings editor, click the Refresh
link to the right of the category name. Clicking this link updates the model
diagram. |
The Code Mappings editor presents valid storage class options for a given category. The options can include:
Unspecified storage class (
Default
). The code generator places the code for the category of data elements in standard structures, such asB_
,ExtY_
,ExtU_
,DW_
, andP_
. See Data Structures in the Generated Code.Relevant predefined storage classes, such as
ExportedGlobal
.Relevant storage classes in an available package, such as
ImportFromFile
(requires Embedded Coder®) .Storage class defined in an Embedded Coder Dictionary (requires Embedded Coder) .
Storage Class
— Code definition for model data elements
character vector
Definition (specification) that the code generator uses to determine
properties, such as appearance and location, for code that it produces for
model data elements. Valid settings are
Default
,
ExportedGlobal
,
ImportedExtern
, and
ImportedExternPointer
. See Choose Storage Class for Controlling Data Representation in Generated Code.
Source
— Name of root-level Inport block or bus element
character vector
Identifies a root Inport block or an element of an In Bus Element block
(for example, InBus1.signal1
) in the model. If the
element resolves to a data object, the Code Mappings editor displays a
resolve-to-signal-object icon to the right of the source name and resolves
the configuration based on whether the storage class setting for the element
is Auto
. If the storage class is Auto
,
the data element assumes the code configuration that the data object
specifies. The editor changes the display text in the Storage
Class column to From signal object:
followed by the name of the storage class of the data object. If the storage
class is not Auto
, the data element assumes the
configuration that you specify in the Code Mappings editor.
Storage Class
— Code definition for root inport
character vector
Definition that the code generator uses to determine properties, such as
appearance and location, for code that it produces for the root inport.
Valid settings are
Auto
, Model
default
, ExportedGlobal
,
ImportedExtern
, and
ImportedExternPointer
. See Choose Storage Class for Controlling Data Representation in Generated Code.
Identifier
— Name of variable
character vector
Name for the variable that represents the inport in the generated code.
CalibrationAccess
— Enable or disable calibration of the inport
NoCalibration
(default) | Calibration
Select Calibration
for the inport to enable the
calibration. Select NoCalibration
to view the value of
the inport and disable the calibration.
CompuMethod
— Name of conversion method
character vector
Name of the method for converting the ECU-internal value to a physical value for easy readability.
DisplayIdentifier
— Display name of the inport
character vector
Optional display name of the inport for the measurement purpose in the calibration tool, which is different than the inport name in the Simulink model.
Format
— Display format of the inport value
%[length].[layout]
Special display format to be specified for measurement in the calibration
tool. This format specification overrules the display format specified in
CompuMethod
of the inport.
Source
— Name of root Outport block or bus element
character vector
Identifies a root-level Outport block or an element of an
Out Bus Element block (for example,
OutBus1.signal1
) in the model. If the element
resolves to a data object, the Code Mappings editor displays a
resolve-to-signal-object icon to the right of the source name and resolves
the configuration based on whether the storage class setting for the element
is Auto
. If the storage class is Auto
,
the data element assumes the code configuration that the data object
specifies. The editor changes the display text in the Storage
Class column to From signal object:
followed by the name of the storage class of the data object. If the storage
class is not Auto
, the data element assumes the
configuration that you specify in the Code Mappings editor.
Storage Class
— Code definition for root outport
character vector
Definition that the code generator uses to determine properties, such as
appearance and location, for code that it produces for the root outport.
Valid settings are
Auto
, Model
default
, ExportedGlobal
,
ImportedExtern
, and
ImportedExternPointer
. See
Choose Storage Class for Controlling Data Representation in Generated Code.
Identifier
— Name of variable
character vector
Name for the variable that represents the outport in the generated code.
CalibrationAccess
— Enable or disable calibration of the outport
NoCalibration
(default) | Calibration
Select Calibration
for the outport to enable the
calibration. Select NoCalibration
to view the value of
the outport and disable the calibration.
CompuMethod
— Name of conversion method
character vector
Name of the method for converting the ECU-internal value to a physical value for easy readability.
DisplayIdentifier
— Display name of the outport
character vector
Optional display name of the outport for the measurement purpose in the calibration tool, which is different than the outport name in the Simulink model.
Format
— Display format of the outport value
%[length].[layout]
Special display format to be specified for measurement in the calibration
tool. This format specification overrules the display format specified in
CompuMethod
of the outport.
Source
— Name of model parameter argument, model parameter, or external parameter
character vector
Identifies a parameter in the model. If the element resolves to a data
object, the Code Mappings editor displays a resolve-to-parameter-object icon
to the right of the source name and resolves the configuration based on
whether the storage class setting for the element is
Auto
. If the storage class is Auto
,
the data element assumes the code configuration that the data object
specifies. The editor changes the display text in the Storage
Class column to From parameter object:
followed by the name of the storage class of the data object. If the storage
class is not Auto
, the data element assumes the
configuration that you specify in the code mappings.
Types of parameter elements are listed in this table.
Type of Parameter Element | Description |
---|---|
Model parameter | Parameter that is defined within a model, such as a parameter in the model workspace. Excludes model arguments. |
External parameter | Parameter that you define as an object in the base
workspace or in a data dictionary. Multiple models in an
application can use these parameters. This grouping of
parameters appears in the editor only if the model uses such
an element. To view and configure these parameters in the
Code Mappings editor, click the Refresh
link to the right of the category name. Clicking this link
updates the model diagram. |
Storage Class
— Code definition for parameter
character vector
Definition that the code generator uses to determine properties, such as
appearance and location, for code that it produces for the parameter. For
external parameters, after you click the Refresh
link to
the right of the category name, the compiled storage class (for example, the
storage class configured for an external parameter) appears on the right
side of the Storage Class column. Valid settings are Auto
,
Model default
,
ExportedGlobal
,
ImportedExtern
, and
ImportedExternPointer
. See
Choose Storage Class for Controlling Data Representation in Generated Code.
Identifier
— Name of variable
character vector
Name for the variable that represents the model parameter or model parameter argument in the generated code.
CalibrationAccess
— Enable or disable calibration of the model parameter
NoCalibration
(default) | Calibration
Select Calibration
for the model parameter to enable
the calibration. Select NoCalibration
to view the value
of the model parameter and disable the calibration.
CompuMethod
— Name of conversion method
character vector
Name of the method for converting the ECU-internal value to a physical value for easy readability.
DisplayIdentifier
— Display name of the model parameter
character vector
Optional display name of the model parameter for the measurement purpose in the calibration tool, which is different than the outport name in the Simulink model.
Format
— Display format of the model parameter value
%[length].[layout]
Special display format to be specified for measurement in the calibration
tool. This format specification overrules the display format specified in
CompuMethod
of the model parameter.
Source
— Name of local data store, shared local data store, or global data store
character vector
Identifies a data store in the model. If the element resolves to a data
object, the Code Mappings editor displays a resolve-to-signal-object icon to
the right of the source name and resolves the configuration based on whether
the storage class setting for the element is Auto
. If the
storage class is Auto
, the data element assumes the code
configuration that the data object specifies. The editor changes the display
text in the Storage Class column to From
signal object:
followed by the name of the storage class of
the data object. If the storage class is not Auto
, the
data element assumes the configuration that you specify in the code
mappings.
Types of data store elements are listed in this table.
Type of Data Store Element | Description |
---|---|
Local data store | Data store that is accessible from anywhere in the model hierarchy that is at or below the level at which you define the data store. You can define a local data store graphically in a model by including a Data Store Memory block or by creating a signal object (synthesized data store) in the model workspace. |
Shared local data store | Data Store Memory block that has the block parameter Share across model instances set. These data stores are accessible only in the model where they are defined. The data store value is shared across instances of the model. This grouping of data stores appears in the editor only if such an element exists in the model. |
Global data store | Data store that is defined by a signal object in the base
workspace or in a data dictionary. Multiple models in an
application can use these data stores. These data stores are
not configurable in the code mappings. After you click the
refresh button, they appear in the Code Mappings editor in a
read-only state for viewing or accounting purposes. This
grouping of data stores appears in the editor only if the
model uses such an element. To view and configure these data
stores in the Code Mappings editor, click the
Refresh link to the right of the
category name. Clicking this link updates the model
diagram. |
Names of local and shared local data stores appear in the format
. block-name
:
data-store-name
Depending on how the data store element is represented and configured in the model, local and shared local data stores can resolve to a signal object in the model workspace, based workspace, or a data dictionary. Global data stores resolve to a signal object in the base workspace or a data dictionary.
Storage Class
— Code definition for data store
character vector
Definition that the code generator uses to determine properties, such as
appearance and location, for code that it produces for the data store. For
global data stores, after you click the Refresh
link to
the right of the category name, the compiled storage class (for example, the
storage class configured for a global data store) appears on the right side
of the Storage Class column. Valid settings are Auto
, Model
default
, ExportedGlobal
,
ImportedExtern
, and
ImportedExternPointer
. See
Choose Storage Class for Controlling Data Representation in Generated Code.
Path
— Path to data store in model
character vector
Link that you can click to highlight the data store in the model diagram.
Identifier
— Name of variable
character vector
Name for the variable that represents the data store in the generated code.
CalibrationAccess
— Enable or disable calibration of the data store
NoCalibration
(default) | Calibration
Select Calibration
for the data store to enable the
calibration. Select NoCalibration
to view the value of
the data store and disable the calibration.
CompuMethod
— Name of conversion method
character vector
Name of the method for converting the ECU-internal value to a physical value for easy readability.
DisplayIdentifier
— Display name of the data store
character vector
Optional display name of the data store for the measurement purpose in the calibration tool, which is different than the outport name in the Simulink model.
Format
— Display format of the data store value
%[length].[layout]
Special display format to be specified for measurement in the calibration
tool. This format specification overrules the display format specified in
CompuMethod
of the data store.
Source
— Name of signal or state
character vector
Identifies a signal line or state in the model. If the element resolves to
a data object, the Code Mappings editor displays a resolve -to-signal-object
icon to the right of the source name and resolves the configuration based on
whether the storage class setting for the element is
Auto
. If the storage class is Auto
,
the data element assumes the code configuration that the data object
specifies. The editor changes the display text in the Storage
Class column to From signal object:
followed by the name of the storage class of the data object. If the storage
class is not Auto
, the data element assumes the
configuration that you specify in the Code Mappings editor.
The Code Mappings editor lists:
Named signals and states by using the data element name
Unnamed signals by using the format
source-block
:port-number
States used in multiple blocks by using the format
block-name
:state-name
To configure an individual signal line in the Code Mappings editor for a model, first you must add the signal to the mappings. See Configure Signal Data for C Code Generation.
Storage Class
— Code definition for signal
character vector
Definition that the code generator uses to determine properties, such as
appearance and location, for code that it produces for the signal line or
state. Valid settings are
Auto
, Model
default
, ExportedGlobal
,
ImportedExtern
, and
ImportedExternPointer
. See
Choose Storage Class for Controlling Data Representation in Generated Code.
Path
— Path to signal line or state in model
character vector
Link that you can click to highlight the signal line or block that uses the state in the model diagram.
Identifier
— Name of variable
character vector
Name for the variable that represents the signal or state in the generated code.
CalibrationAccess
— Enable or disable calibration of the signal or state
NoCalibration
(default) | Calibration
Select Calibration
for the signal or state to enable
the calibration. Select NoCalibration
to view the value
of the signal or state and disable the calibration.
CompuMethod
— Name of conversion method
character vector
Name of the method for converting the ECU-internal value to a physical value for easy readability.
DisplayIdentifier
— Display name of the signal or state
character vector
Optional display name of the signal or state for the measurement purpose in the calibration tool, which is different than the outport name in the Simulink model.
Format
— Display format of the signal or state value
%[length].[layout]
Special display format to be specified for measurement in the calibration
tool. This format specification overrules the display format specified in
CompuMethod
of the signal or state.
Version History
Introduced in R2020b