Highlights from
Embedded Coder Support Package for Green Hills MULTI IDE (R2012b)

image thumbnail

Embedded Coder Support Package for Green Hills MULTI IDE (R2012b)

by

 

Embedded Coder integration for creating models that run directly in Green Hills MULTI IDE

multilink_workflow_testbench_script
function multilink_workflow_testbench_script
%MULTILINK_WORKFLOW_TESTBENCH_SCRIPT tests the processor implementation of the
% multilinkcodegensumdiff algorithm used in codegen workflow demo.
%
% MULTILINK_WORKFLOW_TESTBENCH_SCRIPT:
%
%  1) creates two input test vectors
%  2) calculates expected results in MATLAB
%  3) does necessary MULTI setup
%  4) executes the algorithm on processor:
%       -- write input test vectors to processor's memory
%       -- run cpu to calculate actual results
%       -- read actual results from processor's memory
%  5) compares expected and actual results
%  6) prints the difference at MATLAB prompt
%

% Copyright 2007-2011 The MathWorks, Inc.


%********** Initial error checking ********************


systemName    = gcs;
exe_full_name = fullfile(pwd, [systemName '_ghsmulti'], systemName);
ideObjectName = get_param(systemName, 'ideObjName');

if strcmpi(get_param(systemName,'SystemTargetFile'),linkfoundation.util.getSTFName('grt'))
    fn_name = 'MdlOutputs';
elseif strcmpi(get_param(systemName,'SystemTargetFile'),linkfoundation.util.getSTFName('ert'))
    fn_name = [systemName '_step'];
else
    disp('The model is not configured for using IDE Link');
    clear exe_full_name;
    return;
end

if evalin ('base', ['exist(''', ideObjectName, ''', ''var'')']) && exist(exe_full_name, 'file')
    IDE_Obj = evalin('base', ideObjectName);
else
    disp('Please first generate the code from the demo model,');
    disp('then use this script to verify the final implementation.');
    clear exe_full_name fn_name;
    return;
end

try

    %********** Create two input test vectors ********************
    disp('#Creating test data.');
    invec1 = { int32(zeros(1,16)); int32(zeros(1,16)) };   
    invec2 = { int32(zeros(1,16)); int32(zeros(1,16)) }; 
    for i = 1:2
         invec1{i} = int32(round(sqrt(1:16).*randn(1,16)));
         invec2{i} = int32(round(sqrt(1:16).*randn(1,16)));
    end

    %********** Calculate expected sum and diff ********************
    expected_sum  = { int32(zeros(1,16)); int32(zeros(1,16)) };
    expected_diff = { int32(zeros(1,16)); int32(zeros(1,16)) };
    for i = 1:2
        expected_sum{i} = int32(invec1{i} + invec2{i});
        expected_diff{i} = int32(invec1{i} - invec2{i});
    end

    %********** Set-up the processor ********************
    if isrunning(IDE_Obj)
        halt(IDE_Obj);
    end
    %------------------------------------
    %On some processors you may try reset
    %reset(IDE_Obj);
    disp(['#Loading the program: ' exe_full_name]);
    load(IDE_Obj, exe_full_name);
    connect(IDE_Obj);
    address_ysum = address(IDE_Obj, 'ysum');
    address_ydiff = address(IDE_Obj, 'ydiff');
    address_invec1 = address(IDE_Obj, 'invec1');
    address_invec2 = address(IDE_Obj, 'invec2');
    disp('#Running the processor.');
    address_fn = address(IDE_Obj,fn_name);
    insert(IDE_Obj,address_fn);
    run(IDE_Obj, 'runtohalt', 100);
    disp('#Processor ran through initialization.');
    

    %********** Execute the algorithm on the processor ********************
    actual_sum  = { int32(zeros(1,16)); int32(zeros(1,16)) };
    actual_diff = { int32(zeros(1,16)); int32(zeros(1,16)) };
    for i = 1:2        
        disp(sprintf('#Writing data set: %d',i)); %#ok<DSPS>
        % write the input test vectors to processor's memory
        write(IDE_Obj, address_invec1, invec1{i});
        write(IDE_Obj, address_invec2, invec2{i});

        % run cpu to calculate actual results
        disp('#Running the processor.');
        run(IDE_Obj, 'runtohalt', 100);
        
        %On some hardware, the base rate will be much faster
        % that the step function will not get any chance to
        % execute from a break point.
        %In such cases, we have to rely on running the processor
        % for sometime before collecting the data.
        %disp('#Running the processor.');
        %remove(IDE_Obj,address_fn);
        %run(IDE_Obj);
        
        %disp('#Waiting for the processor to process data.');
        %pause(2);

        %disp('#Halting the processor to collect the result.');
        %halt(IDE_Obj);

        % read actual results from processor's memory
        actual_sum{i}(1:16) = read(IDE_Obj, address_ysum, 'int32', 16);
        actual_diff{i}(1:16) = read(IDE_Obj, address_ydiff, 'int32', 16);
    end

    %********** Compare expected and actual results ********************
    disp('#Checking the result.');
    error_sum  = { int32(zeros(1,16)); int32(zeros(1,16)) };
    error_diff = { int32(zeros(1,16)); int32(zeros(1,16)) };
    for i = 1:2
        error_sum{i}  = expected_sum{i} - actual_sum{i};
        error_diff{i} = expected_diff{i} - actual_diff{i};
    end

    %********** Print the difference at MATLAB prompt ********************

    if any(cellfun(@any,error_sum)) && any(cellfun(@any,error_diff))
        disp('The two results - MATLAB and Processor implementation are not the same.');
        for i = 1:2
            error_sum{i} %#ok<NOPRT>
            error_diff{i} %#ok<NOPRT>
        end
    else
        disp('The two results - MATLAB and Processor implementation are the same.');
    end

catch tbscrException

    %********** Clean-up ********************

    disp('An error occurred while verifying final implementation.');
    disp(tbscrException.message);
    remove(IDE_Obj,address(IDE_Obj, fn_name));
    localVars = who;

    for varid=1:numel(localVars)
        clear (localVars{varid});
    end

    clear localVars varid;
    return;
end

%********** Clean-up ********************

remove(IDE_Obj,address(IDE_Obj, fn_name));
localVars = who;

for varid=1:numel(localVars)
    clear (localVars{varid});
end

clear localVars varid;

%[EOF] multilink_workflow_testbench_script.m

Contact us