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

📄 rtdxtutorial.m

📁 matlab连接ccs的例子
💻 M
字号:
%RTDXTUTORIAL Link for RTDX(tm) tutorial.
%   RTDXTUTORIAL is an example script intended to get the user started with the
%   Link for RTDX.  A simple target DSP application is loaded and run on the 
%   target DSP, and data messages are transfered via RTDX between the host 
%   application (MATLAB) and the target DSP.  The tutorial writes integers 1:10 
%   to the target DSP.  The target DSP takes the array of integers and 
%   increments it by 1 and writes the resultant array to the host.  This action 
%   is performed 20 successive times, with each iteration incrementing the the 
%   previous array result by one.  The 20 messages are read by the script using 
%   READMSG and READMAT, employing various output formats.
%
%   See also CCSTUTORIAL, RTDXLMSDEMO, CCSFIRDEMO

%   Copyright 2002 The MathWorks, Inc.
%   $Revision: 1.16 $  $Date: 2002/03/28 21:06:57 $

% Board and processor selection
disp(sprintf(['You will need to select a board and processor using the '...
      'BOARD SELECTION TOOL.\nHit any key to bring up the selection tool...']));
pause;

[boardNum,procNum] = boardprocsel;
echo on
cc=ccsdsp('boardnum',boardNum,'procnum',procNum)
echo off


% Make sure selected processor is RTDX-compatible
% ========================================================================
count = 0;
notReady = 1;
while notReady & count < 2,
    if cc.isrtdxcapable,
        if (cc.info.subfamily >= hex2dec('50')) & ...
                (cc.info.subfamily <= hex2dec('5f')),
            c5x = logical(1);
            target_subdir = 'c5x';
            outFile = 'rtdxtutorial_5x.out';
            notReady = 0;
            % GEL reset
            disp('Hit any key to continue...');
            pause
            uiwait(msgbox({'For the C54xx, you may need to manually load c5000.gel ';...
                    'and then run C5402_DSK_Init under GEL --> C54x.'}, ...
                'Warning: Reset GEL','modal'));
            
        elseif (cc.info.subfamily  >= hex2dec('60')) & ...
                (cc.info.subfamily  <= hex2dec('6f')),
            c5x = logical(0);
            if cc.info.revfamily > 10,
                target_subdir = 'c6x';  
                outFile = 'rtdxtutorial_6x1x.out';
            else
                target_subdir = 'c6x';
                outFile = 'rtdxtutorial_6x0x.out';
            end
            notReady = 0;
        else % Selected processor is not a C5xxx nor C6xxx
            uiwait(msgbox({'RTDX is not supported for the selected board,  '; 
                'please select another board'},...
                'Selection Error','modal'));
            count = count+1;
            if count<2,
                clear cc;
                [boardNum,procNum] = boardprocsel;
                pause(0.1);
                echo on;
                cc=ccsdsp('boardnum',boardNum,'procnum',procNum);
                echo off;
            end
        end
    else % Selected processor is a Simulator
        uiwait(msgbox({'RTDX is not supported for the Simulator,  ';
            'please select another board'},...
            'Selection Error','modal'));
        count = count+1;
        if count<2,
            clear cc;
            [boardNum,procNum] = boardprocsel;
            pause(0.1);
            echo on;
            cc=ccsdsp('boardnum',boardNum,'procnum',procNum);
            echo off;
        end
    end
end
if ~exist('outFile'),
    clear cc;
    error('RTDX is not supported for the selected board.  Exiting tutorial ...');
end
%===========================================================================


% ======================== START OF TUTORIAL ===============================
echo on;

% Specify target directory where target files reside
% target_subdir is dependent on processor type
target_dir = fullfile(matlabroot,'toolbox','ccslink','ccsdemos','rtdxtutorial',target_subdir);

% Go to target directory
cc.cd(target_dir);

% Display contents of target directory
cc.dir;

% make Code Composer IDE visible
cc.visible(1);

% LOAD .out file to target
cc.load(outFile);

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% CONFIGURE channel buffers, 4 buffers of 1024 bytes each
cc.rtdx.configure(1024,4);

% OPEN write channel
cc.rtdx.open('ichan','w');

% OPEN read channel
cc.rtdx.open('ochan','r');

% ENABLE RTDX, and verify, for C54x 
cc.rtdx.enable;
cc.rtdx.isenabled

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% SET global timeout value, and verify
timeout = cc.rtdx.get('timeout')
cc.rtdx.set('timeout', 15)       % set timeout to 15 seconds
timeout = cc.rtdx.get('timeout')

% test DISPLAY and DISP
cc.rtdx

% RESTART target
cc.restart;

% RUN target
cc.run;

%===========================================================================
echo off
pause(3)
disp('Hit any key to continue...');
pause
echo on

% ENABLE write channel
cc.rtdx.enable('ichan');
cc.rtdx.isenabled('ichan')

% write to target DSP
if cc.rtdx.iswritable('ichan'),
    disp('writing to target...')
    indata=1:10
    cc.rtdx.writemsg('ichan', int16(indata))    
end

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% Check enable status of read channel
cc.rtdx.isenabled('ochan')

% Query for number of available messages -- should be 0
num_of_msgs = cc.rtdx.msgcount('ochan')

% ENABLE read channel, and verify
cc.rtdx.enable('ochan');
cc.rtdx.isenabled('ochan')

% give time for target DSP to process data,
% and write results to channel buffer
pause(4);

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% Query for number of available messages -- should be 20
num_of_msgs = cc.rtdx.msgcount('ochan')

% Read one message:
outdata = cc.rtdx.readmsg('ochan', 'int16')

% Read three messages into a cell array of three 1x10 vectors:
outdata = cc.rtdx.readmsg('ochan', 'int16', 3)
% Look at second matrix--de-reference cell array:
outdata{1,2}

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on


% Read two messages into two 2x5 matrices:
outdata = cc.rtdx.readmsg('ochan', 'int16', [2 5], 2)

% Look at both matrices by de-referencing cell array:
outdata{1,:}

% Read one message into one 10x1 column vector:
outdata = cc.rtdx.readmsg('ochan', 'int16', [10 1])

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% READMAT
% Read into a 5x2 matrix:
outdata = cc.rtdx.readmat('ochan','int16', [5 2])

% Query for remaining number of available messages in read channel queue...
num_of_msgs = cc.rtdx.msgcount('ochan')

% Read into a 4x5 matrix (= two messages):
outdata = cc.rtdx.readmat('ochan','int16', [4 5])

% Check the remaining number of available messages in read channel queue.
% Note: Count has been decremented by two.
num_of_msgs = cc.rtdx.msgcount('ochan')

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% Read into a 10x5 matrix (= five messages):
outdata = cc.rtdx.readmat('ochan','int16', [10 5])

% Check the remaining number of available messages in read channel queue.
% Note: Count has been decremented by five.
num_of_msgs = cc.rtdx.msgcount('ochan')

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% FLUSH one message:
cc.rtdx.flush('ochan',1)

% Check the remaining number of available messages in read channel queue.
% Note: Count has been decremented by one.
num_of_msgs = cc.rtdx.msgcount('ochan')

% FLUSH all remaining messages:
cc.rtdx.flush('ochan','all')

% Check the remaining number of available messages in read channel queue.
% Note: COUNT has been reset to zero.
num_of_msgs = cc.rtdx.msgcount('ochan')

%===========================================================================
echo off
disp('Hit any key to continue...');
pause
echo on

% DISABLE all open channels
cc.rtdx.disable('ALL');

if cc.isrunning,       % if the target DSP is running
    cc.halt;           %    halt the processor
end

% DISABLE RTDX
cc.rtdx.disable;

% CLOSE channels
cc.rtdx.close('ichan');       
cc.rtdx.close('ochan');
% or use: cc.rtdx.close('all');

if cc.isvisible,
    cc.visible(0);
end

clear cc;   % Call destructors
echo off;

% =========================== END OF TUTORIAL ================================

% [EOF] rtdxtutorial.m

⌨️ 快捷键说明

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