% Copyright (c) 2016 Freescale Semiconductor, Inc.
% All rights reserved.
function mbd_pnt_make_rtw(varargin)
% workaround for rtwmakecfg.m search path issue
path(strcat(mbd_find_pnt_root, '\mbdtbx_pnt\MCLIB_pnt\bam'), path);
%
slsfnagctlr('Clear', gcs, 'RTW Builder');
set_param(gcs, 'SimulationCommand', 'update');
model = mbd_pnt_get_cur_model();
try
p = inputParser;
p.KeepUnmatched = true;
p.StructExpand = true;
addParameter(p, 'TopOfBuildModel', model);
parse(p, varargin{1});
topModel = p.Results.TopOfBuildModel;
catch ME
% If somehow the parse method fails, we consider the current
% model to be the top model.
topModel = model;
mbd_pnt_dprint(ME);
end
set_param(model, 'GenerateSampleERTMain', 'off');
try
save_system(model);
set_param(model, 'GenerateMakefile', 'on');
set_param(model, 'PostCodeGenCommand', 'mbd_pnt_analyzegencode(buildInfo)');
catch ME
mbd_pnt_dprint(ME);
end
env_err = 0;
compiler = get_param(model, 'target_compiler');
install_doc = [mbd_find_pnt_root, filesep, 'help', filesep, 'Motor_Control_Toolbox_Installation_Quick_Start.pdf'];
if strcmp(get_param(model,'GenCodeOnly'), 'off')
configBlocks = find_system(model, 'Regexp','on', 'LookUnderMasks','on', 'MaskType','MBDTBX_EC_PNT');
if ~isempty(configBlocks)
configBlocks = configBlocks{1};
else
configBlocks = model;
end
if strcmp(compiler, 'CodeWarrior')
if isempty(getenv('MW_TOOL')) && isempty(getenv('CW_TOOL'))
errorMsg = ['Environment Variables MW_TOOL or CW_TOOL not set. Please refer to ''Setting up the Target Compilers'' in Model Based Design Toolbox Installation Quick Start.pdf in the help folder'];
mbd_pnt_nag_error(configBlocks, errorMsg);
env_err = 1;
end
elseif strcmp(compiler, 'DIAB')
if isempty(getenv('DIAB_TOOL'))
errorMsg = ['Environment Variable DIAB_TOOL not set. Please refer to ''Setting up the Target Compilers'' in Model Based Design Toolbox Installation Quick Start.pdf in the help folder'];
mbd_pnt_nag_error(configBlocks, errorMsg);
env_err = 1;
end
elseif strcmp(compiler, 'S32 Design Studio')
if isempty(getenv('S32DS_PA_TOOL'))
errorMsg = ['Environment Variable S32DS_PA_TOOL not set. Please refer to ''Setting up the Target Compilers'' in Model Based Design Toolbox Installation Quick Start.pdf in the help folder'];
mbd_pnt_nag_error(configBlocks, errorMsg);
env_err = 1;
end
elseif strcmp(compiler, 'GreenHills Multi')
if isempty(getenv('GHS_TOOL'))
errorMsg = ['Environment Variable GHS_TOOL not set. Please refer to ''Setting up the Target Compilers'' in Model Based Design Toolbox Installation Quick Start.pdf in the help folder'];
mbd_pnt_nag_error(configBlocks, errorMsg);
env_err = 1;
end
end
end
errs = slsfnagctlr('GetNags', gcs);
toolbox_err = 0;
if ~isempty(errs)
for i = 1 : length(errs)
if strcmp(errs(i,1).type, 'error')
toolbox_err = toolbox_err+1;
end
end
end
if (env_err == 0) && (toolbox_err == 0)
try
make_rtw(varargin{:});
% Run the BAM download only for the top model, skip for
% the referenced models.
if strcmp(model, topModel)
mbd_pnt_bam('', 'BAM');
mbd_pnt_ds();
end
catch ME
mbd_pnt_dprint(ME);
end
else
slsfnagctlr('View');
end
end