Documentation

痕迹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.

  1. At the command prompt, typeold_sf_car.

  2. Select模拟>模型配置参数.

  3. In theCode Generation窗格,去Target selectionsection and enterert.tlcfor the system target file. ClickApply.

  4. Verify that you have selected these parameters on theCode Generation>Reportpane:

    • Create code generation report

    • Open report automatically

    • Code-to-model

    • Model-to-code

  5. 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.

  6. PressCtrl+B.

    After the code generation process is complete, the code generation report appears.

  7. In the report, on the left navigation pane, click theold_sf_car.chyperlink.

  8. 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.

  9. 单击行号上的超链接190. The corresponding element is highlighted.

Bidirectional Traceability for States and Transitions

  1. At the command prompt, typeold_sf_car.

  2. Select模拟>模型配置参数.

  3. In theCode Generation窗格,去Target selectionsection and enterert.tlcfor the system target file. ClickApply. Traceability comments appear in generated code only for embedded real-time targets.

  4. Verify that you have selected these parameters on theCode Generation>Reportpane:

    • Create code generation report

    • Open report automatically

    • Code-to-model

    • Model-to-code

  5. Code Generation>注释窗格并选择Stateflow object comments. This parameter enables the traceability comments for Statefloww elements.

  6. 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.

  7. PressCtrl+Bto generate source code and header files for theold_sf_carmodel that contains theshift_logicchart. After the code generation process is complete, the code generation report appears.

  8. 在报告中,单击old_sf_car.chyperlink.

View Results

  1. 要查看可追溯性评论,请滚动浏览代码。这些行号可能与您的代码生成报告中出现的数字有所不同。

  2. Click the:2hyperlink in this traceability comment:

    /*在'gear_state':'期间:2' */

    相应的状态出现在图表中。

  3. Click the:12hyperlink in this traceability comment:

    /* Transition: ':12' */

    The corresponding transition appears highlighted in the chart. To remove highlighting from an element in the chart, selectDisplay>Remove Highlighting.

  4. You can also trace objects in the model to lines of generated code. In the chart, right-click the objectGear_stateand selectC/C++ Code>Navigate to C/C++ Code.

    The code for that state appears highlighted inold_sf_car.c.

  5. 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 inold_sf_car.c.

    不te

    For a list of the Stateflow elements in your model that are traceable, click the痕迹ability Reporthyperlink 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.

  1. At the command prompt, typesf_cdplayer_stt. This model is already configured for traceability. For more information on these configurations, see痕迹ability of Stateflow Objects in Generated Code(Stateflow).

  2. PressCtrl+Bto generate source code and header files for thesf_cdplayer_sttmodel. After the code generation process is complete, the code generation report appears.

  3. Click thesf_cdplayer_stt.chyperlink in the report.

  4. 要查看可追溯性评论,请滚动浏览代码。The line numbers shown can differ from the numbers that appear in your code generation report.

  5. Click the:58hyperlink in this traceability comment:

    /* Entry Internal 'ON': ':58' */

    The corresponding state'ON'appears highlighted in the state transition table.

  6. Right-click the highlighted state and select查看状态对象. The state'ON'also appears highlighted in the underlying state transition diagram.

  7. 您可以跟踪状态或从状态过渡表到生成的代码的过渡。右键单击该州Standbyand selectC/C++ Code>Navigate to C/C++ Code.

    The entry code for the stateStandbyis highlighted in the generated code.

Bidirectional Traceability for Truth Table Blocks

  1. At the command prompt, typesf_climate_control

  2. 完成步骤2至6Bidirectional Traceability for States and Transitions.

  3. To build the model, pressCtrl+B.

  4. In the code generation report, click thesf_climate_control.chyperlink.

  5. 要查看可追溯性评论,请滚动浏览代码。These line numbers can differ from the numbers that appear in your code.

  6. Click the:1:47hyperlink in this traceability comment:

    /* Action '3': ':1:47' */

    In the Truth Table Editor, row 3 of the Action Table appears highlighted.

  7. 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 columnD2and selectC/C++ Code>Navigate to C/C++ Code.

    The code for that decision appears highlighted insf_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

  1. At the command prompt, typesf_clutch_enabled_subsystems.

  2. 完成步骤2至6Bidirectional Traceability for States and Transitions.

  3. In the Model Configuration Parameters dialog box, go to the求解器pane. In the求解器optionssection, selectFixed-stepin theTypefield. ClickApply. Before generating code, you must perform this step because the model does not work with variable-step solvers.

  4. To build the model, pressCtrl+B.

  5. In the code generation report, click thesf_clutch_enabled_subsystems.chyperlink.

  6. 要查看可追溯性评论,请滚动浏览代码。这些行号可能与您的代码生成报告中出现的数字有所不同。

  7. Click the:3hyperlink in this traceability comment:

    /* Graphical Function 'getSlipTorque': ':3' */

    In the chart, the graphical functiongetSlipTorqueappears highlighted.

  8. You can trace a graphical function in the chart to a line of generated code. For example, right-click the graphical functiondetectSlipand selectC/C++ Code>Navigate to C/C++ Code.

    The code for that graphical function appears highlighted insf_clutch_enabled_subsystems.c.

Code-to-Model Traceability for Events

  1. At the command prompt, typesf_security.

  2. 完成步骤2至6Bidirectional Traceability for States and Transitions.

  3. To build the model, pressCtrl+B.

  4. In the code generation report, click thesf_security.chyperlink.

  5. To see this traceability comment, scroll through the code. These numbers can differ from the numbers that appear in your code generation report.

  6. Click the:56hyperlink in this traceability comment:

    /* Event: ':56' */

    In theContentspane of the Model Explorer, the eventSoundappears highlighted.

Model-to-Code Traceability for Junctions

  1. At the command prompt, typesf_abs.

  2. 完成步骤2至6Bidirectional Traceability for States and Transitions.

  3. In the Model Configuration Parameters dialog box, go to the求解器pane. In the求解器optionssection, selectFixed-stepin theTypefield. ClickApply. Before generating code, you must perform this step because the model does not work with variable-step solvers.

  4. To build the model, pressCtrl+B.

  5. 在代码生成报告中,打开AbsoluteValuechart.

  6. 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 insf_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 theduringaction of the stateGear_state超链接:2.

Transition

Syntax

/* Transition: '' */

Example

/* Transition: ':12' */

This comment refers to a transition, which has the hyperlink:12.

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超链接:99.

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超链接:100.

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超链接:123.

金宝app功能

Syntax

/* 金宝appsimulink函数'<名称>':'' */

Example

/* 金宝appsimulink函数'simfcn':':10' */

This comment refers to a Simulink®function namedsimfcn超链接:10.

Event

Syntax

/* Event: '' */

Example

/* Event: ':33' */

This comment refers to an event, which has the hyperlink:33.

Was this topic helpful?