Code Mappings – C++ Editor
Configure how model elements and functions appear in generated C++ code
Description
The Code Mappings editor is a graphical interface used to configure how Simulink® model data elements and functions appear in generated C++ code.
To configure Simulink model data elements and functions for C++ code generation, use the tables in the Code Mappings editor:
Data
Functions
Open the Code Mappings – C++ Editor
Open the Embedded Coder® app. Verify the Output is set to Embedded Code - C++. On the C++ Code tab, click the Code Interface menu and select Code Mappings.
Examples
Configure Data Elements
You can use the Code Mappings editor to customize the data visibility and method
access of model elements in the generated C++ class interface. This example uses the
model rtwdemo_roll
to show how to configure the data visibility
and method access for the inports in this model.
Open model
rtwdemo_roll
.Open the Embedded Coder app. In the Apps gallery, click Embedded Coder.
Set the language to C++. On the C++ Code tab, click Output and select Embedded Code - C++.
Open the Code Mappings editor. From the tab, click Code Interface and select Code Mappings.
In the Code Mappings editor, click the Data tab.
Customize the data visibility. For the Inports category, in the Data Visibility column, select
public
.Customize the method access. For the Inports category, in the Member Access Method column, select
method
.
Generate code.
Verify the generated C++ code for the inports. In the Code view, open
rtwdemo_roll.cpp
file and search for the inports in the model.
Configure Functions
You can use the Code Mappings editor to customize the names of entry-point
functions and the names and arguments of base-rate periodic or Simulink Functions.
This examples uses the model rtwdemo_roll
to show how to
configure the name and arguments of a base-rate periodic function.
Open model
rtwdemo_roll
.Open the Embedded Coder app. In the Apps gallery, click Embedded Coder.
Set the language to C++. On the C++ Code tab, click Output and select Embedded Code - C++.
Open the Code Mappings editor. From the tab, click Code Interface and select Code Mappings.
In the Code Mappings editor, click the Functions tab.
Customize the name of the periodic function. In the Function Name column, enter the name
roll_run
.Customize the arguments of the periodic function. In the Function Preview column, click the prototype hyperlink. A configuration dialog box opens.
In the dialog box, select Configure arguments for Step function prototype and click Get Default. A table that displays the arguments opens.
Customize the arguments:
From the C++ return argument drop-down list, select
Ail_Cmd
.For each port, in the C++ Identifier Name field, remove the
arg_
prefix from their default names.For the
HDG_Mode
inport, from the C++ Type Qualifier drop-down list, selectPointer
. In the C++ Identifier Name field change the name toHDG_Mode_Ptr
Click Apply. Visually verify that the function prototype reflects the changes. Click OK to exit.
Generate code.
Verify the updated method names and arguments in the generated C++ code. In the Code view, in the open
rtwdemo_roll.cpp
file, search for the base-rate periodic function,roll_run
.
Parameters
DataModel Element Category
— Category of model data elements
character vector
Each category describes a type of Simulink model data element. The data visibility and method access set for a category applies to the data elements in that category for the model.
Model Element Category | Description |
---|---|
Inports | Root-level data input ports of a model, such as Inport and In Bus Element blocks. |
Outports | Root-level data output ports of a model, such as Outport and Out Bus Element blocks. |
Model parameter arguments | Workspace variables that appear as per instance (nonstatic) class data members. |
Model parameters | Workspace variables that are shared across instances of the model class and are generated as static class data members. |
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. |
Data Visibility
— Determines the access specifier for the generated class members
character vector
The data visibility determines if data elements appear in generated code as public or private. For model parameter arguments, this parameter can also specify that data elements are generated outside the class and passed as individual arguments.
Member Access Method
— Determines the generated get and set methods for class members
character vector
The access determines how the generated code provides access to the class member data.
Source
— Functions in a model
character vector
The functions in a model that generate entry-point methods in a C++ class interface. The functions include:
Initialize Functions
Terminate Functions
Periodic Functions
Partition Functions
Exported Functions
Reset Functions
Simulink Functions
Method Name
— Name of generated class method
character vector
Name for the generated class method.
Method Preview
— Preview of method prototype
character vector
Preview of the entry-point method prototype. To customize the prototype, click the preview hyperlink and configure the method in the opened dialog box.
Version History
Introduced in R2021a