%% Generate Code Using Simulink(R) Coder(TM) 
% This example shows how to select a system target file for a Simulink(R) model,
% generate C code for real-time simulation, 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 model |rtwdemo_rtwintro| and save a copy to a writable
% location.

model='rtwdemo_rtwintro';
open_system(model)

%%
% 2. Open the *Simulink Coder* app.

%%
% 3. Open the Model Configuration Parameters dialog box. In the *C Code*
% tab, click *Settings*.  Alternatively, from the command line, enter:
%

cs = getActiveConfigSet(model);
openDialog(cs);

%%
% 4. Select the *Code Generation* tab.
%
% <<../rtw_main_page_grt.png>>

%%
% 5. In the *Target Selection* pane, click *Browse* to select a system target
% file.
% 
% You can generate code for a specific target computer environment or purpose.
% Some options are provided by built-in system target files,
% which control the code generation process for a target computer environment.
%
% <<../rtw_browse_stf_button_grt.png>>
%
% <<../rtw_target_selection_grt.png>>

%%
% 6. Select the *Generic Real-Time (GRT)* system target file and click *Apply*.
%
% Optionally, in the *Code Generation Advisor* pane set the parameter *Select
% objective* to *Execution efficiency* or *Debugging*.  Then, to identify 
% and systematically change parameters to meet your objectives, click
% *Check model...* 

%%
% 7. Generate code for the model by using one of these options:
% 
% * On the *C Code* tab, click *Build*.
% * Press *Ctrl+B*.
%
% <<../rtw_build_button_grt.png>>

%%
% 8. View the code generation report.
%
% The report includes links to model files such as |rtwdemo_rtwintro.c| and
% associated utility and header files.
%
% <<../rtwintro_report.png>>
%

%%
% This figure contains a portion of |rtwdemo_rtwintro.c|.
%
% <<../ag_rtwdemo_rtwintro_grtstep.png>>

%%
% 9. 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:ecoder_ug#bs_13dn Generate Code Using Embedded Coder>
% * <docid:rtw_ug#mw_1dca1113-5338-4700-81c4-24481c1b68d4 Generate Code and Simulate Models in a Simulink Project>
% * <docid:rtw_ug#mw_e21123f9-11bb-4c8c-92ca-c6215e4f03d8 Generate Code and Simulate Models with Simulink Project API>

