Trace Simulink Model Elements in Generated Code
To verify the generated code, Embedded Coder® provides bidirectional traceability between the Simulink® model and the generated code. You can use either method for traceability:
Code-to-model: The generated code displays these hyperlinks in comment lines in the generated code:
To highlight the corresponding block or subsystem in the Simulink Editor, click the hyperlinks.
Model-to-code: You can select single or multiple blocks of a model in the Simulink Editor and navigate to the corresponding generated code.
The Code view in code perspective provides bidirectional traceability by default.
To use hyperlinks for tracing code-to-model elements:
Open the model and configure it as an ERT target.
Build or generate code for the model. The Code view opens by default to display the generated code next to the model.
In the generated code, place your cursor over the block names in comments to highlight source blocks. For example, generate an HTML report for the model
rtwdemo_hyperlinks. In the generated code for the model step function in
rtwdemo_hyperlinks.c, place your cursor over the
UnitDelay: '<Root>/X'block. In the model window, the corresponding
UnitDelayblock is highlighted.
To use line numbers for tracing code-to-model elements:
In the previous model,
rtwdemo_hyperlinks, click the hyperlink at line number 153. The line numbers can differ from the numbers that appear in your generated code.
In the model window, the Chart subsystem is highlighted and contains the functionality on line 153.
Traceability to Hidden Blocks
The code generator sometimes inserts hidden blocks during the code generation process for various reasons, for example, to maintain data integrity. Comments for the hidden blocks are included in the generated code. These comments, and the code generated from the hidden block, trace back to the original block in the model that triggered the insertion of the hidden block. Comments to hidden blocks follow this template:
/* <Hidden_Block_Type> generated from: <Hyperlinked_Original_Block_Name> */
/* SignalConversion generated from: '<Root>/Subsystem' */ Varianttoground_B.VM_Conditional_Signal_Subsystem_0 = 0.0;
SignalConversionis not present in the model. You can trace to the
'<Root>/Subsystem'block in the model that triggered the insertion of the hidden block by clicking on the hyperlink on
'<Root>/Subsystem'. For more information on this example, see Code Generation for Variant Blocks with One Variant Choice.
To trace model elements to their corresponding generated code:
Complete steps 1 and 2 as in Code-to-Model Traceability
Build or generate code for the model. The generated code is displayed in the Code view window next to the model.
In the model window, click on a model element. To select multiple blocks, hold the SHIFT key and select additional blocks.
In the generated code in Code view window, you see the first instance of highlighted code that is generated for the model element. At the top of the Code view, numbers that appear to the right of generated file names indicate the total number of highlighted lines in each file. This figure shows the result of tracing the Unit Delay block in model
At the top of the code window, use the navigation bar to move forward and backward through multiple instances of highlighted lines. Use the navigation sidebar to go directly to a line of code.
If you close and reopen a model, the Code view does not open until you open the Embedded Coder app. The Code view might not be available because Embedded Coder cannot find a build folder for your model in the current working folder. Reset the current working folder to the parent folder of the existing build folder.
If you are using the code generation report and want to reload existing traceability information, see Reload Existing Traceability Information.