📄 make_mc9s12orig.m
字号:
function varargout = make_mc9S12(varargin)
% MAKE_RTW Executes the Real-Time Workshop Build procedure for a block diagram.
%
% MAKE_RTW first invokes the Target Language Compiler to generate the
% code and then invokes the language specific make procedure.
%
% Calls rtw_<target_language>, tlc_<target_language>
% Copyright 1994-2002 The MathWorks, Inc.
% $Revision: 1.136 $
%----------------------------------------------------------------------%
% Check for UNC directory on Windows or under MATLABROOT on all %
% platforms to avoid corrupting product or RTW project directories. %
% MATLABROOT/Work will be accepted on PC. %
%----------------------------------------------------------------------%
%
% modified to suite Dragon12 boards, fw-02-05
rtw_checkdir;
% -------- changed from here...
%
% (FW-11-02)
% ... read current work directory (from m68HC12.tmf) and ensure that
% we are working from there.
% locate template makefile
tmffile = which('mc9S12.tmf');
% load contents of template makefile
whd = fopen(tmffile, 'r');
tmf = fscanf(whd, '%c');
fclose(whd);
% % filter out USE_WORK_DIR specifier
% % ... begin
% useworktxtdefb = min(findstr(tmf,['USE_WORK_DIR']))+7;
%
% % ... end
% useworktxtdefe = useworktxtdefb + min(findstr(tmf(useworktxtdefb:end),[char(13) char(10)]));
%
% % ... adjust begin
% useworktxtdefb = useworktxtdefb + findstr(tmf(useworktxtdefb:useworktxtdefe), '-');
%
% % ... overread blanks
% while(tmf(useworktxtdefb) == ' ')
% useworktxtdefb = useworktxtdefb + 1;
% end
%
% % assign useworkdir variable
% useworkdir = tmf(useworktxtdefb:useworktxtdefb+1);
%
% if(useworkdir == 'y')
% filter out WORK_DIR_TXT specifier
% ... begin
worktxtdefb = min(findstr(tmf,['WORK_DIR_TXT']));
% ... end
worktxtdefe = worktxtdefb + min(findstr(tmf(worktxtdefb:end),[char(13) char(10)]))-2;
% ... adjust begin
worktxtdefb = worktxtdefb + findstr(tmf(worktxtdefb:worktxtdefe), '-');
% ... overread blanks
while(tmf(worktxtdefb) == ' ')
worktxtdefb = worktxtdefb + 1;
end
% assign workdir path variable
workdir = tmf(worktxtdefb:worktxtdefe);
currdir = pwd;
% not used anymore...
clear tmf;
% change current path to workdir
cd(workdir);
% else
%
% % compiling from wherever we are...
% currdir = pwd;
%
% % not used anymore...
% clear tmf;
%
% end
% perform consistency check
rtmc9S12_resource_check;
% to here ---------------------
%------------------------%
% General initialization %
%------------------------%
buildDir = '';
startDirToRestore = [];
%Error out if matlabroot contains whitespaces in the path
if (any(isspace(matlabroot)) ~= 0)
error(['The Real-Time Workshop requires that you install MATLAB ', ...
'in a folder that does not have any spaces in the name. ', ...
'This is because some of the third-party compiler make tools ', ...
'are unable to process rules that have white spaces. Please ',...
're-install MATLAB in a directory (folder) that does not '...
'have spaces in the name.']);
end
%Error out if matlabroot contains dollar signs ($) in the path
ispc = strncmp(computer,'PC',2);
if ispc & (findstr('$', matlabroot))
error(['The Real-Time Workshop requires that you install MATLAB in a ', ...
'folder that does not have any dollar signs ($) in the name. ', ...
'This is because windows treats file names with dollar signs ', ...
'differently and may result in unpredictable results. Please ',...
're-install MATLAB in a directory (folder) that does not '...
'have dollar signs in the name.']);
end
%---------------------------%
% Parse the build arguments %
%---------------------------%
buildArgs = '';
for i = 1:nargin
buildArgs = [buildArgs, varargin{i}, ' '];
end
if length(buildArgs) > 0
buildArgs(end) = [];
end
[modelName, initRTWOptsAndGenSettingsOnly, languageDir, ...
adaEnvVar, buildArgs] = ParseBuildArgs(buildArgs);
hModel = get_param(modelName,'handle');
%Cache the original dirty flag
origDirtyFlag = get_param(hModel,'Dirty');
% cache the original start time
origStartTime = get_param(hModel, 'StartTime');
% need to know where it's got called (from simprm, accel, or ssgenxxx, etc)
callerName = tdisplay_caller_info('');
% determine if we need to set the start time to be zero
resetToZero = 0;
% switch off RTWCodeReuse for the s-function target
rtwCodeReuseSetting = feature('RTWCodeReuse');
if any(findstr(get_param(hModel, 'RTWSystemTargetFile'), 'rtwsfcn.tlc'))
feature('RTWCodeReuse',0);
end
% accelerator mode simulation, need to set
if ~isempty(findstr(callerName, 'simprm')) & ...
( isempty(findstr(get_param(hModel, 'RTWSystemTargetFile'), ...
'rtwsfcn.tlc')) & ...
isempty(findstr(get_param(hModel, 'RTWSystemTargetFile'), ...
'rsim.tlc')) )
resetToZero = 1;
end
if str2num(origStartTime) ~= 0 & resetToZero == 1
buttonName = questdlg(...
['Start time must be zero for a real time system. ' ...
'Do you want Real-Time Workshop to generate code with start ' ...
'time zero? '], 'Build question', 'Yes', 'No', 'Yes');
switch buttonName
case 'Yes',
set_param(hModel, 'StartTime', '0');
disp([sprintf('\n'), '### Setting start time to zero.']);
case 'No',
% warn user
warnStatus = [warning; warning('query','backtrace')];
warning off backtrace;
warning on;
warning('Start time is not zero for this real time system.');
warning(warnStatus);
end
end
% cache the original lock and dirty flags
origLockFlag = get_param(hModel,'Lock');
if strcmp(origLockFlag, 'on'),
% need to unlock the model so that the set_params in the code below will
% work
set_param(hModel,'Lock','off');
end
%
% All the build procedure is wrapped in a try .. catch so that if any errors
% occur in this function or in any of the other functions called from here,
% they all fall through to the catch, where we restore the cached lock and
% dirty flags and re-echo the error that occured during try.
%
try
%----------------------------%
% Get the system target file %
%----------------------------%
[systemTargetFilename,systemTargetFileId] = getstf(hModel);
if (systemTargetFileId == -1)
if strcmp(systemTargetFilename,'ert.tlc') & ~ecoderinstalled(modelName)
error(['You must install Real-Time Workshop Embedded Coder ', ...
'to generate Embedded C code']);
else
error('%s', ['make_rtw: Unable to locate system target file: ', ...
systemTargetFilename]);
end
end
%----------------------------------------------------------------------%
% Load rtw hook m-file if it exists, run 'entry' rtw hook, %
% issue start build message %
%----------------------------------------------------------------------%
makeRTWHookMFile = rtw_hook_name(systemTargetFilename, 'make_rtw');
if ~initRTWOptsAndGenSettingsOnly
if ~isempty(makeRTWHookMFile)
makeRTWHookMethod='entry';
feval(makeRTWHookMFile,makeRTWHookMethod,modelName,[],[],[],buildArgs);
else
fprintf(1,['\n### Starting Real-Time Workshop build procedure for ', ...
'model: %s\n'],modelName);
end
end
[tlcArgs,...
gensettings,...
commonOptions,...
optionsTargetFile,...
rtwVerbose,...
codeFormat] = ConfigForTLC(hModel,buildArgs,systemTargetFileId, ...
systemTargetFilename, languageDir);
% -------- changed from here...
%
% (FW-03-05)
% ... define tlc variable 'Ode_Solver'
tlcArgs = [tlcArgs ' -aODE_Solver="' get_param(hModel,'Solver') '"'];
% to here ---------------------
if ~initRTWOptsAndGenSettingsOnly
% Continue with build configuration
if isfield(gensettings,'BuildDirSuffix')
buildDir = ['.',filesep,modelName,gensettings.BuildDirSuffix];
startDirToRestore = pwd;
rtwprivate('rtwattic','setBuildDir', ...
[pwd, filesep, modelName,gensettings.BuildDirSuffix]);
disp(['### Generating code into build directory: ',buildDir]);
else
error(['Unable to locate rtwgensettings.BuildDirSuffix '...
'within system target file']);
end
% Now handle build arguments from various source.
rtwBuildArgs = get_param(hModel, 'RTWBuildArgs');
combined = combinestruct(optionsTargetFile, commonOptions, ...
'makevariable');
tlcArgsArray = optstr_struct(tlcArgs);
% % -------- changed from here...
% %
% % (FW-10-02)
% % ... ensure consistent parameter settings (RTW / ext_comm)
%
% % determine parameter settings of the serial interface (COMx, baudrate)
% for(kk = 1:length(tlcArgsArray))
% if(strcmp(tlcArgsArray(kk).name, 'baudrate'))
% % baudrate parameter (14)
% baudrate = tlcArgsArray(kk).value;
% end
% if(strcmp(tlcArgsArray(kk).name, 'port'))
% % baudrate parameter (15)
% port = tlcArgsArray(kk).value;
% end
% end
%
%
% % ensure that communication parameters are set in 'ext_comm'
% ext_comm_str = [port(5) ',0,' baudrate];
% kk = get_param(hModel, 'ExtModeMexArgs');
% if(~strcmp(kk, ext_comm_str))
% set_param(hModel, 'ExtModeMexArgs', ext_comm_str);
% end
%
% % to here ---------------------
% Update the values in the combined makevariable array based on current
% TLC options set by tlcArgs.
combined = LocRTWStuffArray(combined, tlcArgsArray, ...
{'tlcvariable', 'name'}, ...
{'value', 'value', ''}, ...
{'default', 'value', 'LocMapFcn'});
% Convert the structure from an rtw option form to a 'build' struct array.
makeArgsArray = optarr_bldargarr(combined);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do not combine the buildargs specified in the main Real-Time Workshop
% options page and pass them as the last build arguments (the "user" build
% arguments). (The lines marked with # were removed).
% These will override the build arguments in the template make file
% anyways so there's really no need to include them here except to
% have the param 'RTWBuildArgs' accurately reflect what was actually
% built.
%
% Now, parse the build arguments passed in on the main Real-Time Workshop
% options page
%
% # buildArgsArray = bldargstr_struct(buildArgs);
%
% Combine the two, giving precedence to the arguments specified in the
% main Real-Time Workshop options page.
%
% # buildArgsArray = combinestruct(buildArgsArray, makeArgsArray, 'name');
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
currentDirtyFlag = get_param(hModel,'Dirty');
build_args = bldargarr_str(makeArgsArray);
set_param(hModel,'RTWBuildArgs',build_args);
CleanupDirtyFlag(hModel,currentDirtyFlag)
%-----------------------------------------------------------------------%
% Invoke the Target Language Compiler to generate the specific language %
%-----------------------------------------------------------------------%
rtwroot = fullfile(matlabroot, 'rtw');
[rtwroot] = LocInternalMathWorksDevelopment(rtwroot);
%
% Get the template makefile - this must be done before invoking tlc_c or
% tlc_ada because these files cd into the build directory
%
[templateMakefile,compilerEnvVal] = LocGetTMF(hModel,rtwroot,....
languageDir,adaEnvVar);
if (ispc)
system_dependent('ShowCommandWindow')
end
%
% This is the 'before_tlc' point of make_rtw. If makeRTWHookMFile is
% existing call it with Method equal 'before_tlc'.
%
if ~isempty(makeRTWHookMFile)
makeRTWHookMethod='before_tlc';
feval(makeRTWHookMFile,makeRTWHookMethod,modelName,rtwroot,[],[],...
buildArgs);
end
%
% RTW-EC hook
%
make_ecoder_hook('before_tlc',modelName);
buildRes = feval(['tlc_',languageDir], modelName, rtwroot, ...
systemTargetFilename, rtwVerbose, tlcArgs, buildDir,...
codeFormat);
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -