Hauptinhalt

Cross-Network Cosimulation

R2026b

Why Perform Cross-Network Cosimulation?

You can perform cross-network cosimulation when your setup comprises one machine running MATLAB® and Simulink® software and another machine running the HDL simulator. Typically, a Windows®-platform machine runs the MATLAB and Simulink software, while a Linux® machine runs the HDL simulator. However, these procedures apply to any combination of platforms that HDL Verifier™ and the HDL simulator support.

VCS® does not support cross-network cosimulation. Vivado® cosimulation runs as a single process with a shared DLL, and therefore does not support cross-network cosimulation.

Preparing for Cross-Network Cosimulation

Before you cosimulate between the HDL simulator and MATLAB or Simulink across a network, perform the following steps:

  1. Create your design and testing files.

    • Create and compile your HDL design, and create your MATLAB function (for MATLAB cosimulation) or Simulink model (for Simulink cosimulation).

    • If you are going to cosimulate with Simulink, use the -voptargs=+acc flag when you compile so that the design is not optimized, and include the same flag when you issue the vsim command (see Performing Cross-Network Cosimulation Using Simulink). Using this flag retains some unused signals from the design which are required by the Simulink model to run and display the results.

    Create, compile, and elaborate your HDL design, and create your MATLAB function (for MATLAB cosimulation), or Simulink model (for Simulink cosimulation).

  2. Install MATLAB and HDL Verifier on the machine with the HDL simulator.

    Note

    In releases prior to R2022b, you could copy the Linux libraries from the Windows installation and vice-versa.

    Since R2022b, MATLAB only ships platform-specific libraries, so you must also install MATLAB on the machine with the HDL simulator.

  3. On the machine with the HDL simulator, copy the HDL Verifier libraries to a known location.

    You can find the libraries in the default installed folder:

    matlabroot/toolbox/edalink/extensions/adaptor/platform/

    This table shows the variables and their available values.

    VariableDescription
    matlabrootThe location where you installed the MATLAB software.
    adaptorThe HDL simulator. You can choose from incisive, modelsim, or vcs
    platformThe operating system of the machine with the HDL simulator. You can choose from linux64 or windows64.

    See Cosimulation Libraries for the specific library file names.

    Make note of the location to which you copied the libraries; you'll need this information when you are actually establishing the connection to the HDL simulator. For purposes of this example, the sample code refers to the destination folder as HDLSERVER_LIB_LOCATION.

If you now want to cosimulate with MATLAB, see Performing Cross-Network Cosimulation Using MATLAB. If you want to cosimulate with Simulink, see Performing Cross-Network Cosimulation Using Simulink.

Performing Cross-Network Cosimulation Using MATLAB

To perform an HDL-simulator-to-MATLAB cosimulation session across a network, follow these steps:

  1. In MATLAB, get an available socket using hdldaemon:

    hdldaemon('socket',0)

    Or assign one (that you know is available):

    hdldaemon('socket',4449)
  2. On the machine with the HDL simulator, launch the HDL simulator from a shell with the following command:

    vsim -foreign "matlabclient /HDLSERVER_LIB_LOCATION/library_name;" design_name

    where the arguments shown in the following table have the values indicated.

    ArgumentValue
    library_nameThe name of the library you copied to the machine with the HDL simulator (in Preparing for Cross-Network Cosimulation).
    design_nameThe VHDL® or Verilog® design you want to load
  3. In the HDL simulator, schedule the testbench or component (matlabcp or matlabtb). Specify the socket port number from step 1 and the name of the host machine where hdldaemon is running.

  1. In MATLAB, get an available socket using hdldaemon:

    hdldaemon('socket',0)

    Or assign one:

    hdldaemon('socket',4449)
  2. Create a MATLAB configuration file (for loading the functions used in the HDL simulator) with the following contents:

    //Command file for MATLAB HDL Verifier.
    //Loading of foreign Library and HDL simulator functions.
    
    
    -loadcfc /HDLSERVER_LIB_LOCATION/library_name:matlabclient
    //TCL wrappers for MATLAB commands
    -input @proc" "nomatlabtb" "{args}" "{call" "nomatlabtb" "\$args}
    -input @proc" "matlabtb" "{args}" "{call" "matlabtb" "\$args}
    -input @proc" "matlabcp" "{args}" "{call" "matlabcp" "\$args}
    -input @proc" "matlabtbeval" "{args}" "{call" "matlabtbeval" "\$args}
    

    Where library_name is the name of the library you copied in Preparing for Cross-Network Cosimulation. You may name this configuration file anything you like.

  3. On the machine with the HDL simulator, launch the HDL simulator from a shell with the following command:

    xmsim -gui -f matlab_config_file design_name

    where the arguments shown in the following table have the values indicated.

    ArgumentValue
    matlab_config.fileThe name of the MATLAB configuration file (from step 3)
    design_nameThe VHDL or Verilog design you want to load
  4. In the HDL simulator, schedule the testbench or component (matlabcp or matlabtb). Specify the socket port number from step 1 and the name of the host where hdldaemon is running.

Performing Cross-Network Cosimulation Using Simulink

When you want to perform an HDL-simulator-to-Simulink cosimulation session across a network, follow these steps:

  1. Launch the HDL simulator from a shell with the following command:

    vsim -foreign "simlinkserver /HDLSERVER_LIB_LOCATION/library_name;
        -socket socket_num" -voptargs=+acc design_name

    where the arguments shown in the following table have the values indicated.

    ArgumentValue
    library_nameThe name of the library you copied to the machine with the HDL simulator (in Preparing for Cross-Network Cosimulation).
    socket_numThe socket number you have chosen for this connection
    design_nameThe VHDL or Verilog design you want to load
  2. On the machine with MATLAB and Simulink, start Simulink and open your model.

  3. Double-click on the HDL Cosimulation block to open the Function Block Parameters dialog box.

  4. Click on the Connections tab.

    1. Clear “The HDL simulator is running on this computer.” HDL Verifier changes the Connection method to Socket.

    2. In the text box labeled Host name, enter the host name of the machine where the HDL simulator is located.

    3. In the text box labeled Port number or service, enter the socket number from step 1.

    4. Click OK to exit block dialog box, and save your changes.

  1. Launch the HDL simulator from a shell with the following command:

    xmsim -gui -loadvpi "/HDLSERVER_LIB_LOCATION/library_name:simlinkserver"
        +socket=socket_num design_name

    where the arguments shown in the following table have the values indicated.

    ArgumentValue
    library_nameThe name of the library you copied to the machine with the HDL simulator (in Preparing for Cross-Network Cosimulation).
    socket_numThe socket number you have chosen for this connection
    design_nameThe VHDL or Verilog design you want to load
  2. On the machine with MATLAB and Simulink, start Simulink and open your model.

  3. Double-click on the HDL Cosimulation block to open the Function Block Parameters dialog box.

  4. Click on the Connections tab.

    1. Clear the check box labeled The HDL simulator is running on this computer. HDL Verifier changes the Connection method to Socket.

    2. In the Host name box, enter the host name of the machine where the HDL simulator is located.

    3. In the Port number or service box, enter the socket number from step 1.

    4. Click OK to exit block dialog box, and save your changes.

Next, run your simulation, add more blocks, or make other desired changes. For instructions on using Simulink and the HDL simulator for cosimulation, see Simulink as a Testbench or Component Simulation with Simulink.