| Contents | Index |
| On this page… |
|---|
Considerations When Mapping Application Objectives Define High-Level Code Generation Objectives Determine Whether the Model is Configured for Specified 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:
What settings might help you debug your application?
What is the highest objective for your application — efficiency, traceability, extra safety precaution, debugging, or some other criteria?
What is the second highest objective?
Can the objective at the start of the project differ from the objective required for the end result? What tradeoffs can you make?
After you answer these questions:
Define your objectives in the configuration set. For more information, see Define High-Level Code Generation Objectives.
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.
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:
Execution efficiency — Configure code generation settings to achieve fast execution time.
ROM efficiency — Configure code generation settings to reduce ROM usage.
RAM efficiency — Configure code generation settings to reduce RAM usage.
Traceability — Configure code generation settings to provide mapping between model elements and code.
Safety precaution — Configure code generation settings to increase clarity, determinism, robustness, and verifiability of the code.
Debugging — Configure code generation settings to debug the code generation build process.
MISRA-C:2004 guidelines — Configure code generation settings to increase compliance with MISRA-C:2004 guidelines.
Note If you select the MISRA-C:2004 guidelines code generation objective, the Code Generation Advisor checks:
|
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.
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.
Tip You can use the Code Generation Advisor to review a model before generating code, or as part of the code generation process. When you choose to review a model before generating code, you specify which model, subsystem, or referenced model the Code Generation Advisor reviews (see Review the Model Without Generating Code). When you choose to review a model as part of the code generation process, the Code Generation Advisor reviews the entire system (see Review the Model During Code Generation). |
To specify code generation objectives in the Configuration Parameters dialog box:
Open the Configuration Parameters dialog box and select Code Generation.
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.
Click Set objectives. The Set Objectives - Code Generation Advisor dialog box opens.
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:
In Available objectives, double-click Execution efficiency. Execution efficiency is added to Selected objectives - prioritized.
In Available objectives, double-click Traceability. Traceability is added to Selected objectives - prioritized below Execution efficiency.

Click OK to accept the objectives. In the Configuration Parameters dialog box, Code Generation > General > Prioritized objectives is updated.
To specify code generation objectives by writing a MATLAB script or entering commands at the command line:
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');
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'});Caution When you specify a GRT-based system target file, you can specify any objective at the command line. If you specify ROM efficiency, RAM efficiency, Traceability, MISRA-C:2004 guidelines, or Safety precaution, the build process changes the objective to Unspecified because you have specified a value that is invalid when using a GRT-based target. |
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.
To review a model without generating code using the Code Generation Advisor:
Specify your code generation objectives.
In the Configuration Parameters > Code Generation > General pane, click Check model. The System Selector window opens.
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.
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.

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.
To review a model as part of the code generation process using the Code Generation Advisor:
Specify your code generation objectives.
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)
Select Generate code only if you only want to generate code; otherwise clear the check box to build an executable.
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.
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.
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.
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:
Creating a new objective and adding parameters and checks to a new objective.
Creating a new objective based on an existing objective, then adding, modifying and removing the parameters and checks within the new objective.
When you create a custom objective, you specify the values of configuration parameters that the Code Generation Advisor reviews using the following methods:
addParam — Add parameters and specify the values that the Code Generation Advisor reviews in Check model configuration settings against code generation objectives. When you add parameters that have dependencies, the software includes the dependencies in the list of parameter values that the Code Generation Advisor reviews.
modifyInheritedParam — Modify inherited parameter values that the Code Generation Advisor reviews in Check model configuration settings against code generation objectives.
removeInheritedParam — Remove inherited parameters from a new objective that is based on an existing objective. When a user selects multiple objectives, if another selected objective includes this parameter, the Code Generation Advisor reviews the parameter value in Check model configuration settings against code generation 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:
addCheck — Add checks to the Code Generation Advisor. When a user selects the custom objective, the Code Generation Advisor displays the check, unless the user specifies an additional objective with a higher priority that excludes the check.
For example, you might add a check to the Code Generation Advisor to include a custom check in the automatic model checking process.
excludeCheck — Exclude checks from the Code Generation Advisor. When a user selects multiple objectives, if the user specifies an additional objective that includes this check as a higher priority objective, the Code Generation Advisor displays this check.
For example, you might exclude a check from the Code Generation Advisor when a check takes a long time to process.
removeInheritedCheck — Remove inherited checks from a new objective that is based on an existing objective. When a user selects multiple objectives, if another selected objective includes this check, the Code Generation Advisor displays the check.
For example, you might remove an inherited check, rather than exclude the check, when the check takes a long time to process, but the check is important for another objective.
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:
Open the rtwdemo_rtwecintro model.
Specify an ERT-based target.
Specify the Execution efficiency objective.
Check the model.
The Code Generation Advisor displays in the right pane the list of checks in the Execution efficiency objective.

Caution The following objectives exclude the listed checks. For more information about excluding checks, see excludeCheck.
|
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:
Run Check model configuration settings against code generation objectives.
Click Modify Parameters.
Rerun the check.
The Code Generation Advisor displays in the check results the list of parameters and recommended values in the Execution efficiency objective.

To create a custom objective:
Create an sl_customization.m file.
Note
|
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:
Create a handle to the code generation objective, using the ObjectiveCustomizer constructor.
Register a callback function for the custom objectives, using the ObjectiveCustomizer.addCallbackObjFcn method.
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
Create a MATLAB callback function that:
Creates code generation objective objects using the rtw.codegenObjectives.Objective constructor.
Adds, modifies, and removes configuration parameters for each objective using the addParam, modifyInheritedParam, and removeInheritedParam methods.
Includes and excludes checks for each objective using the addCheck, excludeCheck, and removeInheritedCheck methods.
Registers objectives using the register method.
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
If you previously opened the Code Generation Advisor, close the model from which you opened the Code Generation Advisor.
Refresh the customization manager. At the MATLAB command line, enter the sl_refresh_customizations command.
Open your model and review the new objectives.
![]() | Configuration | Target | ![]() |

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 |