痕迹StateflowElements in Generated Code
To verify the generated code for your Stateflow®elements, you can trace Stateflow elements in your model to the code generation report by using these types of navigation:
Code-to-model: Trace generated code from the code generation report back to the model by clicking hyperlinks in the comments or the hyperlinked line numbers, which highlights the corresponding model element in the Simulink Editor.
Model-to-code: Trace the model elements in the Simulink Editor to corresponding lines in generated code by right-clicking the model element and navigating to the generated code.
These examples illustrate how to trace different Stateflow elements.
内联的可追溯性StateflowElements
Inline traceability refers to the line-level traceability available in the code generation report. You can click the hyper-linked line numbers to trace single or multiple Stateflow elements at the same time.
At the command prompt, type
old_sf_car
.Select模拟>模型配置参数.
In theCode Generation窗格,去Target selectionsection and enter
ert.tlc
for the system target file. ClickApply.Verify that you have selected these parameters on theCode Generation>Reportpane:
Create code generation report
Open report automatically
Code-to-model
Model-to-code
去Code Generation>Interfacepane. In theSoftware environmentsection, selectcontinuous time. ClickApply. Before generating code, you must perform this step because this model contains a block with a continuous sample time.
PressCtrl+B.
After the code generation process is complete, the code generation report appears.
In the report, on the left navigation pane, click the
old_sf_car.c
hyperlink.To the view the inline traceability hyperlinks, scroll through the code. These line numbers can differ from the numbers that appear in your code generation report.
单击行号上的超链接
190
. The corresponding element is highlighted.
Bidirectional Traceability for States and Transitions
At the command prompt, type
old_sf_car
.Select模拟>模型配置参数.
In theCode Generation窗格,去Target selectionsection and enter
ert.tlc
for the system target file. ClickApply. Traceability comments appear in generated code only for embedded real-time targets.Verify that you have selected these parameters on theCode Generation>Reportpane:
Create code generation report
Open report automatically
Code-to-model
Model-to-code
去Code Generation>注释窗格并选择Stateflow object comments. This parameter enables the traceability comments for Statefloww elements.
去Code Generation>Interfacepane. In theSoftware environmentsection, selectcontinuous time. ClickApply. Before generating code, you must perform this step because this model contains a block with a continuous sample time.
PressCtrl+Bto generate source code and header files for the
old_sf_car
model that contains theshift_logic
chart. After the code generation process is complete, the code generation report appears.在报告中,单击
old_sf_car.c
hyperlink.
View Results
要查看可追溯性评论,请滚动浏览代码。这些行号可能与您的代码生成报告中出现的数字有所不同。
Click the
hyperlink in this traceability comment::2 /*在'gear_state':'期间
:2 ' */相应的状态出现在图表中。
Click the
hyperlink in this traceability comment::12 /* Transition: '
:12 ' */The corresponding transition appears highlighted in the chart. To remove highlighting from an element in the chart, selectDisplay>Remove Highlighting.
You can also trace objects in the model to lines of generated code. In the chart, right-click the object
Gear_state
and selectC/C++ Code>Navigate to C/C++ Code.The code for that state appears highlighted in
old_sf_car.c
.In the chart, right-click the transition with the condition
[speed > up_th]
and selectC/C++ Code>Navigate to C/C++ Code.The code for that transition appears highlighted in
old_sf_car.c
.不te
For a list of the Stateflow elements in your model that are traceable, click the
痕迹ability Report
hyperlink in the code generation report.
Bidirectional Traceability for State Transition Tables
This example shows how to navigate bidirectionally between objects in a state transition table and the generated C/C++ and HDL code for traceability.
At the command prompt, type
sf_cdplayer_stt
. This model is already configured for traceability. For more information on these configurations, see痕迹ability of Stateflow Objects in Generated Code(Stateflow).PressCtrl+Bto generate source code and header files for the
sf_cdplayer_stt
model. After the code generation process is complete, the code generation report appears.Click the
sf_cdplayer_stt.c
hyperlink in the report.要查看可追溯性评论,请滚动浏览代码。The line numbers shown can differ from the numbers that appear in your code generation report.
Click the
hyperlink in this traceability comment::58 /* Entry Internal 'ON': '
:58 ' */The corresponding state
'ON'
appears highlighted in the state transition table.Right-click the highlighted state and select查看状态对象. The state
'ON'
also appears highlighted in the underlying state transition diagram.您可以跟踪状态或从状态过渡表到生成的代码的过渡。右键单击该州
Standby
and selectC/C++ Code>Navigate to C/C++ Code.The entry code for the state
Standby
is highlighted in the generated code.
Bidirectional Traceability for Truth Table Blocks
At the command prompt, type
sf_climate_control
完成步骤2至6Bidirectional Traceability for States and Transitions.
To build the model, pressCtrl+B.
In the code generation report, click the
sf_climate_control.c
hyperlink.要查看可追溯性评论,请滚动浏览代码。These line numbers can differ from the numbers that appear in your code.
Click the
hyperlink in this traceability comment::1:47 /* Action '3': '
:1:47 ' */In the Truth Table Editor, row 3 of the Action Table appears highlighted.
You can also trace a condition, decision, or action in the table to a line of generated code. For example, right-click a cell in the column
D2
and selectC/C++ Code>Navigate to C/C++ Code.The code for that decision appears highlighted in
sf_climate_control.c
.Tip
选择C/C++ Code>Navigate to C/C++ Codefor a condition, decision, or action, right-click a cell in the row or column that corresponds to that truth table element.
Bidirectional Traceability for Graphical Functions
At the command prompt, type
sf_clutch_enabled_subsystems
.完成步骤2至6Bidirectional Traceability for States and Transitions.
In the Model Configuration Parameters dialog box, go to the求解器pane. In the求解器optionssection, select
Fixed-step
in theTypefield. ClickApply. Before generating code, you must perform this step because the model does not work with variable-step solvers.To build the model, pressCtrl+B.
In the code generation report, click the
sf_clutch_enabled_subsystems.c
hyperlink.要查看可追溯性评论,请滚动浏览代码。这些行号可能与您的代码生成报告中出现的数字有所不同。
Click the
hyperlink in this traceability comment::3 /* Graphical Function 'getSlipTorque': '
:3 ' */In the chart, the graphical function
getSlipTorque
appears highlighted.You can trace a graphical function in the chart to a line of generated code. For example, right-click the graphical function
detectSlip
and selectC/C++ Code>Navigate to C/C++ Code.The code for that graphical function appears highlighted in
sf_clutch_enabled_subsystems.c
.
Code-to-Model Traceability for Events
At the command prompt, type
sf_security
.完成步骤2至6Bidirectional Traceability for States and Transitions.
To build the model, pressCtrl+B.
In the code generation report, click the
sf_security.c
hyperlink.To see this traceability comment, scroll through the code. These numbers can differ from the numbers that appear in your code generation report.
Click the
hyperlink in this traceability comment::56 /* Event: '
:56 ' */In theContentspane of the Model Explorer, the event
Sound
appears highlighted.
Model-to-Code Traceability for Junctions
At the command prompt, type
sf_abs
.完成步骤2至6Bidirectional Traceability for States and Transitions.
In the Model Configuration Parameters dialog box, go to the求解器pane. In the求解器optionssection, select
Fixed-step
in theTypefield. ClickApply. Before generating code, you must perform this step because the model does not work with variable-step solvers.To build the model, pressCtrl+B.
在代码生成报告中,打开
AbsoluteValue
chart.Right-click the left junction and selectC/C++ Code>Navigate to C/C++ Code.
The code for the first outgoing transition of that junction appears highlighted in
sf_abs.c
.
Format of Traceability Comments forStateflowObjects
The format of a traceability comment depends on the Stateflow object type.
State
Syntax
/*' ': ' ' */
Example
/*在'gear_state':'期间:2 ' */
This comment refers to theduring
action of the stateGear_state
超链接
.
Transition
Syntax
/* Transition: ' ' */
Example
/* Transition: ':12 ' */
This comment refers to a transition, which has the hyperlink
.
MATLAB功能
Syntax
/* MATLAB Function '': ' ' */
Within the inlined code for a MATLAB®function, comments that link to individual lines of the function have this syntax:
/* ' ' */
Examples
/* MATLAB Function 'test_function': ':99 ' */
/* ':99:20 ' */
The first comment refers to the MATLAB function namedtest_function
超链接
.
The second comment refers to line 20 of the MATLAB function in your chart.
Truth Table Block
Syntax
/* Truth Table Function '': ' ' */
Within the inlined code for a Truth Table block, comments for conditions, decisions, and actions have this syntax:
/* Condition '#': ' ' *//* Decision 'D ': ' ' *//* Action ' ': ' ' */
是真实表编辑器中出现的行或列号。
Examples
/* Truth Table Function 'truth_table_default': ':100 ' */
/* Condition '#1': ':100:8 ' *//* Decision 'D1': ':100:16 ' *//* Action '1': ':100:31 ' */
The first comment refers to a Truth Table block namedtruth_table_default
超链接
.
The other three comments refer to elements of that Truth Table block. Each condition, decision, and action in the Truth Table block has a unique hyperlink.
Truth Table Function
For syntax and examples, seeTruth Table Block.
Graphical Function
Syntax
/ *图形函数“<名称>”:“ ' */
Example
/* Graphical Function 'hello': ':123 ' */
This comment refers to a graphical function namedhello
超链接
.
金宝app功能
Syntax
/* 金宝appsimulink函数'<名称>':' ' */
Example
/* 金宝appsimulink函数'simfcn':':10 ' */
This comment refers to a Simulink®function namedsimfcn
超链接
.
Event
Syntax
/* Event: ' ' */
Example
/* Event: ':33 ' */
This comment refers to an event, which has the hyperlink
.