%% Generate Code Using Embedded Coder(R)
% This example shows how to select a system target file for a Simulink(R) model,
% configure model parameters, generate C code for embedded systems, and view
% generated files.
%
% The model represents an 8-bit counter that feeds a triggered subsystem
% that is parameterized by constant blocks |INC|, |LIMIT|, and |RESET|.  |Input| and
% |Output| represent I/O for the model. The |Amplifier| subsystem amplifies the
% input signal by gain factor |K|, which updates when signal |equal_to_count| is |true|.
%
% Copyright 2008-2019 The MathWorks, Inc.

%%
% *1.* Open the model.

model='rtwdemo_rtwecintro';
open_system(model)
   
%%
% *2.* Open the Model Configuration Parameters dialog box.
%
   
cs = getActiveConfigSet(model);
openDialog(cs);

%%
% *3.* Select the *Code Generation* tab.
%
% <<../rtw_codegen_pane_ert.png>>

%%
% *4.* To select a system target file, in the *Target Selection* pane, click *Browse* 
% You can generate code for a specific target environment or purpose.
% Some built-in targeting options are provided by system target files,
% which control the code generation process for a target environment.
%
% <<../rtw_browse_stf_button_ert.jpg>>
%
% <<../rtw_target_selection_ert.jpg>>

%%
% *5.* Select the *Embedded Real-Time (ERT)* system target file and click *Apply*.
%
% The ERT system target file supports a utility that you can use to specify 
% and prioritize code generation settings based on your application objectives.

%%
% *6.* In the *Code Generation Advisor* pane, click *Set Objectives*.
%
% You can set and prioritize objectives for the generated code.  For
% example, while code traceability might be a very important criterion 
% for your application, you might not want to prioritize it at the cost 
% of code execution efficiency.  
%
% <<../rtw_check_model_ert_nobuild.png>>

%%
% *7.* In the *Set Objectives* pane, select *Execution efficiency* and
% *Traceability*. Click *OK*.
%
% You can select and prioritize a combination of objectives before generating
% code.
%
% <<../rtw_objectives_selection_ert.jpg>>

%%
% *8.* In the model window, initiate code generation and the build process 
% for the model by using one of these options:
% 
% * Click the Build Model button.
% * Press *Ctrl+B*.
% * Invoke the |rtwbuild| command from the MATLAB command line.
% * Invoke the |slbuild| command from the MATLAB command line.

%%
% *9.* View the code generation report.
%
% The report includes |rtwdemo_rtwecintro.c|, associated utility and header
% files, and traceability and validation reports.
%
% <<../rtwecintro_report.png>>

%%
% This figure contains a portion of |rtwdemo_rtwecintro.c|
%
% <<../ag_rtwdemo_rtwecintro_ertstep.png>>

%%
% *10.* Close the model.

bdclose(model)
rtwdemoclean;

%% Related Topics
%
% * <docid:rtw_ug.bsuz9rn Configure Model, Generate Code, and Simulate>
% * <docid:rtw_ug.f1116557 Configure a System Target File>
% * <docid:rtw_ug#mw_1dca1113-5338-4700-81c4-24481c1b68d4 Generate Code and Simulate Models in a Simulink Project>
% * <docid:ecoder_ug#mw_e21123f9-11bb-4c8c-92ca-c6215e4f03d8 Generate Code and Simulate Models with Simulink Project API>