Running MATLAB Link Sessions

Overview

The EDA Simulator Link MQ software offers flexibility in how you start and control an HDL model test bench or component session with MATLAB software. A MATLAB link session is the application of a matlabtb, matlabtbeval, or matlabcp function.

Process for Running MATLAB Link Sessions

To start and control the execution of a simulation in the MATLAB environment, perform the following steps:

  1. Place MATLAB link function on the MATLAB search path.

  2. Check the MATLAB server's link status.

  3. Start the MATLAB server.

  4. Launch the HDL simulator for use with MATLAB.

  5. Load an HDL model in the HDL simulator for simulation and verification with MATLAB.

  6. Decide on how you want to schedule invocations of the MATLAB test bench function.

  7. Register callbacks for the MATLAB link session.

  8. Apply test bench stimuli.

  9. Run and monitor the test bench session.

  10. Restart simulator during a test bench session.

  11. Stop a test bench session.

Placing a MATLAB Test Bench or Component Function on the MATLAB Search Path

The MATLAB function associated with an HDL component must be on the MATLAB search path or reside in the current working directory (see the MATLAB cd function). To verify whether the function is accessible, use the MATLAB which function. The following call to which checks whether the function MyVhdlFunction is on the MATLAB search path:

which MyVhdlFunction
D:\work\modelsim\MySym\MyVhdlFunction.m

If the specified function is on the search path, which displays the complete path to the function's M-file. If the function is not on the search path, which informs you that the file was not found.

To add a MATLAB function to the MATLAB search path, open the Set Path window by clicking File > Set Path, or use the addpath command. Alternatively, for temporary access, you can change the MATLAB working directory to a desired location with the cd command.

Starting the MATLAB Server

Start the MATLAB server as follows:

  1. Start MATLAB.

  2. In the MATLAB Command Window, call the hdldaemon function with property name/property value pairs that specify whether the EDA Simulator Link MQ software is to perform the following tasks:

    Use the following syntax:

    hdldaemon('PropertyName', PropertyValue...)
    

    For example, the following command specifies using socket communication on port 4449 and a 64-bit time resolution format for the MATLAB function's output ports.

    hdldaemon('socket', 4449, 'time', 'int64')

    See hdldaemon reference documentation for when and how to specify property name/property value pairs and for more examples of using hdldaemon.

The MATLAB server can service multiple simultaneous HDL simulator modules and clients. However, your M-code must track the I/O associated with each entity or client.

Checking the MATLAB Server's Link Status

The first step to starting an HDL simulator and MATLAB test bench session is to check the MATLAB server's link status. Is the server running? If the server is running, what mode of communication and, if applicable, what TCP/IP socket port is the server using for its links? You can retrieve this information by using the MATLAB function hdldaemon with the 'status' option. For example:

hdldaemon('status')

The function displays a message that indicates whether the server is running and, if it is running, the number of connections it is handling. For example:

HDLDaemon socket server is running on port 4449 with 0 connections

If the server is not running, the message reads

HDLDaemon is NOT running

See "Link Status" in the hdldaemon reference documentation for information on determining the mode of communication and the TCP/IP socket in use.

Starting the HDL Simulator for Use with MATLAB

Start the HDL simulator directly from MATLAB by calling the MATLAB function vsim. See Starting the HDL Simulator for instructions on using vsim.

Applying Stimuli with the HDL Simulator force Command

After you establish a link between the HDL simulator and MATLAB, you can then apply stimuli to the test bench environment. One way of applying stimuli is through the iport parameter of the linked MATLAB function. This parameter forces signal values by deposit.

Other ways to apply stimuli include issuing force commands in the ModelSim main window or using the Edit > Clock option in the ModelSim Signals window.

For example, consider the following sequence of force commands:

VSIM n> force clk 0 0 ns, 1 5 ns -repeat 10 ns
VSIM n> force clk_en 1 0
VSIM n> force reset 0 0

These commands drive the following signals:

Running a Link Session

These steps describe a typical sequence for running a simulation interactively from the main HDL simulator window:

  1. Start the simulation by entering the HDL simulator run command.

    The run command offers a variety of options for applying control over how a simulation runs. For example, you can specify that a simulation run for several time steps.

    The following command instructs the HDL simulator to run the loaded simulation for 50000 time steps:

    run 50000
    
  2. Set breakpoints in the HDL and MATLAB code to verify and analyze simulation progress and correctness.

    How you set breakpoints in the HDL simulator will vary depending on what simulator application you are using. In MATLAB, there are several ways you can set breakpoints; for example, by using the Set/Clear Breakpoint button on the toolbar.

  3. Step through the simulation and examine values.

    How you step through the simulation in the HDL simulator will vary depending on what simulator application you are using. In MATLAB, there are several ways you can step through code; for example, by clicking theStep toolbar button.

  4. When you block execution of the MATLAB function, the HDL simulator also blocks and remains blocked until you clear all breakpoints in the function's M-code.

  5. Resume the simulation, as needed.

    How you resume the simulation in the HDL simulator will vary depending on what simulator application you are using. In MATLAB, there are several ways you can resume the simulation; for example, by clicking the Continue toolbar button.

    The following HDL simulator command resumes a simulation:

    run -continue
    

For more information on HDL simulator and MATLAB debugging features, see the appropriate HDL simulator documentation and MATLAB online help or documentation.

Restarting a Link Session

Because the HDL simulator issues the service requests during a MATLAB test bench session, you must restart a test bench session from the HDL simulator. To restart a session, perform the following steps:

  1. Make the HDL simulator your active window, if your input focus was not already set to that application.

  2. Reload HDL design elements and reset the simulation time to zero.

  3. Reissue the matlabtb command.

Stopping a Link Session

When you are ready to stop a test bench session, it is best to do so in an orderly way to avoid possible corruption of files and to ensure that all application tasks shut down appropriately. You should stop a session as follows:

  1. Make the HDL simulator your active window, if your input focus was not already set to that application.

  2. Halt the simulation. You must quit the simulation at the HDL simulator side or MATLAB may hang until the simulator is quit.

  3. Close your project.

  4. Exit the HDL simulator, if you are finished with the application.

  5. Quit MATLAB, if you are finished with the application. If you want to shut down the server manually, stop the server by calling hdldaemon with the 'kill' option:

    hdldaemon('kill')
    

For more information on closing HDL simulator sessions, see the HDL simulator documentation.

  


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