Code covered by the BSD License  

Highlights from
MPC555 Motor Control Function Blockset

MPC555 Motor Control Function Blockset

by

 

20 Mar 2006 (Updated )

Additional I/O blocks for MPC555 target - specifically targetting TPU functionality

mpc555_dptram_wizard_set(block, module, fname, fn_names, macronames, emumodes, banknums)
function mpc555_dptram_wizard_set(block, module, fname, fn_names, macronames, emumodes, banknums)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION MPC555_DPTRAM_WIZARD_SET(BLOCK, MODULE, FNAME, FN_NAMES,
% MACRONAMES, EMUMODES, BANKNUMS)
%
% A utility to be used for automated testing, to set values in the DPTRAM
% configuration wizard block
%
%
%   BLOCK:          The DPTRAM mask configuration wizard block to be
%                   configured
%   MODULE:         The DPTRAM module to configure 'AB', or 'C'
%   FNAME:          A string containing an 8.3 filename e.g. 'DEFAULT.ASC'
%   FN_NAMES:       A [16,3] sized cell array of strings containing
%                   function names. Note that this is not checked in any
%                   way, so if an invalid name is specified compilation
%                   will fail.
%   MACRONAMES:     A cell array containing the strings of the following
%                   nature:  {'macroname', '0123456', 'macroname', '01234'}
%                   Specify macro names and a string of HEXADECIMAL
%                   characters denoting the channels that should be
%                   configured.  Refer to the macro source files for the
%                   order in which these should be specified.
%  EMUMODES:        A string containing R or E for each TPU module to be
%                   configured.  For DPTRAM_AB, valid combinations are:
%                   'RR', 'RE', 'ER', 'EE'
%  BANKNUMS:        A string containing bank number for each TPU module to
%                   be configured. '00' '01' '02' '10' '11' '12' '20' '21'
%                   '22' etc...
%
% Example:
%
% mpc555_dptram_wizard_set(wizblock, 'AB', 'autotest.asc', fn_names, ...
%   {pp, currmodel.channelsettings{p}{:}}, 'RE', '00');

% Ensure that a block of the correct type is used - or else all sorts of
% mess will be created
if ~strcmp(get_param(block, 'ReferenceBlock'), 'mpc555_mtrctrl/DPTRAM Configuration Wizard')
    error ('Block reference must be the DPTRAM Configuration Wizard');
end

% Create a data class object
dptram_res = mpc555mtrctrldata.DPTRAMDATA;

% Firstly check that a valid module has been chosen and set in the data
% class object.
switch module
    case 'AB'
        dptram_res.DPTRAMModule = 'AB';
    case 'C'
        dptram_res.DPTRAMModule = 'C';
    otherwise
        error('Invalid setting for module - valid settings are ''AB'' and ''C''');
end

% Check that the filename is valid, then set in the data class object
if length(fname) > 12 || ~eq(strfind(fname, '.'), length(fname)-3)
    error('File name must be in format 8.3');
else
    dptram_res.Filename = fname;
end

% Check that the function names are at least the correct shape
if isequal(size(fn_names), [16, 3]) || ~iscell(fn_names)
    dptram_res.FNNames = fn_names;
else
    error('Function names should be a [16, 3] sized cell array of strings')
end

% Macro names - check that they are at least specified plausibly.
if mod(length(macronames), 2) ~= 0
    error ('Channels not specified for all macros')
end

% If specified plausibly, create 
dptram_res.Macros = {};
if length(macronames) ~= 0
    for n=1:2:length(macronames)
        dptram_res.Macros{ (n+1)/2 } = mpc555mtrctrldata.MACROSETTING;
        dptram_res.Macros{ (n+1)/2 }.Name = macronames{n};
        dptram_res.Macros{ (n+1)/2 }.Channels = mpc555_dptram_wizard_macros( 'DECODE', macronames{n+1}, macronames{n});
    end
end

% Configure emulation mode
switch dptram_res.DPTRAMModule
    case 'AB'
        tpu_list = {'TPU_A', 'TPU_B'};
    case 'C'
        tpu_list = {'TPU_C'};
end

dptram_res.TPU = {};
for n=1:length(tpu_list)
    dptram_res.TPU{n} = mpc555mtrctrldata.MODULES;
    dptram_res.TPU{n}.Name = tpu_list{n};
end

if length(emumodes) ~= length(tpu_list)
    error('Invalid emulation mode setting');
end
if length(banknums) ~= length(tpu_list)
    error('Invalid bank number setting');
end

% For each required TPU
for n=1:length(tpu_list)
    switch emumodes(n)
        case 'R'
            dptram_res.TPU{n}.Emulation = 'ROM';
        case 'E'
            dptram_res.TPU{n}.Emulation = 'EMULATION';
        otherwise
            error('Invalid emulation mode setting - R, E only valid');
    end
    
    % Check which Bank has been chosen
    switch banknums(n)
        case '0'
            dptram_res.TPU{n}.Bank = 'Bank 0';
        case '1'
            dptram_res.TPU{n}.Bank = 'Bank 1';
        case '2'
            dptram_res.TPU{n}.Bank = 'Bank 2';
        otherwise
            error('Invalid bank number');
    end
end


% If all is successful, set the userdata object in the block
set_param(block, 'userdata', dptram_res);
set_param(block, 'userdatapersistent', 'on');


end

Contact us