| EDA Simulator Link™ MQ | ![]() |
| On this page… |
|---|
Associating the HDL Module Component with the MATLAB Link Function Specifying HDL Signal/Port and Module Paths for MATLAB Link Sessions |
This section describes establishing a relationship between the link function and the HDL model in the ModelSim simulator by naming the link function (either implicitly or explicitly) and using scheduling options (action based on a specific time or event and registering callbacks) for the MATLAB link session.
You can name and specify a MATLAB link function however you like, so long as you follow MATLAB function and file naming guidelines. By default, the EDA Simulator Link MQ software assumes the name for a MATLAB function matches the name of the HDL module that the function verifies or visualizes. For example, if you name the HDL module mystdlogic, the EDA Simulator Link MQ software assumes the corresponding MATLAB function is mystdlogic and resides in the file mystdlogic.m.
Should you name the m-function or m-file something different than the HDL instance, you must specify the -mfunc parameter of one of the link functions and provide the m-function name.
For details on MATLAB function naming guidelines, see "MATLAB Programming Tips" on files and file names in the MATLAB documentation.
By default, the EDA Simulator Link MQ software assumes the name for a MATLAB function matches the name of the HDL module that the function verifies or visualizes. See Naming a MATLAB Link Function.
In the Oscillator demo, the HDL model instantiates an HDL entity as the component u_osc_filter (see osc_top.vhd). After the HDL simulator compiles and loads the HDL model, an association must be formed between the u_osc_filter component and the MATLAB component function oscfilter. To do so, the software invokes the HDL simulator command matlabcp when the simulation is set up.
matlabcp u_osc_filter -mfunc oscfilter
The matlabcp command instructs the HDL simulator to call back the oscfilter function when u_osc_filter executes in the simulation.
The rules stated in this section are for signal/port and module path specifications for MATLAB link sessions. Other specifications may work but are not guaranteed to work in this or future releases.
In the following example:
matlabcp u_osc_filter -mfunc oscfilter
u_osc_filter is the top level component. However, if you are specifying a subcomponent, you must follow valid module path specifications for MATLAB link sessions.
Note HDL designs generally do have hierarchy; that is the reason for this syntax. However, this specification does not represent a file name hierarchy. |
These path specifications rules must be followed:
The path specification must start with a top-level module name.
The path specification can include "." or "/" path delimiters, but cannot include a mixture.
The leaf module or signal must match the HDL language of the top-level module.
The following examples show valid signal and module path specifications:
top.port_or_sig /top/sub/port_or_sig top top/sub top.sub1.sub2
The following examples show invalid signal and module path specifications:
top.sub/port_or_sig :sub:port_or_sig : :sub
These path specifications rules must be followed:
The path specification may include the top-level module name, but it is not required.
The path specification can include "." or "/" path delimiters, but cannot include a mixture.
The leaf module or signal must match the HDL language of the top-level module.
The following are valid signal and module path specification examples:
top.port_or_sig /sub/port_or_sig top top/sub top.sub1.sub2
The following are invalid signal and module path specification examples:
top.sub/port_or_sig :sub:port_or_sig : :sub
When providing TCP/IP information for a MATLAB link function, you can choose a TCP/IP port number or TCP/IP port alias or service name.
If the HDL simulator 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. See TCP/IP Socket Communication for more detail in specifying TCP/IP values.
For example,
vsim> matlabcp u_osc_filter -mfunc oscfilter -socket 4449
A remote connection might look like this:
>matlabcp u_osc_filter -mfunc oscfilter -socket computer93:4449
or
>matlabcp u_osc_filter -mfunc oscfilter -socket 4449@computer23
There are two ways to schedule the invocation of a link function:
Using the arguments to the matlabcp or matlabtb functions (Scheduling Link Functions Using Link Function Parameters)
Inside the MATLAB m-function using the tnext parameter (Scheduling Link Functions Using the tnext Parameter of an M-Function)
You can schedule a MATLAB simulation function to execute under any of the following conditions:
At a time that the MATLAB function passes to the HDL simulator with the tnext parameter
Based on a time specification that can include discrete time values, repeat intervals, and a stop time
When a specified signal experiences a rising edge—changes from '0' to '1'
When a specified signal experiences a falling edge—changes from '1' to '0'
Based on a sensitivity list—when a specified signal changes state
Decide on a combination of options that best meet your test bench application requirements. For details on using the tnext parameter and information on setting other scheduling parameters, see Scheduling Link Functions Using the tnext Parameter of an M-Function.
By default, the EDA Simulator Link MQ software invokes a MATLAB test bench function once (when time equals 0). If you want to apply more control and execute the MATLAB function more than once, decide on scheduling options that specify when and how often the EDA Simulator Link MQ software is to invoke the relevant MATLAB function. Depending on your choices, you may need to modify the function or specify specific arguments when you begin a MATLAB test bench session with the matlabtb function.
In addition, the matlabtb function can include parameters that control when the MATLAB function executes.
You must specify at least one instance of a VHDL entity or Verilog module in your HDL model. By default, the command establishes a shared memory communication link and associates the specified instance with a MATLAB function that has the same name as the instance. See Associating the HDL Module Component with the MATLAB Link Function.
The matlabtbeval function executes the MATLAB function immediately, while matlabtb provides several options for scheduling MATLAB function execution. The following table lists the various scheduling options.
Simulation Scheduling Options
| To Specify MATLAB Function Execution... | Include... | Where... |
|---|---|---|
| At explicit times | time[, ...] | time represents one of n time values, past time 0, at which the MATLAB function executes. 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. |
| At 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 executes 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 path name of a signal defined as a logic type—STD_LOGIC, BIT, X01, and so on. |
| On change of signal values (sensitivity list) | -sensitivitysignal[, ...] | signal represents a path name 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 path name format. If you do not specify a full path name, the command applies the HDL simulator 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 conditions:
| modsimrand | That an instance of the 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
You can control the callback timing of a MATLAB test bench function by using that function's tnext parameter. This parameter passes a time value to the HDL simulator, which gets added to the MATLAB function's simulation schedule. If the function returns a null value ([]) , no new entries are added to the schedule.
You can set the value of tnext to a value of type double or int64. The following table explains how the interface converts each type of data for use in the HDL simulator environment.
Time Representations for tnext Parameter
| If You Specify a... | The Interface... |
|---|---|
| double value | Converts the value to seconds. For example, the following value
converts to the simulation time nearest to 1 nanosecond as a multiple
of the current HDL simulator time resolution.tnext = 1e-9 |
| int64 value | Converts to an integer multiple of the current HDL simulator
time resolution limit. For example, the following value converts to
100 ticks of the current time resolution.tnext=int64(100) |
Note The tnext parameter represents time from the start of the simulation. Therefore, tnext should always be greater than tnow. If it is less, nothing is scheduled. |
Example. In the Oscillator demo, the oscfilter function calculates a time interval at which callbacks should be executed. This interval is calculated on the first call to oscfilter and is stored in the variable fastestrate. The variable fastestraterepresents the sample period of the fastest oversampling rate supported by the filter, derived from a base sampling period of 80 ns.
The following assignment statement sets the timing parameter tnext, which schedules the next callback to the MATLAB component function, relative to the current simulation time (tnow).
tnext = tnow + fastestrate;
A new value for tnext is returned each time the function is called.
![]() | Coding an EDA Simulator Link MQ MATLAB Application | Running MATLAB Link Sessions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |