⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 make_mc9s12orig.m

📁 simulink real-time workshop for dragon12 development board from
💻 M
📖 第 1 页 / 共 4 页
字号:
        % RTW-EC hook
        %
        make_ecoder_hook('after_tlc',modelName);
        
        %
        % Generate HTML report if neccesary
        %
        
        rptContentsFile = rtwprivate('rtwattic', 'getContentsFileName');
        rptFileName     = rtwprivate('rtwattic', 'getReportFileName');
        if ~isempty(rptContentsFile)
            rtwprivate('rtwreport', 'convertC2HTML', rptContentsFile);
            rtwprivate('rtwshowhtml', rptFileName);
        end
        
        %
        % buildRes = { rtwFile, modules, noninlinedSFcns, listSFcns }
        %
        
        buildOpts = CreateBuildOpts(hModel,languageDir, systemTargetFilename, ...
            rtwroot, rtwVerbose, compilerEnvVal, ...
            buildRes,codeFormat);

        
        % -------- changed from here...
        %
        % (FW-03-05)
        % ... add non-inlined 'SFunctions' to 'rtw_filelist.mpf'
        
        % assemble list of (non-inlined) SFunctions within the model
        % note: there's a list of all SFunctions in buildOpts as well ...
        sfcns = '';
        for i=1:length(buildOpts.noninlinedSFcns)
            sfcns    = [sfcns, [buildOpts.noninlinedSFcns{i}, '.c ']];
        end
        if length(sfcns) > 0
            sfcns(end) = [];
        end

        % if there are any SFunctions -> append'em to 'rtw_filelist.mpf'
        if(~isempty(sfcns))
            % get path information
            sfcnPathArray = {};
            sfcns = unique({sfcns});
            for i=1:length(sfcns)
                [sfcnPath, sfcnName, sfcnExt] = fileparts(which(sfcns{i}));
                if ~isempty(sfcnPath)
                    sfcnPathArray = {sfcnPathArray{:}, sfcnPath};
                end
            end
            
            % Append list of fNames to the rtw_filelist.mpf file.
            current_path = pwd;
            fid = fopen([current_path, filesep, 'rtw_filelist.mpf'], 'a');
            for i=1:length(sfcns)
                fprintf(fid,'..%s..%s..%smc%s%s\n', filesep, filesep, filesep, filesep, sfcns{i});
            end
            fclose(fid);
        end
        
        % to here ---------------------
      
        %
        % This is the 'before_make' point of image building.
        % If makeRTWHookMFile is existing call it with Method equal 'before_make'.
        %
        if ~isempty(makeRTWHookMFile)
            makeRTWHookMethod='before_make';
            feval(makeRTWHookMFile,makeRTWHookMethod,modelName,rtwroot,...
                templateMakefile,buildOpts,buildArgs);
        end
        
        %
        % RTW-EC hook
        %
        make_ecoder_hook('before_make',modelName);
        
        feval(['rtw_',languageDir], ...
            modelName, rtwroot, templateMakefile, buildOpts, buildArgs);
        
        %
        % RTW-EC hook
        %
        make_ecoder_hook('after_make',modelName);
        
        %
        % This is the 'exit' point of make_rtw. If makeRTWHookMFile is
        % existing call it with Method equal 'exit'.
        %
        if ~isempty(makeRTWHookMFile)
            makeRTWHookMethod='exit';
            feval(makeRTWHookMFile, makeRTWHookMethod, modelName, rtwroot,...
                templateMakefile, buildOpts, buildArgs);
        else
            disp(['### Successful completion of Real-Time Workshop build ',...
                    'procedure for model: ', modelName]);
        end
        make_ecoder_hook('exit',modelName);
    end
catch
    % An error occured above, clean up and error out again, echoing the last
    % error
    CleanupForExit(startDirToRestore,hModel,origLockFlag,origDirtyFlag,...
        origStartTime,rtwCodeReuseSetting);
    error('%s', lasterr);
end

% Restore settings (locked and dirty flags, start time, and code reuse 
% feature) before exit and restore working directory.
CleanupForExit(startDirToRestore,hModel,origLockFlag,origDirtyFlag,...
    origStartTime,rtwCodeReuseSetting);


% -------- changed from here...
%
% (FW-11-02)

% change current path to back to what it was before...
cd(currdir);

% to here ---------------------


%endfunction make_rtw


%-----------------%
% Local functions %
%-----------------%

% Function: ConfigForTLC =======================================================
% Abstract:
%	Configure the
%          RTWGenSettings
%       and
%          RTWOptions
%       as well as other items needed for running TLC.
%
function [tlcArgs,gensettings,commonOptions,optionsTargetFile,...
        rtwVerbose,codeFormat] = ...
    ConfigForTLC(hModel, buildArgs, systemTargetFileId, ...
    systemTargetFileName, languageDir)

% Order of combines:
%   1) Common opts
%   2) System target file
%   3) RTWOptions parameter
% We do the first three in reverse order due to the way
% private/combinestruct.m works.  See comments in that file for more
% information.
%   4) RTWMakeCommand arguments for backwards compatibility

% Get options for all targets from commonoptions.m
commonOptions      = rtwcommonoptions;
commonOptionsArray = optarr_struct(commonOptions);

% Get code generation options from the existing system target file.
[optionsTargetFile, gensettings] = tfile_optarr(systemTargetFileId);
fclose(systemTargetFileId); % we don't need the target file any more


% For Tornado target or other STF that have CodeFormat as an RTW
% option, check RTW options for whether RealTime or
% RealTimeMalloc CodeFormat will be used, then set UsingMalloc flag in
% gensettings appropriately.
% Need this here when one STF is used for two CodeFormats since we
% need to propagate UsingMalloc flag to RTW gensettings for Simulink
% to be aware of it.
overloadCodeFormat = '';
if isfield(gensettings,'UsingMalloc') & ...
        strcmp(gensettings.UsingMalloc,'if_RealTimeMalloc')
    tmpoptions = get_param(hModel,'RTWOptions');
    if length(findstr(tmpoptions,'RealTimeMalloc')) > 0
        gensettings.UsingMalloc = 'yes';
        overloadCodeFormat = 'RealTimeMalloc';
    else
        gensettings.UsingMalloc = 'no';
    end
end

combinedOptions = combinestruct(commonOptions, optionsTargetFile, ...
    'tlcvariable');
if ~isempty(combinedOptions)
    options = borrow(combinedOptions, commonOptions, ...
        'tlcvariable', 'type');
    % Check to make sure that all fields have a non-empty 'type' field
    for k = 1:length(options)
        if (isfield(options(k), 'type'))
            if (isempty(options(k).type))
                error (['make_rtw: Field type empty for option ' ...
                        options(k).prompt]);
            end
        else
            error (['make_rtw: Field type undefined for option ' ...
                    options(k).prompt]);
        end
    end
    optionsArray = optarr_struct(options);
else
    options = [];
    optionsArray = [];
end

rtwOptions = get_param(hModel, 'RTWOptions');

if ~isempty(rtwOptions)
    rtwOptionsArray = optstr_struct(rtwOptions);
    rtwOptionsArray = stuff_array(optionsArray, rtwOptionsArray, ...
        {'name',   'name'}, ...
        {'value',  'value'}, ...
        {'enable', 'enable'});
else
    % This is a new model and we should put the
    % common options into it.
    rtwOptionsArray = optionsArray;
end

optionsArray = rtwOptionsArray;

%--------------------------------------------------------------------------%
% Get the TargetType (RT or NRT) and Language from the system target file  %
%     %assign TargetType  = "<RT | NRT>" 	  		               %
%     %assign Language    = "<lang>"                                       %
%--------------------------------------------------------------------------%

[tlcTargetType,tlcLanguage, codeFormat, ...
        maxStackSize, maxStackVariableSize, divideStackByRate] = ...
    LocGetOptionsFromTargetFile(systemTargetFileName, rtwOptionsArray);

% Tornado target overlaods CodeFormat (see 'if_RealTimeMalloc' above)
if ~strcmp(overloadCodeFormat,'')
    codeFormat = overloadCodeFormat;
end

gensettings.MaxStackSize         = num2str(maxStackSize);
gensettings.MaxStackVariableSize = num2str(maxStackVariableSize);
gensettings.DivideStackByRate    = num2str(divideStackByRate);

currentDirtyFlag = get_param(hModel,'Dirty');
set_param(hModel, 'RTWGenSettings',gensettings);
CleanupDirtyFlag(hModel,currentDirtyFlag)

%---------------------------------------%
% Get target type from specified solver %
%---------------------------------------%
modelName = get_param(hModel,'name');

targetType = LocMapSolverToTargetType(hModel, ...
    get_param(hModel,'Solver'), ...
    tlcTargetType);

if ~strcmp(tlcTargetType,targetType)
    if ~strcmp(tlcTargetType,'NRT')
        error('%s', ['The system target file is configured for ',tlcTargetType, ...
                ' whereas ', modelName, ' is configured for ',targetType]);
    end
end

language=languageDir;
language(1) = char(languageDir(1)-32);
if ~strcmp(tlcLanguage,language)
    error('%s', ['The system target file is configured for language ', ...
            tlcLanguage, ...
            ' whereas ', modelName, ' is configured for ', language]);
end

% Get RTWVerbose settings from the rtw options
%check optionsArray to see if RTWVerbose has been defined already
if (isval(optionsArray, 'name', 'RTWVerbose'))
    location = array_index(optionsArray, 'name', 'RTWVerbose');
    rtwVerbose = str2num(optionsArray(location).value);
else
    % If the user explicitly set this variable, then we set it above;
    % Else, we set it to the default (which is also the default in
    % commonsetup.ttlc)
    rtwVerbose = 1;
end


%-------------------%
% Setup TLC options %
%-------------------%

extraOptions = [];

opt.name = 'InlineParameters';
opt.value = strcmp(get_param(hModel,'RTWInlineParameters'),'on');
extraOptions = [extraOptions ' -a' opt.name '=' num2str(opt.value)];

extraOptions = fliplr(deblank(fliplr(deblank(extraOptions))));
extraOptionsArray = optstr_struct(extraOptions);
% Give precedence to options specified in dialog box or target file.
optionsArray = combinestruct(optionsArray, extraOptionsArray, 'name');

tlcArgsFromMakeArgs = LocMapMakeVarsToTLCVars(buildArgs);
tlcArgsFromMakeArgs = fliplr(deblank(fliplr(deblank(tlcArgsFromMakeArgs))));
tlcFromMakeArray = optstr_struct(tlcArgsFromMakeArgs);
optionsArray = combinestruct(tlcFromMakeArray, optionsArray, 'name');

systemTargetFileString = get_param(hModel,'RTWSystemTargetFile');
k = find(isspace(systemTargetFileString)==1);
if ~isempty(k)
    tlcArgs = systemTargetFileString(k(1):end);
else
    tlcArgs = [];
end

tlcArgs = [tlcArgs ' ' struct_optstr(optionsArray)];

% After all the arguments are parsed, set the consolidated InlineParameters
% flag and the RTWOptions string in the model via the set_param API. This is
% required to make TLC and rtwgen look at the same values for these
% attributes

idx = findstr(tlcArgs,'-aInlineParameters=1');
val = 'on';
if isempty(idx),
    val = 'off';
end
set_param(hModel, 'RTWInlineParameters', val);

currentDirtyFlag = get_param(hModel,'Dirty');
set_param(hModel, 'RTWOptions', tlcArgs);
CleanupDirtyFlag(hModel,currentDirtyFlag)

%endfunction: ConfigForTLC

% Function: CreateBuildOpts ====================================================
% Abstract:
%	Create the build options used when invoking rtw_c or rtw_ada
%
function buildOpts = CreateBuildOpts(hModel,languageDir,systemTargetFilename,...
    rtwroot,rtwVerbose, compilerEnvVal,...
    buildRes, codeFormat)

%-------------------------------------------------------------%
% Need to define RT_MALLOC on the compile line if the code    %
% format is RealTimeMalloc since grt_main.c and ode1-5.c      %
% conditionally compile depending on the memory allocation    %
% scheme.                                                     %
%-------------------------------------------------------------%
if strcmp(codeFormat, 'RealTimeMalloc')
    buildOpts.mem_alloc = 'RT_MALLOC';
else
    buildOpts.mem_alloc = 'RT_STATIC';
end

%------------------------------------------------------------------------%
% Get the following from the model.rtw file:                             %
%    solver     - can't use get_param because we can default to discrete %
%    solverType - same reason as above, either FixedStep of VariableStep %
%    solverMode - '0' or '1'                                             %
%    tid01eq    - '0' or '1'                                             %
%    ncstates   - number of continuous states                            %
%    numst      - number of sample times                                 %
%------------------------------------------------------------------------%

fid = fopen(buildRes.rtwFile,'r');
if fid == -1,
    error('%s', ['Unable to open ',buildRes.rtwFile]);
end

solver     = [];
solverType = [];
tid01eq    = [''];
solverMode = [];
ncstates   = [];
numst      = [];

while (1)
    line = fgetl(fid); if ~isstr(line), break; end
    
    if isempty(solver)
        if length(line) > 8 & all(line(1:8) == '  Solver')
            line(1:8) = [];
            solver = sscanf(line,'%s');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -