| Link for ModelSim | ![]() |
Add the script code for the decoder test as follows:
Clear the testisdone flag and display informational messages that inform users about what the test does.
testisdone = 0;
disp('========================================================');
disp('MATLAB testing Manchester Receiver component decoder.vhd...');
disp('Creates two plots of the entity''s transfer function,');
disp('providing a visualization of the decoder behavior.');Set the project directory to a directory that has write access and is suitable for holding a ModelSim project. This tutorial assumes the writable project directory is unixprojectdir:
projectdir = pwd;
Change the format of the project directory and decoder VHDL file specifications to the UNIX format, which ModelSim and Tcl use, by replacing backslashes (\) with forward slashes (/).:
% ModelSim and Tcl use the UNIX file specification format unixprojectdir = strrep(projectdir,'\','/'); unixsrcfile = strrep(fullfile(matlabroot,'toolbox','modelsim',... 'modelsimdemos','vhdl','manchester','decoder.vhd'),'\','/');
Define a sequence of Tcl commands to be executed in the context of ModelSim. Define tclcmd as follows:
tclcmd = { ['cd ' unixprojectdir ],...
'catch {wm geometry . 500x200+0+0}',...
'vlib work',...
['vcom -performdefaultbinding ' unixsrcfile],...
'vsimmatlab work.decoder',...
['matlabtb decoder -mfunc Manchester_decoder,...
-socket ' num2str(portnum)],...
'run 3000',...
'quit -f'};The following list explains what each Tcl command does:
The cd command changes to a writable directory.
The wm command adjusts the placement of the ModelSim window so it does not obscure the MATLAB Command Window. This command works in ModelSim SE environments only.
The vlib command creates the design library work.
The vcom command compiles the VHDL file. The -performdefaultbinding option enables default bindings in the event that they have been disabled in the modelsim.ini file.
The vsimmatlab command, a variant of the ModelSim vsim command, loads an instance of the VHDL entity decoder for MATLAB verification. This command is a Link for ModelSim extension to the ModelSim command set.
The matlabtb command initiates a MATLAB test bench session for the loaded instance of entity decoder. This command is a Link for ModelSim extension to the ModelSim command set. The command specifies:
The entity instance.
The -mfunc option, which specifies the MATLAB function that is to test the entity (manchester_decoder.m). This option is required because the MATLAB function name is not the same as the entity name.
TCP/IP socket communication with socket port portnum. For a link to be established between ModelSim and MATLAB, the value specified with -socket must match the socket port that was specified when the MATLAB server (hdldaemon) was started.
The run command starts and runs a ModelSim simulation such that it runs for 3000 iterations of the current resolution limit. By default, the simulation runs for 3000 nanoseconds.
The quit command quits ModelSim. The -f option causes the command to quit without asking for confirmation.
Start ModelSim for use with the Link for ModelSim with the following call to function vsim:
vsim('startupfile','decoder.do', 'tclstart',tclcmd);This command starts ModelSim with a Tcl command script that executes some general-purpose startup commands and then the user-defined commands specified with the property name/property value pair‘tclstart' tclcmd .
The ‘startupfile' property causes vsim to write the entire startup Tcl command script to decoder.do for future reference or use.
Add the following lines of code to display informational messages and wait for manchester_decoder.m to run to completion:
disp('Waiting for testing of ''decoder.vhd'' to complete...');
disp('Flag from manchester_decoder.m indicates completion...');
while testisdone == 0,
pause(0.001);
end
pause(1);
disp('MATLAB test of decoder.vhd is complete. Check the');
disp('generated plot for results.');
disp('Press any key to continue to the next test.');
pause; | Starting the MATLAB Server from the Test Script | Writing Script Code for the I/Q Convolver Test | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |