Creating and Using a Code Generation Report

Overview

The Real-Time Workshop Embedded Coder code generation report is an enhanced version of the HTML code generation report normally generated by the Real-Time Workshop build process. In the report,

In the Generated Source Files section of the Contents pane, you can click the names of source code files generated from your model to view their contents in a MATLAB Web browser window. In the displayed source code,

Generating an HTML Code Generation Report

To generate a Real-Time Workshop Embedded Coder code generation report,

  1. With your ERT-based model open, open the Configuration Parameters dialog box or Model Explorer and navigate to the Real-Time Workshop > Report pane.

  2. Select Create code generation report if it is not already selected. By default, Launch report automatically and Code-to-model also are selected, and Model-to-code is cleared, as shown in the figure below.

    You can select or clear any of these options as desired.

  3. Generate code from your model or subsystem (for example, for a model, by clicking Build on the Real-Time Workshop pane of the Configuration Parameters dialog box).

  4. The Real-Time Workshop build process writes the code generation report files in the html subdirectory of the build directory. The top-level HTML report file is named model_codegen_rpt.html or subsystem_codegen_rpt.html.

  5. If you selected Launch report automatically, the Real-Time Workshop build process automatically opens a MATLAB Web browser window and displays the code generation report.

    If you did not select Launch report automatically, you can open the code generation report (model_codegen_rpt.html or subsystem_codegen_rpt.html) manually into a MATLAB Web browser window, or into another Web browser.

  6. If you selected Code-to-model, hyperlinks to blocks in the generating model are created in the report files. When you view the report files in a MATLAB Web browser, clicking on these hyperlinks displays and highlights the referenced blocks in the model. For more information, see Using Code-to-Model Traceability.

  7. If you selected Model-to-code, model-to-code highlighting support is included in the generated HTML report. To highlight the generated code for a block in your Simulink model, right-click the block and select Real-Time Workshop > Navigate to Code. This selection highlights the generated code for the block in the HTML code generation report. For more information, see Using Model-to-Code Traceability and Using the Traceability Report to Completely Map Model Elements to Code.

Using Code-to-Model Traceability

To use Code-to-model,

  1. Open an ERT-based model and go to the Real-Time Workshop + Report pane of the Configuration Parameters dialog box. Select the option Create code generation report if it is not already selected. By default, Launch report automatically and Code-to-model also are selected.

  2. Build or generate code for your model. This will launch an HTML code generation report.

  3. In the HTML report window, click any of the hyperlinks present to highlight the source block. For example, in the HTML report shown below for the demo model rtwdemo_hyperlinks, you could click the first UnitDelay hyperlink in the generated code for the model step function.

    Clicking the UnitDelay hyperlink highlights the corresponding source block in the Simulink model window.

See also the demo rtwdemo_hyperlinks, which walks you through using Code-to-model .

Using Model-to-Code Traceability

To use Model-to-code,

  1. Open an ERT-based model and go to the Real-Time Workshop > Report pane of the Configuration Parameters dialog box. Select the options Create code generation report, Launch report automatically, and Model-to-code, if they are not already selected.

    Selecting Model-to-code enables the Configure button, which you can use to open the Model-to-code navigation dialog box; see Using the Model-to-Code Navigation Dialog Box to Load Existing Trace Information. Selecting Model-to-code also enables and selects content options for generating a Traceability Report, described in Using the Traceability Report to Completely Map Model Elements to Code.

  2. Build or generate code for your model. This launches an HTML code generation report.

  3. In the model window, right-click any block. In the right-click menu, select Real-Time Workshop > Navigate to Code.

    Selecting Navigate to Code highlights the generated code for the block in the HTML code generation report and takes you to the first instance. The total number of highlighted lines is displayed next to each source file name in the left panel of the HTML report. To navigate through multiple instances of highlighted lines, use the Previous and Next buttons.

    The report below shows the result of tracing the Unit Delay block in the demo model rtwdemo_hyperlinks.

See also the demo rtwdemo_hyperlinks, which walks you through using Model-to-code.

Using the Model-to-Code Navigation Dialog Box to Load Existing Trace Information

To open the Model-to-code navigation dialog box, click the Configure button on the Real-Time Workshop > Report pane of the Configuration Parameters dialog box. You can use this dialog box to reconnect your model with a previously-generated build directory, including trace information for model-to-code highlighting.

If you find that you cannot use right-click Real-Time Workshop > Navigate to Code to trace a block's code, because Navigate to Code is greyed out, it means that a build directory for your model cannot be found in the current working directory. To fix this without having to reset the current working directory or rebuild the model,

  1. Click the Configure button to launch the Model-to-code navigation dialog box.

  2. In the dialog box, click the Browse button, browse to the build directory for your model, and select the directory. The build directory path should be displayed in the Build directory field of the dialog box, as shown in the example above.

  3. Click Apply or OK. This loads trace information from the earlier build into your Simulink session, provided that you selected Model-to-code for the build.

  4. Now you can now successfully use right-click Real-Time Workshop > Navigate to Code to trace a block's code.

Using the Code Interface Report to Analyze the Generated Code Interface

Code Interface Report Overview

When you select the Create code generation report option for an ERT-based model, a Code Interface Report section is automatically included in the generated HTML report. The Code Interface Report section provides documentation of the generated code interface, including model entry point functions and interface data, for consumers of the generated code. The information in the report can help facilitate code review and code integration.

The code interface report includes the following subsections

For limitations that apply to code interface reports, see Code Interface Report Limitations

Generating a Code Interface Report

To generate a code interface report for your model, perform the following steps.

  1. Open your model, go to the Real-Time Workshop pane of the Configuration Parameters dialog box, and select ert.tlc or an ERT-based System target file, if one is not already selected.

  2. Go to the Real-Time Workshop > Report pane of the Configuration Parameters dialog box and select the option Create code generation report, if it is not already selected. The rtwdemo_basicsc, rtwdemo_mrmtbb, and rtwdemo_fcnprotoctrl demo models used in this section select every Report pane option by default, but selecting Create code generation report alone is sufficient to generate a Code Interface Report section in the HTML report.

    Alternatively, you can programmatically select the option by issuing the following MATLAB command:

    set_param(bdroot, 'GenerateReport', 'on')

    If the Report pane option Code-to-model is selected, the generated report will contain hyperlinks to the model. You should leave this value selected unless you plan to use the report outside the MATLAB environment.

  3. Build the model. If you selected the Report pane option Launch report automatically, the code generation report opens automatically after the build process completes. (Otherwise, you can launch it manually from within the model build directory.)

  4. To display the code interface report for your model, go to the Contents pane of the HTML report and click the Code Interface Report link. For example, here is the generated code interface report for the demo model rtwdemo_basicsc (with the ExportedGlobal Storage Class button selected in the demo model window).

For help navigating the content of the code interface report subsections, see Navigating Code Interface Report Subsections. For help interpreting the content of the code interface report subsections, see the sections beginning with Interpreting the Entry Point Functions Subsection.

Navigating Code Interface Report Subsections

To help you navigate code interface descriptions, the code interface report provides collapse/expand tokens and hyperlinks, as follows:

For general backward and forward navigation within the HTML code generation report, use the Back and Forward buttons above the Contents section in the upper left corner of the report.

Interpreting the Entry Point Functions Subsection

The Entry Point Functions subsection of the code interface report provides the following interface information about each model entry point function, including model_initialize, model_step, and (if applicable) model_terminate.

FieldDescription
Function:Lists the function name. You can click on the function name to go to its declaration in model.c.
PrototypeDisplays the function prototype, including the function return value, name, and arguments.
DescriptionProvides a text description of the function's purpose in the application.
TimingDescribes the timing characteristics of the function, such as how many times the function is called, or if it is called periodically, at what time interval. For a multirate timing example, see the rtwdemo_mrmtbb report excerpt below.
ArgumentsIf the function has arguments, displays the number, name, data type, and Simulink description for each argument. If you selected the Report pane option Code-to-model for your model, you can click the hyperlink in the description to go to the block corresponding to the argument in the model display. For argument examples, see the rtwdemo_fcnprotoctrl report excerpt below.
Return valueIf the function has a return value, displays the return value data type and Simulink description. If you selected the Report pane option Code-to-model for your model, you can click the hyperlink in the description to go to the block corresponding to the return value in the model display. For a return value example, see the rtwdemo_fcnprotoctrl report excerpt below.
Header fileLists the name of the header file for the function. You can click on the header file name to go to the header file source listing.

For example, here is the Entry Point Functions subsection for the demo model rtwdemo_basicsc.

To illustrate how timing information might be listed for a multirate model, here are the Entry Point Functions and Inports subsections for the demo model rtwdemo_mrmtbb. This multirate, discrete-time, multitasking model contains Inport blocks 1 and 2, which specify 1-second and 2-second sample times, respectively. The sample times are constrained to the specified times by the Periodic sample time constraint option on the Solver pane of the Configuration Parameters dialog box.

To illustrate how function arguments and return values are displayed in the report, here is the Entry Point Functions description of the model step function for the demo model rtwdemo_fcnprotoctrl.

Interpreting the Inports and Outports Subsections

The Inports and Outports subsections of the code interface report provide the following interface information about each inport and outport in the model.

FieldDescription
Block NameDisplays the Simulink block name of the inport or outport. If you selected the Report pane option Code-to-model for your model, you can click on each inport or outport Block Name value to go to its location in the model display.
Code Identifier

Lists the identifier associated with the inport or outport data in the generated code, as follows:

  • If the data is defined in the generated code, the field displays the identifier string.

  • If the data is declared but not defined in the generated code — for example, if the data is resolved with an imported storage class — the field displays the identifier string prefixed with the label 'Imported data:'.

  • If the data is neither defined nor declared in the generated code — for example, if the option Generate reusable code is selected for the model — the field displays the string 'Defined externally'.

Data TypeLists the data type of the inport or outport.
DimensionLists the dimensions of the inport or outport (for example, 1 or [4, 5]).

For example, here are the Inports and Outports subsections for the demo model rtwdemo_basicsc.

Interpreting the Interface Parameters Subsection

The Interface Parameters subsection of the code interface report provides the following interface information about tunable parameters that are associated with the model.

FieldDescription
Parameter Source

Lists the source of the parameter value, as follows:

  • If the source of the parameter value is a block, the field displays the block name, such as <Root>/Gain2 or <S1>/Lookup1. If you selected the Report pane option Code-to-model for your model, you can click on the Parameter Source value to go to the parameter's location in the model display.

  • If the source of the parameter value is a workspace variable, the field displays the name of the workspace variable prefixed with the label 'Workspace variable:'; for example, Workspace variable: K2.

Code Identifier

Lists the identifier associated with the tunable parameter data in the generated code, as follows:

  • If the data is defined in the generated code, the field displays the identifier string.

  • If the data is declared but not defined in the generated code — for example, if the data is resolved with an imported storage class — the field displays the identifier string prefixed with the label 'Imported data:'.

  • If the data is neither defined nor declared in the generated code — for example, if the option Generate reusable code is selected for the model — the field displays the string 'Defined externally'.

Data TypeLists the data type of the tunable parameter.
DimensionLists the dimensions of the tunable parameter (for example, 1 or [4, 5, 6]).

For example, here is the Interface Parameters subsection for the demo model rtwdemo_basicsc (with the ExportedGlobal Storage Class button selected in the demo model window).

Interpreting the Data Stores Subsection

The Data Stores subsection of the code interface report provides the following interface information about global data stores and data stores with non-auto storage that are associated with the model.

FieldDescription
Data Store Source

Lists the source of the data store memory, as follows:

  • If the data store is defined using a Data Store Memory block, the field displays the block name, such as <Root>/DS1. If you selected the Report pane option Code-to-model for your model, you can click on the Data Store Source value to go to the data store's location in the model display.

  • If the data store is defined using a Simulink.Signal object, the field displays the name of the Simulink.Signal object prefixed with the label 'Global:'.

Code Identifier

Lists the identifier associated with the data store data in the generated code, as follows:

  • If the data is defined in the generated code, the field displays the identifier string.

  • If the data is declared but not defined in the generated code — for example, if the data is resolved with an imported storage class — the field displays the identifier string prefixed with the label 'Imported data:'.

  • If the data is neither defined nor declared in the generated code — for example, if the option Generate reusable code is selected for the model — the field displays the string 'Defined externally'.

Data TypeLists the data type of the data store.
DimensionLists the dimensions of the data store (for example, 1 or [1, 2]).

For example, here is the Data Stores subsection for the demo model rtwdemo_basicsc (with the ExportedGlobal Storage Class button selected in the demo model window).

Using the Traceability Report to Completely Map Model Elements to Code

When you select the Model-to-code traceability option discussed in Using Model-to-Code Traceability, the generated HTML report includes a Traceability Report section. The content of the generated traceability report is determined by your selections among the following options on the Real-Time Workshop > Report pane of the Configuration Parameters dialog box.

The traceability report allows you to account for Eliminated / virtual blocks that are untraceable, versus the listed Traceable Simulink blocks, Traceable Stateflow objects, and Traceable Embedded MATLAB functions, providing a complete mapping between model elements and code.

The display below shows the beginning of the traceability report generated by selecting all four traceability content options for the demo model rtwdemo_hyperlinks.

For the full report, see the demo rtwdemo_hyperlinks, which walks you through using the traceability report, and be sure to select all four traceability content options.

HTML Code Generation Report Limitations

The following limitations apply to Real-Time Workshop Embedded Coder HTML code generation reports.

Traceability Limitations

Code Interface Report Limitations

  


 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS