📄 ccsfirdemo.m
字号:
'extends the same functionality to MATLAB. After the '
'target code is built, the target can be loaded and '
'executed by MATLAB. By interactively modifying and '
'reading memory locations in the DSP, it is possible to '
'directly evaluate the target''s algorithms, in place! '
' The first step is to create the necessary target program.'
'This requires assembling a Code Composer(tm) project and '
'building the necessary program files. By pressing the '
'''Load Project'' button, a sample project file is loaded. '
'This project has the required source files: '
' ccsfir.c - C Source file supplied with this demo. '
' vectos_x.asm - Assembly source file which implements '
' vector table. '
' ccsfir_x.cmd - Linker command file '
' (x = will depend on the user''s processor type) '
' '
' See also OPEN '
' File name: ccsfirdemo.m '];
elseif slidenum == 3,
ttlStr = 'Loading the Program File';
hlpStr = [ ...
'The supplied Code Composer project has all the necessary '
'source files to implement the demo. These files must be '
'compiled and linked to produce an executable COEFF file, '
'which can be loaded into the target DSP processor. '
'Several sample projects are supplied with this demo for '
'different families of processors. This demo will try to '
'load the version which best matches your processor. The '
'following projects are supplied: '
' TMS32054xx family - ccsfir_54xx.mak '
' TMS3206211/6711 - ccsfir_6x11.mak '
' TMS3206201/6202/6701 - ccsfir_6x0x.mak (map 1) '
' If your processor is not on this list, or it has a unique'
'memory arrangement, some modification to the project '
'may be necessary. Before proceeding, these changes must '
'be applied and a suitable program file generated. This '
'file should have the default name: ''a.out.'' This file '
'should be built with symbol generation enabled. When the '
'program file is ready, press ''Load Program'' to proceed '
'with the demo. '
' '
' See also OPEN '
' File name: ccsfirdemo.m '];
elseif slidenum == 4,
ttlStr = 'Query Symbol Table';
hlpStr = [ ...
'The Target now has the code necessary to execute the '
'demo. The next step is to determine the proper locations '
'in target memory for the data values that will be '
'manipulated by this demo. This is done by querying the '
'symbol table for global variables that were defined in the'
'main source file: ''ccsfir.c''. By writing into these '
'memory locations, it is possible to directly modify the '
'target program''s filter characteristics. '
' To implement this demo, the coefficients of the filter '
'are written to the target. Also, a block of random data '
'is transferred to the target and then processed by the '
'FIR filter. The post-filter data is then read to produce'
'direct measurements of filter performance. '
'Press ''Read Symbols'' to proceed with demo. '
' '
' See also ADDRESS,SYMBOL,READ,WRITE '
' File name: ccsfirdemo.m '];
else
ttlStr = 'Execute Target Filter and Measure Response';
hlpStr = [ ...
'By changing the filter options, the user can modify the '
'filter coefficients. The expected filter response is '
'plotted in the plot window as the blue trace. Note, this '
'response does NOT include the effects of quantization. '
'Therefore, the measured and expected will differ, '
'particularly in the rejected bands. The theoretical '
'response is generated by the MATLAB function: FREQZ. '
' By pressing the ''Run Target'' button, the target '
'processors''s implementation of the filter is tested and '
'plotted in red. This testing is done continuously in '
'blocks of 512 data points. Use ''Halt'' to suspend the '
'execution. After halting, it is possible to modify the '
'filter parameters and re-run the target characterization '
'program. The filter options are as follows: '
' W0 - First cutoff frequency '
' W1 - Second cutoff frequency (bandpass, bandstop only) '
' Ncoeff - Number of filter coefficient (max 64). '
' Filter Type - Lowpass, Highpass, Bandpass, Bandstop '
'Frequencies are normalized such that 1 = fsamp/2 . '
' '
' See also FIR1, FREQZ, FREQZPLOT, RUN '
' File name: ccsfirdemo.m '];
end
helpdlg(hlpStr,ttlStr);
% --------------------------------------------------------------------
function varargout = viewscript_Callback(h, eventdata, handles, varargin)
% Callback to specify filter type (lowpass, highpass, etc)
edit ccsfirdemo_script.m
% --------------------------------------------------------------------
function varargout = exit_Callback(h, eventdata, handles, varargin)
% Callback to quit demo
if isempty(get(handles.exit,'UserData'))
set(handles.exit,'UserData',2); % Halt execution (synchronously)
else
delete(gcbf);
end
% --------------------------------------------------------------------
function varargout = slide_Callback(h, eventdata, handles, varargin)
% Callback to advance the slides
slidenum = get(h,'UserData');
pointsave=get(gcbf,'Pointer');
set(gcbf,'Pointer','watch');
if slidenum == 1,
% Slide 1 -> activate Code Composer: 'Make Link'
bdnum = get(handles.boardnum,'UserData');
procnum = get(handles.procnum,'UserData');
cmd = ['cc=ccsdsp(''boardnum'',' num2str(bdnum) ',''procnum'',' num2str(procnum) ');' ];
try
eval(cmd);
set(cc,'timeout',30); % extend default timeout to ensure slow targets do not timeout
catch
set(gcbf,'Pointer','arrow');
errordlg({lasterr 'Failed to establish a link to Code Composer(tm)'},'Link Error');
return;
end
msg = { ['>' cmd],...
' Link to Code Composer(tm) established (cc).',...
'Next a sample target project can be loaded by',...
'pressing ''Load Project''. Three sample projects',...
'are provided with support for several TI DSP',...
'processors. However, modifications to the'...
'project may be required in some cases.'...
};
set(handles.infobox,'String',msg);
handles.cc = cc; % save for later
guidata(gcbo,handles); % store the changes...
set(h,'String','Load Project');
set([handles.boardnum handles.procnum handles.select],'Enable','off'); %Disable
set(h,'UserData',slidenum+1); % Move to next slide
elseif slidenum == 2,
% Slide 2 -> Load Project File
cc = handles.cc;
cc.visible(1);
if cc.info.subfamily == 84,
outout = 'ccsfir_54xx.pjt';
elseif cc.info.revfamily > 10,
outout = 'ccsfir_6x11.pjt';
else
outout = 'ccsfir_6x0x.pjt';
end
outmak = fullfile(matlabroot,'toolbox','ccslink','ccsdemos','ccsfir',outout);
if ~exist(outmak,'file'),
set(gcbf,'Pointer',pointsave);
warndlg({'Error - unable to locate project file:' outmak},'Project File Error');
return;
end
try
cc.open(outmak);
catch
set(gcbf,'Pointer',pointsave);
warndlg({lasterr 'Failed to load project file:' outmak},'CCS File Error');
return;
end
msg = { ['>cc.open(''' outout ''');'],...
' A sample project has been loaded into CCS. ',...
'This includes all the necessary source files.',...
'The linker switches should be adjusted for',...
'the target. Before proceeding, be sure to',...
'build the program file: ''a.out''.',...
'If necessary, load a valid GEL file.',...
'Then press ''Load Program'' to continue.'...
};
set(handles.infobox,'String',msg);
set(h,'String','Load Program');
set(h,'UserData',slidenum+1); % Move to next slide
elseif slidenum == 3,
% Slide 3 -> Load Program File
cc = handles.cc;
if cc.info.subfamily == 84,
outout = 'a54xx.out';
elseif cc.info.revfamily > 10,
outout = 'a6x11.out';
else
outout = 'a6x0x.out';
end
outprog = fullfile(matlabroot,'toolbox','ccslink','ccsdemos','ccsfir',outout);
if ~exist(outprog,'file'),
set(gcbf,'Pointer',pointsave);
warndlg({'Error - unable to locate program file:' outprog},'Program File Error');
return;
end
try
cc.load(outprog);
catch
set(gcbf,'Pointer',pointsave);
warndlg({lasterr 'Failed during loading of program file:' outprog},'CCS File Error');
return;
end
msg = { ['>cc.load(''' outout ''');'],...
' A sample program has been loaded into the DSP. ',...
'The target code should now be ready to run!',...
'Next, press ''Read Symbols'' to query the',...
'target for relevant memory locations.'};
set(handles.infobox,'String',msg);
set(h,'String','Read Symbols');
set(h,'UserData',slidenum+1); % Move to next slide
elseif slidenum == 4,
% Slide 4 -> Check Symbol Table Values
cc = handles.cc;
symbt = struct('coeff',[]);
try
symbt.coeff = cc.address('coeff');
symbt.din = cc.address('din');
symbt.dout = cc.address('dout');
symbt.ncoeff= cc.address('ncoeff');
symbt.nbuf= cc.address('nbuf');
catch
warndlg({lasterr 'Failed to read Target''s symbol table'},'CCS Symbol Error');
return;
end
msg = { '>cc.address(''coeff'');',...
' The location in the target''s memory of ',...
'the data and coefficient arrays has been',...
'located and read into MATLAB. For',...
'example, the filter coefficents are',...
['located at address & page: ' int2str(symbt.coeff) ],....
'Define the desired FIR filter and press',...
'''Run Target'' to perform characterization.'
};
set(handles.infobox,'String',msg);
handles.symbols = symbt; % save for later
guidata(gcbo,handles); % store the changes...
set([handles.type handles.order handles.w1 handles.w2],'Enable','on');
plotfilter(h, eventdata, handles, varargin);
set(h,'String','Run Target');
set(h,'UserData',slidenum+1); % Move to next slide
elseif slidenum == 5,
% Slide 5 -> Execute
set(handles.exit,'UserData',[]); % Clear any old breaks
set(gcbf,'Pointer',pointsave);
set(h,'String','Halt');
cc = handles.cc;
cc.visible(0); % seems to make it much faster
symbt = handles.symbols;
nfrm = 256;
bcoeff = handles.bcoef;
ncoeff = length(bcoeff);
set(h,'UserData',6); % Temporarily re-map this callback!
cscaling = 2^15;
cc.write(symbt.coeff,int16(cscaling.*bcoeff));
cc.write(symbt.ncoeff,int32(ncoeff));
cc.write(symbt.nbuf,int32(nfrm));
msg1 = {'>cc.write(s.din,int16(randn(n,1)))',...
' The data arrays and coefficents have been',...
'written to the target DSP.'
};
msg2 = {'>cc.run(''runtohalt'')',...
'>dout = cc.read(symbols.din,''int16'',n)',...
' The filtered data has been read and',...
'processed to produce the red plot trace.',...
'These steps will be repeated to measure the',...
'filter reponse with new data. Press ''Halt''',...
'to modify the filter or ''Exit'' to leave'...
'the demo.'
};
iter = 0;
while isempty(get(handles.exit,'UserData')),
% Compute Data Arrays
din = randn(nfrm,1);
glim = max([abs(max(din)) abs(min(din))]);
dscale = 2^15/(glim*0.99);
idin = int16(dscale*din);
cc.write(symbt.din,idin);
if ~iter, set(handles.infobox,'String',msg1); end
if ~isempty(get(handles.exit,'UserData')), break; end
% Now ready to execute target
cc.restart;
tout = 15+ncoeff;
cc.run('runtohalt',tout);
% Ok let's read the data and fix scaling
idout = cc.read(symbt.dout,'int16',nfrm);
[sout wsd]= pwelch(double(idout));
sin = pwelch(double(idin));
if ~iter
runningsum = (sout./sin);
else
runningsum = runningsum + (sout./sin);
end
wplotdb = 10*log10(runningsum/(iter+1));
wsdn = wsd/pi;
plot(handles.swdb,handles.scodb,'b',wsdn,wplotdb,'r','Parent',handles.axes);
grid(handles.axes);
% legend('Theoretical','Measured','Parent',handles.axes)
if ~iter, set(handles.infobox,'String',msg2); end
iter = iter +1;
end
msg = {'! Execution halted by user.',...
' Modify filter parameters and then press',...
'''Run Filter'' to measure the response of',...
'the new coefficients. At any time, press',...
'''Close'' to leave the demo.'
};
set(handles.infobox,'String',msg);
set(h,'String','Run Filter');
set(h,'UserData',5); % Undo remap
if get(handles.exit,'UserData') == 2, % Commanded to Exit
delete(gcbf);
end
elseif slidenum > 5, % Break command
set(handles.exit,'UserData',1); % Halt a loop
end
set(gcbf,'Pointer',pointsave);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -