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

📄 ccstutorial.m

📁 matlab连接ccs的例子
💻 M
📖 第 1 页 / 共 3 页
字号:
echo off
elseif c6x11family,
echo on
projfile = fullfile(matlabroot,'toolbox','ccslink','ccsdemos','ccstutorial','ccstut_6x11.pjt')
projpath = fileparts(projfile)
open(cc,projfile)     % Open project file
cd(cc,projpath)       % Change working directory of Code Composer(only)
echo off
elseif c6x0xfamily,
echo on
projfile = fullfile(matlabroot,'toolbox','ccslink','ccsdemos','ccstutorial','ccstut_6x0x.pjt')
projpath = fileparts(projfile)
open(cc,projfile)     % Open project file
cd(cc,projpath)       % Change working directory of Code Composer(only)
echo off
end

%========================================================================
% The Code Composer Files: Build

disp(sprintf(['=================================================================\n'...
              ' You should notice the tutorial''s project loaded in Code Composer.\n'...
              '  Examine the files in Code Composer that comprise this project.\n'...  
              '  the main source file used by this tutorial is ''ccstut.c'',\n'... 
              '  which is identical for all DSP families.  There is also a linker\n'...
              '  command file (*.cmd) and vector table source file (*.asm), which\n'...
              '  will be different, depending on the DSP family you are using. \n'...
              '  Before proceeding, the project must be converted into a program\n'...
              '  file that can be executed by the DSP.  This is done with the \n'...
              '  ''build'' method.  Building a project can be rather slow, depending\n'...
              '  on your configuration.  Therefore, an explicit 60 second timeout is\n'...
              '  supplied with the build method.  Please wait for the build operation\n'...
              '  to complete before proceeeding\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue:  build ---');
pause;
echo on
build(cc,'all',60)
echo off
%========================================================================
% The Code Composer Files: address

disp(sprintf(['=================================================================\n'...
              '  The ''MATLAB Link for Code Composer Studio'' includes methods for \n'...
              '  reading the target''s symbol table to give direct access to data in \n'...
              '  the DSP memory.  Note - The symbol table is only available after\n'...
              '  the program file is built and then loaded into the DSP.\n'...
              '  Therefore the next step is to load the generated program file: \n'...
              '  ''a.out'' via the ''load'' method.  Notice the results of checking\n'...
              '  the symbol table for the variable ''ddat'' before and after\n'...
              '  the load. \n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue:  load,address,dec2hex ---');
pause;

if c5xfamily,
try
echo on
warnState = warning('on');   % Enable warnings to demonstrate the next command
address(cc,'ddat')  % Note - This may (correctly) issue a warning before the executable file is loaded.
warning(warnState);  % Reinstate warning state
load(cc,'ccstut_54xx.out',30)    % Load the target execution file
ddatA = address(cc,'ddat')   % Now it should find the address of global value: ddat
dec2hex(ddatA)     % in hexadecimal (address and page)
echo off    
catch 
    echo off
    warning(warnState);
    disp(lasterr);
    disp(sprintf(['!!!!! The load of ''ccstut_54xx.out'' failed.  Please attempt to rebuild it\n'...
                  'and then manually load it from Code Composer before proceeding. \n'...
                  'Then press return to attempt the load operation again\n']));
    pause;
echo on
load(cc,'ccstut_54xx.out',40)   % Load the target execution file
ddatA = address(cc,'ddat')  % Read the address of global: ddat
dec2hex(ddatA)     % in hexadecimal (address and page)
echo off    
end

elseif c6x11family,
try
echo on
warnState = warning('on');   % Enable warnings to demonstrate the next command
address(cc,'ddat')  % Note - This may (correctly) issue a warning before the executable file is loaded.
warning(warnState);  % Reinstate warning state
load(cc,'ccstut_6x11.out',30)    % Load the target execution file
ddatA = address(cc,'ddat')   % Now it should find the address of global value: ddat
dec2hex(ddatA)     % in hexadecimal (address and page)
echo off    
catch 
    echo off
    warning(warnState);
    disp(lasterr);
    disp(sprintf(['!!!!! The load of ''ccstut_6x11.out'' failed.  Please attempt to rebuild it\n'...
                  'and then manually load it from Code Composer before proceeding. \n'...
                  'Then press return to attempt the load operation again\n']));
    pause;
echo on
load(cc,'ccstut_6x11.out',40)   % Load the target execution file
ddatA = address(cc,'ddat')  % Read the address of global: ddat
dec2hex(ddatA)     % in hexadecimal (address and page)
echo off    
end

elseif c6x0xfamily,
try
echo on
warnState = warning('on');   % Enable warnings to demonstrate the next command
address(cc,'ddat')  % Note - This may (correctly) issue a warning before the executable file is loaded.
warning(warnState);  % Reinstate warning state
load(cc,'ccstut_6x0x.out',30)    % Load the target execution file
ddatA = address(cc,'ddat')   % Now it should find the address of global value: ddat
dec2hex(ddatA)     % in hexadecimal (address and page)
echo off    
catch 
    echo off
    warning(warnState);
    disp(lasterr);
    disp(sprintf(['!!!!! The load of ''ccstut_6x0x.out'' failed.  Please attempt to rebuild it\n'...
                  'and then manually load it from Code Composer before proceeding. \n'...
                  'Then press return to attempt the load operation again\n']));
    pause;
echo on
load(cc,'ccstut_6x0x.out',40)   % Load the target execution file
ddatA = address(cc,'ddat')  % Read the address of global: ddat
dec2hex(ddatA)     % in hexadecimal (address and page)
echo off    
end
end
%=======================================================================
% Insert Breakpoint
disp(sprintf(['=================================================================\n'...
              ' After the target code loaded, it is possible to examine\n'...
              '  and modify data values in the DSP target from MATLAB.\n'...
              '  For static data values, it is possible to read them\n'...
              '  immediately after loading a program file.  However, the\n'...
              '  more interesting case is to manipulate data values at \n'...
              '  intermediate points  during program execution.  To \n'...
              '  facilitate this operation, there are  methods to insert \n'...
              '  (and delete) breakpoints in the DSP program.  The  method \n'...
              '  ''insert'' creates a new breakpoint, which can be specified \n'...
              '  by either a source file location or a physical memory address.\n'...
              '  For this tutorial, we need to insert a breakpoint at line \n'...
              '  64 of the ''ccstut.c'' source file.\n'...
              '  To assist your visibility of this action, the method ''open''\n'...
              '  is used to display the source file in Code Composer.  Futhermore,\n'...
              '  the ''activate'' method will force this file to the front.\n'...
              '  (Although it is not demonstrated here, ''delete'' can be used\n'...
              '  to remove a breakpoint.)\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue:  activate, insert and open ---');
echo on
open(cc,'ccstut.c','text')    % Be sure this file is open for viewing in CCS
activate(cc,'ccstut.c','text') % Bring the source file forward
insert(cc,'ccstut.c',64)   % Insert breakpoint at line 64
echo off 
%========================================================================
% Halt, run, read
disp(sprintf(['=================================================================\n'...
              ' Examine the source file ''ccstut.c'' in the Code Composer Studio \n'...
              '  source editor area.  There should be a breakpoint on line 26\n'...
              '  (indicated by a red dot).  Next, locate the two global data\n'.... 
              '  arrays: ''ddat'' and ''idat'', which are located at lines 10\n'...
              '  and 11 in this file. \n'...
              '  These DSP memory arrays can be accessed directly from\n'...
              '  MATLAB command line using the ''read'' and ''write'' methods.\n'...
              '  To control target execution use the ''run'',''halt'' and\n'...
              '  ''restart'' methods.   The following section will demostrate\n'...
              '  these methods. \n'...
              ' This approach to access DSP memory is powerful but rudimentary. Later\n'...
              '  in the tutorial we''ll introduce an easier method based on\n'...
              '  C variables\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue:  halt,restart,read ---');
pause;
try
if c5xfamily,
echo on
halt(cc)                    % halt the CPU (if necessary)
restart(cc)                 % reset the PC to start of program
run(cc,'runtohalt',20);     % wait for program execution to stop at breakpoint! (timeout = 20 seconds)
    
ddatV = read(cc,address(cc,'ddat'),'single',4)   % Should equal initialized value from C-Code
idatV = read(cc,address(cc,'idat'),'int16',4)
 
write(cc,address(cc,'ddat'),single([pi 12.3 exp(-1) sin(pi/4)]))   % Modify memory values
write(cc,address(cc,'idat'),int16([1:4]))
    
run(cc,'runtohalt',20);     % Resume execution from breakpoint, then modify 
    
ddatV = read(cc,address(cc,'ddat'),'single',4)

⌨️ 快捷键说明

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