| Link for ModelSim | ![]() |
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
Identify the instance of an entity in the VHDL model being simulated and test benched
Define the communication link between ModelSim and MATLAB
Specify a callback to a MATLAB function that executes in the context of MATLAB on behalf of the instance under simulation in ModelSim
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.
| Format | Example |
|---|---|
| Port number | 4449 on this computer |
| Port alias | matlabservice on this computer |
| Port number and remote host name | 4449@compa |
| Remote host name and port number | compa:4449 |
| Port alias and remote host Internet address | matlabservice@123.34.55.23 |
For more information on choosing TCP/IP socket ports, see Choosing TCP/IP Socket Ports.
Note The communication mode and, if appropriate, the TCP/IP specification that you specify with the matlabtb or matlabtbevalcommand must match what you specify for the communication mode when you call the hdldaemon function in MATLAB. For more information on modes of communication, see Modes of Communication. For information on choosing socket ports, see Choosing TCP/IP Socket Ports. For more information on starting the MATLAB end of the communication link, see Starting the MATLAB Server. |
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.
Note For time-based parameters, you can specify any standard time units (ns, sec, and so on). If you do not specify units, the command treats the time value as an integer value of simulation intervals. |
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 interval | time[, ...] -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.
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. |
Note When specifying signals with the -rising, -falling, and -sensitivity options, specify them in full pathname format. If you do not specify a full pathname, the command applies ModelSim rules to resolve signal specifications. |
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:
| modsimrand | That an instance of the VHDL entity modsimrand be linked with the MATLAB function modsimrand. |
| -rising /modsimrand/clk | That the MATLAB function modsimrand be called when the signal /modsimrand/clk changes from '0' to '1'. |
| -socket 4449 | That 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
| Controlling Callback Timing from a MATLAB Test Bench Function | Applying Stimuli with the ModelSim force Command | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |