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

📄 make_mc9s12orig.m

📁 simulink real-time workshop for dragon12 development board from
💻 M
📖 第 1 页 / 共 4 页
字号:
        end
    end
    if isempty(solverType)
        if length(line) > 12 & all(line(1:12) == '  SolverType')
            line(1:12) = [];
            solverType = sscanf(line,'%s');
        end
    end
    if isempty(solverMode)
        if length(line) > 14 & all(line(1:14) == '    SolverMode')
            line(1:14) = [];
            solverMode = sscanf(line,'%s');
        end
    end
    [parsedLine,count] = sscanf(line,'%s%g%1s');
    if count == 2
        parsedLine = sscanf(line,'%s%s%1s');
        if isempty(tid01eq)
            if length(parsedLine) > 7 & all(parsedLine(1:7) == 'TID01EQ')
                parsedLine(1:7) = [];
                tid01eq = parsedLine;
            end
        end
        if isempty(ncstates)
            if length(parsedLine) > 13 & ...
                    all(parsedLine(1:13) == 'NumContStates')
                parsedLine(1:13) = [];
                ncstates = parsedLine;
            end
        end
        if length(parsedLine) > 14 & all(parsedLine(1:14)=='NumSampleTimes')
            parsedLine(1:14) = [];
            numst = parsedLine;
            break;
        end
    end
end
fclose(fid);

deleteRTWFile = strcmp(get_param(hModel,'RTWRetainRTWFile'),'off');
if deleteRTWFile && feature('RTWTesting') == 0
    delete(buildRes.rtwFile);
end

if isempty(numst)
    error('%s', ['NumSampleTimes undefined in ',buildRes.rtwFile]);
end

%----------------------------------------------%
% Invoke the language specific build procedure %
%----------------------------------------------%

% Since getstf.m may have returned a target file
% with a full path pre-pended to it, we must first strip out the
% directory information so that the sysTargetFile field in the
% buildOpts structure matches that in the template make file.
[filePath, systemTargetFilename, ext, tmp2] = ...
    fileparts(systemTargetFilename);
buildOpts.sysTargetFile    = [systemTargetFilename ext];
buildOpts.noninlinedSFcns  = buildRes.noninlinedSFcns;
buildOpts.solver           = solver;
buildOpts.solverType       = solverType;
buildOpts.solverMode       = solverMode;
buildOpts.tid01eq          = tid01eq;
buildOpts.ncstates         = ncstates;
buildOpts.numst            = numst;
buildOpts.modules          = buildRes.modules;
buildOpts.codeFormat       = codeFormat;
buildOpts.listSFcns        = buildRes.listSFcns;
buildOpts.generateCodeOnly = ...
    strcmp(get_param(hModel,'RTWGenerateCodeOnly'),'on');
buildOpts.RTWVerbose       = rtwVerbose;
buildOpts.compilerEnvVal   = compilerEnvVal;

%endfunction CreateBuildOpts

% Function: LocMapMakeVarsToTLCVars ============================================
%
function output = LocMapMakeVarsToTLCVars(makeString)
% LocMapMakeVarsToTLCVars - Add options for TLC based on make (build) arguments.

if LocalFindStr(makeString,'MSFCN=1')
    error('%s', ['The MSFCN=1 make option is no longer supported. ' ...
            'To call an M-file (or Fortran) S-function as a C-MEX ',...
            'S-function, ',...
            'create a sfunction_name.tlc file in the same directory as your ',...
            'S-function which contains (on the first line):',sprintf('\n'),...
            '  %% CallAsCMexLevel1',sprintf('\n'),...
            'or',sprintf('\n'),...
            '  %% CallAsCMexLevel2',sprintf('\n'),...
            'and remove the MSFCN=1 make option']);
end

% For backwards compatibility, check for EXT_MODE=1 in the build arguments.
% If present, make sure we add ExtMode=1 for TLC.
map(1).makename = 'EXT_MODE';
map(1).makevalue = '1';
map(1).tlcname = 'ExtMode';
map(1).tlcvalue = '1';

% For backwards compatibility, check for MAT_FILE=1 in the build
% arguments. If present, tell TLC to add support for mat file logging.
map(2).makename = 'MAT_FILE';
map(2).makevalue = '1';
map(2).tlcname = 'MatFileLogging';
map(2).tlcvalue = '1';

% For backwards compatibility, check for STETHOSCOPE=1 in the build
% arguments. If present, tell TLC to add support for StethoScope.
map(3).makename = 'STETHOSCOPE';
map(3).makevalue = '1';
map(3).tlcname = 'StethoScope';
map(3).tlcvalue = '1';

output = [];
makeString = [' ', makeString];

for j = 1:length(map)
    token = [' ',map(j).makename '=' map(j).makevalue];
    if length(makeString) >= length(token)
        location = findstr(makeString, token);
    else
        location = [];
    end
    if (~isempty(location))
        output = [output ' -a' map(j).tlcname '=' map(j).tlcvalue];
    end
end

%endfunction LocMapMakeVarsToTLCVars


% Function: LocMapSolverToTargetType ===========================================
% Abstract:
%      Given the solver type (and tlcTargetType) determine the type of
%      target: RT or NRT.
%
function output = LocMapSolverToTargetType(hModel, solver, tlcTargetType)
switch (solver)
    case {'FixedStepDiscrete', 'ode1', 'ode2', 'ode3', 'ode4', 'ode5'}
        
        output = 'RT';
        
    case {'VariableStepDiscrete', 'ode45', 'ode23', 'ode113', 'ode15s', ...
                'ode23s', 'ode23t', 'ode23tb'}
        
        output = 'NRT';
        if strcmp(tlcTargetType,'RT')
            
            modelName = get_param(hModel,'name');
            
            errmsg =sprintf(['The specified Real-Time Workshop target cannot be used ' ...
                    'with a variable-step solver. You must configure ',...
                    'the solver options for a fixed-step solver with ' ...
                    'an appropriate integration algorithm (press Open).']);
            
            cmdTxt = sprintf( ...
                ['set_param(''%s'',''SimParamPage'',''Solver''),' ...
                    'set_param(''%s'',''SimulationCommand'',''SimParamDialog'')'], ...
                modelName, modelName);
            
            slsfnagctlr('Clear', modelName, 'RTW Builder');
            
            nag                = slsfnagctlr('NagTemplate');
            nag.type           = 'Error';
            nag.msg.details    = errmsg;
            nag.msg.type       = 'Build';
            nag.msg.summary    = errmsg;
            nag.component      = 'RTW';
            nag.sourceName     = modelName;
            nag.sourceFullName = modelName;
            nag.openFcn        = cmdTxt;
            
            slsfnagctlr('Push', nag);
            slsfnagctlr('View');
            
        end
    otherwise
        error(['make_rtw.m: Unhandled solver ',solver]);
end
%endfunction LocMapSolverToTargetType


% Function: LocGetOptionsFromTargetFile ========================================
% Abstract:
%    Using the TLC server, query values from the system target file.
%
function [tlcTargetType, tlcLanguage, codeFormat, ...
        maxStackSize, maxStackVariableSize, divideStackByRate] = ...
    LocGetOptionsFromTargetFile(systemTargetFileName, optionsArray)

tlcH = tlc('new');
try
    for i=1:length(optionsArray)
        tlc('execstring', tlcH, ['%assign ', optionsArray(i).name, ...
                '=', optionsArray(i).value]);
    end
catch
    error('Loading system targetfile options: %s', lasterr);
end
fid = fopen(systemTargetFileName);
if fid == -1
    error('Unable to open system target file ''%s''', systemTargetFileName);
end
fstring = char(fread(fid))';
fclose(fid);
try
    tlc('execstring', tlcH, fstring);
catch
    lasterr('');
end
try
    tlcTargetType = tlc('query', tlcH, 'TargetType');
catch
    tlc('close', tlcH);
    error('%s', ['TargetType not specified in ', systemTargetFileName]);
end
try
    tlcLanguage = tlc('query', tlcH, 'Language');
catch
    tlc('close', tlcH);
    error('%s', ['Language not specified in ', systemTargetFileName]);
end

% Load CodeFormat. Note, S-Function CodeFormat is changed to
% Accelerator_S-Function if generating an Accelerator S-function.
try
    codeFormat = tlc('query', tlcH, 'CodeFormat');
    if strcmp(codeFormat,'S-Function')
        try
            accelerator = tlc('query', tlcH, 'Accelerator');
        catch
            accelerator = 0;
            lasterr('');
        end
        if accelerator
            % Convert code format from S-Function to Accelerator_S-Function
            % if this is the S-function form of the accelerator target
            codeFormat = 'Accelerator_S-Function';
        end
    end
catch
    codeFormat = 'RealTime'; % default if not specified.
    lasterr('');
end

if any(findstr(fstring, 'MaxStackSize'))
    try
        maxStackSize = tlc('query', tlcH, 'MaxStackSize');
    catch
        if any(findstr(fstring, '%assign MaxStackSize = '))
            warnStatus = [warning; warning('query','backtrace')];
            warning off backtrace;
            warning on;
            warning(['Unable to determine maximum stack size in ', ...
                    'system target file ''%s''. The maximum ', ...
                    'stack size will be assigned to inf. '], ...
                systemTargetFileName);
            warning(warnStatus);
        end
        lasterr('');
        maxStackSize = inf;
    end
else
    maxStackSize = inf;
end

if any(findstr(fstring, 'MaxStackVariableSize'))
    try
        maxStackVariableSize = tlc('query', tlcH, 'MaxStackVariableSize');
    catch
        if any(findstr(fstring, '%assign MaxStackVariableSize'))
            warnStatus = [warning; warning('query','backtrace')];
            warning off backtrace;
            warning on;
            warning(['Unable to determin maximum stack variable size in ', ...
                    'system target file ''%s''. The maximum ', ...
                    'stack variable size will be assigned to inf. '], ...
                systemTargetFileName);
            warning(warnStatus);
        end
        lasterr('');
        maxStackVariableSize = inf;
    end
else
    maxStackVariableSize = inf;
end

if any(findstr(fstring, 'DivideStackByRate'))
    try
        divideStackByRate = tlc('query', tlcH, 'DivideStackByRate');
    catch
        if any(findstr(fstring, '%assign DivideStackByRate'))
            warnStatus = [warning; warning('query','backtrace')];
            warning off backtrace;
            warning on;
            warning(['Unable to determin DivideStackByRate option in ', ...
                    'system target file ''%s''. The default value TLC_FALSE ', ...
                    'will be used for DivideStackByRate. ']);
            warning(warnStatus);
        end
        lasterr('');
        divideStackByRate = 0;
    end
else
    divideStackByRate = 0;
end

tlc('close', tlcH);

if ~any(strcmp(tlcTargetType,{'RT','NRT'}))
    error('%s', ['TargetType defined in ', systemTargetFileName, ...
            ' must be RT or NRT']);
end

%endfunction LocGetOptionsFromTargetFile


% Function: LocInternalMathWorksDevelopment ====================================
% Abstract:
%	See if BuildTTLCDir was specified, if so update rtw root.
%
function [rtwRoot] = LocInternalMathWorksDevelopment(rtwroot)
global BuildTTLCDir;
if ~isempty(BuildTTLCDir)
    savedir = pwd;
    ttlc = fullfile(matlabroot,'rtw','ttlc','scripts');
    if exist(ttlc,'dir')
        disp(['make_rtw.m: BuildTTLCDir global variable defined, invoking ',...
                'conversion script']);
        chdir(ttlc);
        [s,r]=dos('run');
        if ~strcmp(r,'gmake: Nothing to be done for `once''.')
            disp(r);
        end
        chdir(savedir);
    end
end


% Use development sandbox, if TMW_V5_SANDBOX environmental variable is set,
% and the directories rtw, simulink/include and extern/include in the sandbox
% exist. Otherwise use matlabroot.
tmwV5Sandbox = getenv('TMW_V5_SANDBOX');
if ~isempty(tmwV5Sandbox) & ...
        exist(fullfile(tmwV5Sandbox,'rtw'))==7 & ...
        exist(fullfile(tmwV5Sandbox,'simulink', 'include'))==7 & ...
        exist(fullfile(tmwV5Sandbox,'extern', 'include'))==7 ...
        rtwRoot = fullfile(tmwV5Sandbox,'rtw');
    disp(['### Using rtwroot = ',rtwRoot]);
else
    rtwRoot = rtwroot; % did this to quiet "unassigned output" warning by matlab
end

%endfunction LocInternalMathWorksDevelopment


% Function: LocRTWStuffArray ===================================================
%
function output = LocRTWStuffArray(varargin)
% LocRTWStuffArray - Copies the field values of one array to another array.

% The description of the original RTWStuffArray is:
%
%    RTWStuffArray(array1, array2, {primary_key, secondary_key}, ...
%                  {field1, field1a}, {field2, field2a}, ...)
%
% results in the following:
%
% All cases where array1(i).primary_key == array2(j).secondary_key,
%   array1(i).field1 <-- array2(j).field1a
%   array1(i).field2 <-- array2(j).field2a
%                     .
%                     .
%                     .
% Example:

⌨️ 快捷键说明

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