Initializing the Simulator for a MATLAB Test Bench Session

Once you decide on the controls you need to apply for a test bench, you are ready to initialize the ModelSim simulator for a specific MATLAB test bench session. You initialize ModelSim for a cosimulation session with the matlabtb or matlabtbeval command. These commands

In addition, matlabtb commands can include parameters that control when the MATLAB function executes.

You must specify at least one instance of an entity in your VHDL model. By default, the command applies a shared memory communication link and attaches the specified instance to a MATLAB function that has the same name as the instance. For example, if the instance is modsimrand, the command links the instance with the MATLAB function modsimrand in file modsimrand.m. Alternatively, you can specify a different function name with the option -mfunc.

To apply TCP/IP socket communication, specify the command with the -socket option and a TCP/IP specification. If ModelSim and MATLAB are running on the same system, the TCP/IP specification identifies a unique TCP/IP socket port to be used for the link. If the two applications are running on different systems, you must specify a remote host name or Internet address in addition to the socket port. The following table lists different ways of specifying a TCP/IP specification.

FormatExample
Port number4449 on this computer
Port aliasmatlabservice on this computer
Port number and remote host name4449@compa
Remote host name and port numbercompa:4449
Port alias and remote host Internet addressmatlabservice@123.34.55.23

For more information on choosing TCP/IP socket ports, see Choosing TCP/IP Socket Ports.

The matlabtbeval command executes the MATLAB function once at the start of the simulation, while matlabtb provides several options for scheduling MATLAB function execution. The following table lists the various scheduling options.

Simulation Scheduling Options

To Specify that the MATLAB function Execute...Include... Where...
At explicit times time[, ...]

time represents one of n time values, past time 0, at which the MATLAB function is to execute.

For example:

10 ns, 10 ms, 10 sec

The MATLAB function executes when time equals 0 and then 10 nanoseconds, 10 milliseconds, and 10 seconds from time zero.

A combination of explicit times and repeatedly at an intervaltime[, ...] -repeat n

time represents one of n time values at which the MATLAB function is to execute and the n specified with -repeat represents an interval between MATLAB function executions. The interface applies the union of the two options.

For example:

5 ns -repeat 10 ns

The MATLAB function executes at time equals 0 ns, 5 ns, 15 ns, 25 ns, and so on.

When a specific signal experiences a rising or falling edge

-rising signal[, ...]

-falling signal[, ...]

signal represents a pathname of a signal defined as a logic type — STD_LOGIC, BIT, X01, and so on.
A sensitivity list-sensitivitysignal[, ...]

signal represents a pathname of a signal defined as any type. If the value of one or more signals in the specified list changes, the interface invokes the MATLAB function.

    Note   Use of this option for INOUT ports can result in double calls.

If you specify the option with no signals, the interface is sensitive to value changes for all signals.

For example:

-sensitivity /randnumgen/dout 

The MATLAB function executes if the value of dout changes.

Consider the following matlabtb command:

VSIM n> matlabtb modsimrand -rising /modsimrand/clk,
-socket 4449

This command links an instance of the entity modsimrand to function modsimrand.m, which executes within the context of MATLAB based on specified timing parameters. In this case, the MATLAB function is called when the signal /modsimrand/clk experiences a rising edge.

Arguments in the command line specify the following:

modsimrandThat an instance of the VHDL entity modsimrand be linked with the MATLAB function modsimrand.
-rising /modsimrand/clkThat the MATLAB function modsimrand be called when the signal /modsimrand/clk changes from '0' to '1'.
-socket 4449That TCP/IP socket port 4449 be used to establish a communication link with MATLAB.

To verify that the matlabtb or matlabtbeval command established a connection, change your input focus to MATLAB and call the function hdldaemon with the 'status' option as follows:

hdldaemon('status')

If a connection exists, the function returns the message

HDLDaemon socket server is running on port 4449 with 1 connection


Learn more about the latest releases of MathWorks products:

 © 1994-2009 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS