%% Convert DUT Subsystem to Model Reference for Testbenches with Continuous Blocks

% Copyright 2018 The MathWorks, Inc.

%% Guideline ID
% |1.2.2|

%% Severity
% _Strongly Recommended_

%% Description
% In some cases, parts of the Simulink(TM) testbench can contain Simscape(TM) 
% blocks or other blocks from the Simulink library that operate at a
% continuous sample time. To simulate these blocks, you must specify a continuous 
% solver setting for your model. The solver settings that you specify applies 
% to all blocks in your model. This means that the DUT Subsystem uses a
% continuous solver, which is not supported for HDL code generation. To generate HDL 
% code, convert the DUT Subsystem to a model reference, and then use a
% fixed-step discrete solver for the referenced model. As the parent model
% and the referenced model use different solver settings, you must convert the
% sample time by inserting Zero-Order Hold and Rate Transition blocks at the DUT boundary.
%
% *Note: To avoid issues such as reference model file confliction and longer
% code generation time, it is recommended that you avoid using a Subsystem 
% that is hierarchically below the top-level Subsystem as the DUT.* 
%
%%
% For example, open the model |hdlcoder_testbench_continuous.slx|. The
% model uses |ode45|, which is a continuous solver setting. 
% You see that the DUT is a model reference block. Zero-Order Hold and Rate
% Transition blocks at the boundary convert the sample time.
open_system('hdlcoder_testbench_continuous')
set_param('hdlcoder_testbench_continuous','SimulationCommand','Update')
get_param('hdlcoder_testbench_continuous', 'Solver')
%%
% To see the referenced model |hdlcoder_DUT_discrete|, double-click the |DUT| block. 
% You see that the DUT uses a discrete solver setting.
open_system('hdlcoder_testbench_continuous/DUT')
get_param('hdlcoder_DUT_discrete', 'Solver')