Code Mappings – C++ Editor
Configure how model elements and functions appear in generated C++ code
Since R2021a
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 RollAxisAutopilot
to show how to configure the data
visibility and method access for the inports in this model.
Open model
RollAxisAutopilot
.openExample('RollAxisAutopilot')
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
RollAxisAutopilot.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 RollAxisAutopilot
to show how to
configure the name and arguments of a base-rate periodic function.
Open model
RollAxisAutopilot
.openExample('RollAxisAutopilot')
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
RollAxisAutopilot.cpp
file, search for the base-rate periodic function,roll_run
.
Related Examples
- Interactively Configure C++ Interface
- Programmatically Configure C++ Interface
- Configure Parameters for C++ Interface Code Generation
Parameters
Version History
Introduced in R2021a