function hdlsetup(model)
% HDLSETUP(MODEL) Set Simulink model parameters for HDL code generation.
%
% hdlsetup('model') changes the parameters of the Simulink model
% specified by the 'model' argument to values that are commonly used for
% HDL code generation. The specified model should be open in Simulink
% before you invoke the hdlsetup command. The hdlsetup command uses the
% Simulink set_param function to set up models for HDL code generation
% quickly and consistently. The model parameters settings provided by
% hdlsetup are intended as useful defaults, but they may not be
% appropriate for all your applications.
%
% See also CHECKHDL, MAKEHDL, MAKEHDLTB.

% Copyright 2005-2020 The MathWorks, Inc.

if nargin < 1
error(message('hdlcommon:hdlcommon:hdldeprecation'));
end

model = convertStringsToChars(model);

if ~ischar(model)
warning(message('hdlcommon:hdlcommon:hdlsetup'));
return
end

% Get the configuration settings that are compatiable for HDL code generation
paramStruct = hdlcoder.ModelChecker.hdlModelParameters;

% Appending 'SampleTimeColors' model configuration parameters to hdlsetup
% param struct. This will be helpful for better visualization.
paramStruct.SampleTimeColors = 'on';

fields = fieldnames(paramStruct);
modelParams = {};
flag = false;

% parameters that are not visible under configuration parameters
hiddenParams = {'SampleTimeColors', 'ShowLineDimensions', ...
'ShowPortDataTypes', 'DataTypeOverride'};

% Find incorrectly set model parameters compatiable to HDL workflow by
% comparing the parameter value with the value compatiable to HDL workflow.
% If the value is not matched, then set the parameter to suitable value and
% emitting warning message.
for i = 1:numel(fields)
fieldName = fields{i};
modelParams{i} = get_param(model, fieldName); %#ok<AGROW>
if isempty(strfind(paramStruct.(fieldName), modelParams{i}))
% generating the command line message only for parameters present
% under model configuration parameters.
if ~contains(fieldName, hiddenParams)
flag = true;
hdldisp(message('HDLShared:hdlshared:HDLSetupConfigParamUpdateLog',...
model, fieldName, modelParams{i}, paramStruct.(fieldName)));
end
set_param(model, fieldName, paramStruct.(fieldName));
end
end

% providing link to help document
if flag
hdldisp(message('HDLShared:hdlshared:HDLSetupFinishMsgWithFailure'));
else
hdldisp(message('HDLShared:hdlshared:HDLSetupFinishMsgWithSuccess'));
end

% Attach HDL Coder specific settings and implementation bindings to this
% model
attachhdlcconfig(model);

% LocalWords: hdldeprecation fixedstepdiscrete