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

📄 ccstutorial.m

📁 matlab连接ccs的例子
💻 M
📖 第 1 页 / 共 3 页
字号:
idatV = read(cc,address(cc,'idat'),'int16',4)
    
restart(cc);
echo off
else % C6xx Family
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'),'double',4)   % Should equal initialized value from C-Code
idatV = read(cc,address(cc,'idat'),'int32',4)
  
write(cc,address(cc,'ddat'),double([pi 12.3 exp(-1) sin(pi/4)]))   % Modify memory values
write(cc,address(cc,'idat'),int32([1:4]))
    
run(cc,'runtohalt',20);     % Resume execution from breakpoint, then modify 
    
ddatV = read(cc,address(cc,'ddat'),'double',4)
idatV = read(cc,address(cc,'idat'),'int32',4)
    
restart(cc);
echo off
end
catch
echo off
    disp(lasterr);
    disp(sprintf(['!!!! The program execution failed - Generally this is because the\n'....
           'breakpoint was not included in the source file.  This caused the\n'...
           'CPU to continue execution without halting.  Try re-running the\n'...
           'tutorial and be sure to insert the breakpoint when it is requested.\n'...
           'In some cases, resetting the board before running the tutorial may be\n'...
           'necessary.  It is often helpful to verify the Target code in Code\n'...
           'Composer before executing the tutorial.\n']));
     error('CCS Tutorial failure');
end

%========================================================================
% regread/regwrite

disp(sprintf(['=================================================================\n'...
              ' For Assembly language programmers, there are also methods\n'...
              '  to access CPU registers: ''regread'' and ''regwrite''.\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue: regread/regwrite ---');
if c5xfamily,
pause;
echo on
tReg = regread(cc,'AL','2scomp')    % 2's complement version of AL
regread(cc,'TRN','binary')           % Unsigned version of the transition register.
regwrite(cc,'AH','FFFF','binary')
echo off
else
echo on
tReg = regread(cc,'A0','2scomp')    % 2's complement version of A0
regread(cc,'B2','binary')           % Unsigned version of B2
regwrite(cc,'A2',tReg,'2scomp')
echo off
end
%========================================================================
% List, Goto

disp(sprintf(['=================================================================\n'...
              ' Direct access to DSP memory is powerful, but for C programmers it is \n'...
              '  more convenient to manipulate memory in ways consistent with the\n'...
              '  defined C variables.  This type of access is implemented using MATLAB\n'...
              '  objects as representations of embedded entities. \n'...
              ' First, let''s take a look at the same data values that we explored \n'...
              '  above but now we''ll manipulate them using objects. First, we''ll restart\n'...
              '  the program and apply the ''list'' method, which queries Code Composer\n'...
              '  for information ''idat'', i.e. the global C variable of interest\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue: list.goto ---');

pause;
echo on
restart(cc)        % Restart program
goto(cc,'main')   % Ensured Embedded C variables get initialized
listI = list(cc,'variable','idat')  % Returns structure of information about global variable: 'idat'
listI.idat
echo off

%========================================================================
% Createobj, Read, Write

disp(sprintf(['=================================================================\n'...
             ' ''List'' generates lots of information about the embedded ''idat'' variable.\n'...
             '  However, an even more useful method is ''createobj'', which generates \n'...
             '  a MATLAB object object to represent the C variable,  This object \n'...
             '  acquires the properties of the C variable.  Applying the object\n'...
             '  returned by  ''createobj'', you can directly read the entire \n'...
             '  variable or access individuals elements of an array.\n'...
             ' Note - up to this point all methods were applied to the original ''cc''\n'...
             '  object that was created with ''ccsdsp''.  The ''cc'' object represents \n'...
             '  communication with a particular embeddded processor in Code Composer Studio.\n'...
             '  However, for the remainder of this tutorial, methods are applied to many \n'...
             '  different objects.  In typical object-oriented fashion, the action\n'...
             '  performed by a method will depend on it''s object.  The relevant object\n'...
             '  is always the first parameter passed to the method. For example, in the\n'...
             '  following section ''cvar'' is an object representing the embedded \n'...
             '  ''idat''  variable\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue: createobj, read, write ---');

pause;
echo on
cvar = createobj(cc,'idat')   % Creates MATLAB object 'cvar' to manipulate embedded 'idat'
read(cvar)       % Reads the entire embedded array into the MATLAB workspace
read(cvar,2)    % Reads only the second element
write(cvar,4,7001)  % Modifies the forth element to 7001
read(cvar)      % See changes
read(cvar,[1 cvar.size])  % read only first and last element
echo off

%========================================================================
% Cast, Convert, Size
disp(sprintf(['=================================================================\n'...
              ' The previous ''read'' takes the raw memory values and converts them\n'...
              '  into equivalent MATLAB numeric values.  The conversion that gets \n'...
              '  applied is controlled by the properties of the object, which were\n'...
              '  initially configured in ''createobj'' to settings appropriate for \n'...
              '  your DSP architecture and C representation.   In some cases, it is\n'...
              '  useful to alter these default conversion properties.  Several\n'...
              '  properties such as ''endianness'',''arrayorder'' and ''size'' can\n'...
              '  be directly modifed using ''set''.  More complex changes are possible\n'...
              '  using methods such as ''convert'' and ''cast'', which adjust multiple \n'...
              '  properties simultaneously.\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue: cast, convert, size ---');

pause;
echo on
set(cvar,'size',[2])   % Reduce size of 'idat' to first 2 elements
read(cvar)
uicvar = cast(cvar,'unsigned short')   % Creates new object with specified datatype (but otherwise identical)
read(uicvar)   % Note - first value is no longer -1, but unsigned equivalent
convert(cvar,'unsigned short')  % Same as Cast, but alters properties of existing class 
read(cvar)    % Remember - the size of cvar was set to 2!
% 
echo off

%========================================================================
% getmember

disp(sprintf(['=================================================================\n'...
              ' DSP variables such as strings, structures, bitfields, enumerated types\n'...
              '  and pointers can be manipulated just as easily.   The following \n'...
              '  demonstrates some common manipulations on structures, strings\n'...
              '  and enumerated types.  In particular, note the ''getmember'' method,\n'...
              '  which extracts a single field from a structure as a new MATLAB\n'...
              '  object. \n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue: getmember ---');
pause;
echo on
cvar = createobj(cc,'myStruct')   % Object that represents an embedded C structure
read(cvar)
write(cvar,'iz', 'Simulink')   % Modify 'iz' field using actual enumerated name 
cfield = getmember(cvar,'iz')  % Extract object from structure
write(cfield,4)   % Write to same enumerated variable by value
read(cvar)
cstring = createobj(cc,'myString')   %  Object that represents an embedded C structure
read(cstring)
write(cstring,7,'ME')
read(cstring)
write(cstring,1,127)  % Set first location to numeric value 127 (a non-printable ASCII character)
readnumeric(cstring)  % Read equivalent numeric values
% 
echo off
%========================================================================
% Deleting the link: clear
disp(sprintf(['=================================================================\n'...
              ' Finally, the objects created during this tutorial have COM handles\n'...
              '  to Code Composer Studio.  Until these handles are deleted, the\n'...
              '  Code Composer Studio process will remain in memory.  Exiting\n'...
              '  MATLAB will automatically remove these handles, but in some\n'...
              '  cases it might be useful to manually delete them.  Use ''clear''\n'...
              '  to remove objects from the MATLAB workspace and delete any handles\n'...
              '  they contain.  ''Clear all'' will delete everything.\n'...
              '  Alternatively, to retain your MATLAB data use ''clear'' on the\n'...
              '  objects derived from ''ccsdsp'' (including all objects returned\n'...
              '  by ''createobj''). \n'...
              ' In addition ''Close'' is performed on the tutorial project to remove\n'...
              '  it from Code Composer.\n'...
              '=================================================================\n\n']));
disp('--- Press any key to continue:  close, clear ---');
pause;
echo on
close(cc,projfile,'project')   % Let's clean-up Code Composer by closing the project file
clear cc cvar cfield uicvar cstring
echo off

⌨️ 快捷键说明

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