Code Mappings – C++ Editor - Configure how model elements and functions appear in generated C++
code - MATLAB ([original](https://in.mathworks.com/help/ecoder/ref/codemappingsceditor.html)) ([raw](?raw))
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 theCode 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.
Set Up the Environment
- 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.
Customize the Data Visibility and Method Access of Data Elements
- 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 and Verify Code
- Generate code.
- Verify the generated C++ code for the inports. In theCode 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.
Set Up the Environment
- 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.
Customize Function Name and Arguments
- 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 theFunction 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 theC++ Type Qualifier drop-down list, selectPointer
. In the C++ Identifier Name field change the name toHDG_Mode_Ptr
- From the C++ return argument drop-down list, select
- Click Apply. Visually verify that the function prototype reflects the changes. Click OK to exit.
Generate and Verify Code
- 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
Data
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 asInport and In Bus Element blocks. |
Outports | Root-level data output ports of a model, such asOutport and Out Bus Element blocks. |
Model parameter arguments | Workspace variables that appear as 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. |
The data visibility determines if data elements appear in generated code as public, protected, or private. For model parameter arguments, this parameter can also specify that block parameters in referenced models are generated outside the class and passed as individual arguments.
The access determines how the generated code provides access to the class member data.
Functions
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
Name for the generated class method.
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