Associating a MATLAB Link Function with an HDL Module

Overview

This section describes establishing a relationship between the link function and the HDL model in the Cadence Incisive 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.

Naming a MATLAB Link Function

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 IN 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 IN 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.

Associating the HDL Module Component with the MATLAB Link Function

By default, the EDA Simulator Link IN 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.v). 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.

Specifying HDL Signal/Port and Module Paths for MATLAB Link Sessions

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.

Path Specifications for MATLAB Link Sessions with Verilog Top Level

These path specifications rules must be followed:

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

Path Specifications for MATLAB Link Sessions with VHDL Top Level

These path specifications rules must be followed:

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

Specifying TCP/IP Values

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,

ncsim> 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

Scheduling Options for a Link Session

There are two ways to schedule the invocation of a link function:

You can schedule a MATLAB simulation function to execute under any of the following conditions:

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.

Scheduling Link Functions Using Link Function Parameters

By default, the EDA Simulator Link IN 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 IN 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.

    Note   For time-based parameters, you can specify any standard time units (ns, us, and so on). If you do not specify units, the command treats the time value as a value of HDL simulation ticks.

At a combination of explicit times and repeatedly at an intervaltime[, ...] -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.

    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:

ncsim> matlabtb test -rising /test/clk
-socket 4449

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

Arguments in the command line specify the following conditions:

testThat an instance of the entity test be linked with the MATLAB function test.
-rising /test/clkThat the MATLAB function test be called when the signal /test/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

Scheduling Link Functions Using the tnext Parameter of an M-Function

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 valueConverts 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)

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.

  


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