Skip to Main Content Skip to Search
Product Documentation

Application Objectives

Considerations When Mapping Application Objectives

The first step in applying Embedded Coder configuration options to the application development process is to consider how your application objectives, particularly with respect to efficiency, traceability, and safety, map to code generation options in a model configuration set.

Parameters that you set in the Solver, Data Import/Export, Diagnostics, and Code Generation panes of the Configuration Parameters dialog box specify the behavior of a model in simulation and the code generated for the model.

Consider questions such as the following:

After you answer these questions:

  1. Define your objectives in the configuration set. For more information, see Define High-Level Code Generation Objectives.

  2. Use the Code Generation Advisor to identify parameter values that are not configured for the objectives that you selected. For more information, see Determine Whether the Model is Configured for Specified Objectives.

Define High-Level Code Generation Objectives

When you are considering the objectives for your application, there are many different criteria. The code generation software identifies seven high-level objectives that you might consider for your application:

Once you have identified which of these seven objectives are important for your application, you can use the Code Generation Advisor to identify the parameters that are not configured for the objectives that you selected. Review Recommended Settings Summary to see the settings the Code Generation Advisor recommends.

You can specify and prioritize any combination of the available objectives for the Code Generation Advisor to take into consideration. For more information, see Determine Whether the Model is Configured for Specified Objectives.

Determine Whether the Model is Configured for Specified Objectives

You can use the Code Generation Advisor to review your model and identify the parameters that are not configured for your objective. The Code Generation Advisor reviews a subset of model configuration parameters and displays the results in the Check model configuration settings against code generation objectives check.

The Code Generation Advisor uses the information presented in Mapping of Application Requirements to the Optimization Pane : General tab to determine the recommended values. When there is a conflict due to multiple objectives, the higher-priority objective takes precedence.

Specify Code Generation Objectives Using the GUI

To specify code generation objectives in the Configuration Parameters dialog box:

  1. Open the Configuration Parameters dialog box and select Code Generation.

  2. Specify a system target file. If you specify an ERT-based target, more objectives are available. For the purposes of this example, choose an ERT-based target such as ert.tlc.

  3. Click Set objectives. The Set Objectives - Code Generation Advisor dialog box opens.

  4. In the Set Objectives - Code Generation Advisor dialog box, specify your objectives. For example, if your objectives are execution efficiency and traceability, in that priority, do the following:

    1. In Available objectives, double-click Execution efficiency. Execution efficiency is added to Selected objectives - prioritized.

    2. In Available objectives, double-click Traceability. Traceability is added to Selected objectives - prioritized below Execution efficiency.

    3. Click OK to accept the objectives. In the Configuration Parameters dialog box, Code Generation > General > Prioritized objectives is updated.

Specify Code Generation Objectives at the Command Line

To specify code generation objectives by writing a MATLAB script or entering commands at the command line:

  1. Specify a system target file. If you specify an ERT-based target, more objectives are available. For the purposes of this example, specify ert.tlc, where model_name is the name or handle to the model.

    set_param(model_name, 'SystemTargetFile', 'ert.tlc');
  2. Specify your objectives. For example, if your objectives are execution efficiency and traceability, in that priority, enter:

    set_param(model_name, 'ObjectivePriorities',...
    {'Execution efficiency', 'Traceability'});

Review Objectives in Referenced Models

When you review a model during the code generation process, you must specify the same objectives in the top model and referenced models. If you specify different objectives for the top model and referenced model, the build process generates an error.

To specify different objectives for the top model and each referenced model, review the models separately without generating code.

Review the Model Without Generating Code

To review a model without generating code using the Code Generation Advisor:

  1. Specify your code generation objectives.

  2. In the Configuration Parameters > Code Generation > General pane, click Check model. The System Selector window opens.

  3. Select the model or subsystem that you want to review and click OK. The Code Generation Advisor opens and reviews the model or subsystem that you specified.

  4. In the Code Generation Advisor window, review the results by selecting a check from the left pane. The right pane populates the results for that check.

Review the Model During Code Generation

To review a model as part of the code generation process using the Code Generation Advisor:

  1. Specify your code generation objectives.

  2. In the Configuration Parameters > Code Generation > General pane, select one of the following from Check model before generating code:

    • On (proceed with warnings)

    • On (stop for warnings)

  3. Select Generate code only if you only want to generate code; otherwise clear the check box to build an executable.

  4. Apply your changes and then click Generate code/Build. The Code Generation Advisor starts and reviews the top model and subsystems.

    If the Code Generation Advisor issues any failures or warnings and you specified:

    • On (proceed with warnings) — The Code Generation Advisor window opens while the build process proceeds. You can review the results after the build process is complete.

    • On (stop for warnings) — The build process halts and displays the diagnostics viewer. To continue, you must review and resolve the Code Generation Advisor results or change the Check model before generating code selection.

  5. In the Code Generation Advisor window, review the results by selecting a check from the left pane. The right pane populates the results for that check.

  6. After reviewing the check results, you can choose to fix warnings and failures as described in Fixing a Warning or Failure in the Simulink User's Guide.

      Caution   When you specify an efficiency or safety precaution objective, the Code Generation Advisor includes additional checks. When you make changes to one of these checks, the other check results are no longer valid and you must run the check again.

Create Custom Objectives

The Code Generation Advisor reviews your model based on objectives that you specify. If the predefined efficiency, traceability, safety precaution, and debugging objectives do not meet your requirements, you can create custom objectives.

You can create custom objectives by:

Specify Parameters in Custom Objectives

When you create a custom objective, you specify the values of configuration parameters that the Code Generation Advisor reviews using the following methods:

Specify Checks in Custom Objectives

All objectives include the Check model configuration settings against code generation objectives check by default. When you create a custom objective, you specify the list of additional checks that are associated with the custom objective using the following methods:

Determine Checks and Parameters in Existing Objectives

When you base a new objective on an existing objective, you can determine what checks and parameters the existing objective contains. Select the existing objective and check the model. The Code Generation Advisor lists the checks and parameters associated with the existing objective.

The Code Generation Advisor contains the list of checks in each objective. For example, the Efficiency objective includes ten checks, which you can see in the Code Generation Advisor if you:

  1. Open the rtwdemo_rtwecintro model.

  2. Specify an ERT-based target.

  3. Specify the Execution efficiency objective.

  4. Check the model.

The Code Generation Advisor displays in the right pane the list of checks in the Execution efficiency objective.

The first check, Check model configuration settings against code generation objectives, lists all parameters and values specified by the objective. For example, the Code Generation Advisor displays the list of parameters and the recommended values in the Execution efficiency objective, if you:

  1. Run Check model configuration settings against code generation objectives.

  2. Click Modify Parameters.

  3. Rerun the check.

The Code Generation Advisor displays in the check results the list of parameters and recommended values in the Execution efficiency objective.

How to Create Custom Objectives

To create a custom objective:

  1. Create an sl_customization.m file.

      Note  

      • Specify all custom objectives in a single sl_customization.m file only, or the software generates an error. This holds true even if you have more than one sl_customization.m file on your MATLAB path.

      • Except for the matlabroot/work folder, do not place an sl_customization.m file in your root MATLAB folder, or any of its subfolders. Otherwise, the software ignores the customizations that the file specifies.

  2. Create an sl_customization function that takes a single argument. When the software invokes the function, the value of this argument is the Simulink customization manager. In the function:

    1. Create a handle to the code generation objective, using the ObjectiveCustomizer constructor.

    2. Register a callback function for the custom objectives, using the ObjectiveCustomizer.addCallbackObjFcn method.

    3. Add a call to execute the callback function, using the ObjectiveCustomizer.callbackFcn method.

    For example

    function sl_customization(cm)
    %SL_CUSTOMIZATION objective customization callback
    
    objCustomizer = cm.ObjectiveCustomizer;
    index = objCustomizer.addCallbackObjFcn(@addObjectives);
    objCustomizer.callbackFcn{index}();
    
    end
  3. Create a MATLAB callback function that:

    The following example shows you how to create an objective, Reduce RAM Example. Reduce RAM Example includes five parameters and three checks that the Code Generation Advisor reviews:

    function addObjectives
    
    % Create the custom objective
    obj = rtw.codegenObjectives.Objective('ex_ram_1');
    setObjectiveName(obj, 'Reduce RAM Example');
    
    % Add parameters to the objective
    addParam(obj, 'InlineParams', 'on');
    addParam(obj, 'BooleanDataType', 'on');
    addParam(obj, 'OptimizeBlockIOStorage', 'on');
    addParam(obj, 'EnhancedBackFolding', 'on');
    addParam(obj, 'BooleansAsBitfields', 'on');
    
    % Add additional checks to the objective
    % The Code Generation Advisor automatically includes 'Check model
    % configuration settings against code generation objectives' in every
    % objective.
    addCheck(obj, 'Identify unconnected lines, input ports, and output ports');
    addCheck(obj, 'Check model and local libraries for updates');
    
    %Register the objective
    register(obj);
    
    end

    The following example shows you how to create an objective, My Traceability Example, based on the existing Traceability objective. The custom objective modifies, removes, and adds parameters that the Code Generation Advisor reviews. It also adds and removes checks from the Code Generation Advisor:

    function addObjectives
    
    % Create the custom objective from an existing objective
    obj = rtw.codegenObjectives.Objective('ex_my_trace_1', 'Traceability');
    setObjectiveName(obj, 'My Traceability Example');
    
    % Modify parameters in the objective
    modifyInheritedParam(obj, 'GenerateTraceReportSf', 'Off');
    removeInheritedParam(obj, 'ConditionallyExecuteInputs');
    addParam(obj, 'MatFileLogging', 'On');
    
    % Modify checks in the objective
    addCheck(obj, 'Identify questionable software environment specifications');
    removeInheritedCheck(obj, 'Identify questionable code instrumentation (data I/O)');
    
    %Register the objective
    register(obj);
    
    end
  4. If you previously opened the Code Generation Advisor, close the model from which you opened the Code Generation Advisor.

  5. Refresh the customization manager. At the MATLAB command line, enter the sl_refresh_customizations command.

  6. Open your model and review the new objectives.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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