Incorporating Hardware Designs into a Simulink Model

Overview

After you code one of your model's components in VHDL or Verilog and simulate it in the HDL simulator environment, integrate the HDL representation into your Simulink model as an HDL Cosimulation block by performing the following steps:

  1. Open your Simulink model, if it is not already open.

  2. Delete the model component that the HDL Cosimulation block is to replace.

  3. In the Simulink Library Browser, click the EDA Simulator Link DS block library. The browser displays the HDL Cosimulation and To VCD block icons.

    HDL CosimulationBlock that has at least one input port and one output port.

    To VCD FileGenerates a Value Change Dump (VCD) file. For information on using this block, see Adding a Value Change Dump (VCD) File.

  4. Copy the HDL Cosimulation block icon from the Library Browser to your model. Simulink creates a link to the block at the point where you drop the block icon.

  5. Connect any HDL Cosimulation block ports to appropriate blocks in your Simulink model.

Specifying HDL Signal/Port and Module Paths for Cosimulation

These rules are for signal/port and module path specifications in Simulink. Other specifications may work but are not guaranteed to work in this or future releases.

HDL designs generally do have hierarchy; that is the reason for this syntax. This specification does not represent a file name hierarchy.

Path Specifications for Simulink Cosimulation Sessions with Verilog Top Level

Path specifications must follow these rules:

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 Simulink Cosimulation Sessions with VHDL Top Level

Path specifications must follow these rules:

The following examples show valid signal and module path specifications:

top.port_or_sig
/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

Driving Clocks, Resets, and Enables

You can creating rising-edge or falling-edge clocks, resets, or clock enable signals that apply internal stimuli to your model under cosimulation. You can add these signals in the following ways:

Defining the Block Interface

To open the block parameters dialog box for the HDL Cosimulation block, double-click the block icon.

Simulink displays the following Block Parameters dialog box.

Mapping HDL Signals to Block Ports

The first step to configuring your EDA Simulator Link DS Cosimulation block is to map signals and signal instances of your HDL design to port definitions in your HDL Cosimulation block. In addition to identifying input and output ports, you can specify a sample time for each output port. You can also specify a fixed-point data type for each output port.

The signals that you map can be at any level of the HDL design hierarchy.

To map the signals, you can perform either of the following actions:

Obtaining Signal Information Automatically from the HDL Simulator.   The Auto Fill button lets you begin an HDL simulator query and supply a path to a component or module in an HDL model under simulation in the HDL simulator. Usually, some change of the port information is required after the query completes. The following example describes the required steps.

The example is based on a modified copy of the Manchester Receiver model (see Creating a Hardware Model Design for Use in Simulink Applications), in which all signals were first deleted from the Ports pane.

  1. Open the block parameters dialog box for the HDL Cosimulation block. Click the Ports tab. The Ports pane opens.

  2. Click the Auto Fill button. The Auto Fill dialog box opens.

    This modal dialog box requests an instance path to a component or module in your HDL model; here you enter an explicit HDL path into the edit field. The path you enter is not a file path and has nothing to do with the source files.

  3. In this example, the Auto Fill feature obtains port data for a VHDL component called manchester. The HDL path is specified as /top/manchester.

  4. Click OK to dismiss the dialog box and the query is transmitted.

  5. After the HDL simulator returns the port data, the Auto Fill feature enters it into the Ports pane, as shown in the following figure.

  6. Click Apply to commit the port additions.

    The preceding figure shows that the query entered clock, clock enable, and reset ports (labeled clk, enable, and reset respectively) into the ports list. In this example, the clk signal is entered via PreSimTcl property of the launchDiscovery function, as shown here:

    PreSimTcl',    ...
                      { 'force manchester.clk 1 0, 0 5 -repeat 10', ...
                        'force manchester.enable 1 0', ...
                        'force manchester.reset 1 0, 0 1000' }, ...                

    The enable and reset signals are deleted from the Ports pane, as the figures show.

  7. Auto Fill returns default values for output ports:

    You may need to change these values as required by your model. In this example, the Sample time should be set to 10 for all outputs. See also Specifying the Signal Data Types.

  8. Before closing the HDL Cosimulation block parameters dialog box, click Apply to commit any edits you have made.

Observe that Auto Fill returned information about all inputs and outputs for the targeted component. In many cases, this will include signals that function in the HDL simulator but cannot be connected in the Simulink model. You may delete any such entries from the list in the Ports pane if they are unwanted. You can drive the signals from Simulink; you just have to define their values by laying down Simulink blocks.

Note that Auto Fill does not return information for internal signals. If your Simulink model needs to access such signals, you must enter them into the Ports pane manually. For example, in the case of the Manchester Receiver model, you would need to add output port entries for top/manchester/sync_i, top/manchester/isum_i, and top/manchester/qsum_i, as shown in step 8.

Entering Signal Information Manually.   To enter signal information directly in the Ports pane, perform the following steps:

  1. In the HDL simulator, determine the signal path names for the HDL signals you plan to define in your block.

  2. In Simulink, open the block parameters dialog box for your HDL Cosimulation block, if it is not already open.

  3. Select the Ports pane tab. Simulink displays the following dialog box.

    In this pane, you define the HDL signals of your design that you want to include in your Simulink block and set a sample time and data type for output ports. The parameters that you should specify on the Ports pane depend on the type of device the block is modeling as follows:

  4. Enter signal path names in the Full HDL name column by double-clicking on the existing default signal.

    The following dialog box shows port definitions for an HDL Cosimulation block. The signal path names match path names that appear in the HDL simulator wave window.

  5. You must specify a sample time for the output ports. Simulink uses the value that you specify, and the current settings of the Timescales pane, to calculate an actual simulation sample time.

    For more information on sample times in the EDA Simulator Link DS cosimulation environment, see Representation of Simulation Time.

  6. You can configure the fixed-point data type of each output port explicitly if desired, or use a default (Inherited) . In the default case, Simulink determines the data type for an output port as follows:

    If Simulink can determine the data type of the signal connected to the output port, it applies that data type to the output port. For example, the data type of a connected Signal Specification block is known by back-propagation. Otherwise, Simulink queries the HDL simulator to determine the data type of the signal from the HDL module.

    To assign an explicit fixed-point data type to a signal, perform the following steps:

    1. Select either Signed or Unsigned from the Data Type column.

    2. If the signal has a fractional part, enter the Fraction Length.

      For example, if the model has an 8-bit signal with Signed data type and a Fraction Length of 5, the HDL Cosimulation block assigns it the data type sfix8_En5. If the model has an Unsigned 16-bit signal with no fractional part (a Fraction Length of 0), the HDL Cosimulation block assigns it the data type ufix16.

  7. Before closing the dialog box, click Apply to register your edits.

Specifying the Signal Data Types

The Data Type and Fraction Length parameters apply only to output signals, as follows:

The Data Type and Fraction Length properties apply only to the following signals:

Output port data types are determined by the signal width and by the Data Type and Fraction Length properties of the signal. To assign a port data type, set the Data Type and Fraction Length properties as follows:

Configuring the Simulink and HDL Simulator Timing Relationship

You configure the timing relationship between Simulink and the HDL simulator by using the Timescales pane of the block parameters dialog box. Before setting the Timescales parameters, you should read Representation of Simulation Time to understand the supported timing modes and the issues that will determine your choice of timing mode.

You can specify either a relative or an absolute timing relationship between Simulink and the HDL simulator, as described in Timescales Pane of the HDL Cosimulation block reference.

Configuring the Communication Link in the HDL Cosimulation Block

Configure a block's communication link with the Connection pane of the block parameters dialog box.

The following steps guide you through the communication configuration:

  1. Determine whether Simulink and the HDL simulator are running on the same computer. If they are, skip to step 4.

  2. Clear the The HDL simulator is running on this computer check box. (This check box defaults to selected.) Because Simulink and the HDL simulator are running on different computers, Connection method is automatically set to Socket.

  3. Enter the host name of the computer that is running your HDL simulation (in the HDL simulator) in the Host name text field. In the Port number or service text field, specify a valid port number or service for your computer system. For information on choosing TCP/IP socket ports, see Choosing TCP/IP Socket Ports. Skip to step 5.

  4. If the HDL simulator and Simulink are running on the same computer, decide whether you are going to use shared memory or TCP/IP sockets for the communication channel. For information on the different modes of communication, see Communicating with MATLAB or Simulink and the HDL Simulator.

    If you choose TCP/IP socket communication, specify a valid port number or service for your computer system in the Port number or service text field. For information on choosing TCP/IP socket ports, see Choosing TCP/IP Socket Ports.

    If you choose shared memory communication, select the Shared memory check box.

  5. If you want to bypass the HDL simulator when you run a Simulink simulation, use the Connection Mode options to specify what type of simulation connection you want. Select one of the following options:

    With the second and third options, EDA Simulator Link DS software does not communicate with the HDL simulator during Simulink simulation.

  6. Click Apply.

The following example dialog box shows communication definitions for an HDL Cosimulation block. The block is configured for Simulink and the HDL simulator running on the same computer, communicating in TCP/IP socket mode over TCP/IP port 4449.

Programmatically Controlling the Block Parameters

One way to control block parameters is through the HDL Cosimulation block graphical dialog box. However, you can also control blocks by programmatically controlling the mask parameter values and the running of simulations. Parameter values can be read using the Simulink get_param function and written using the Simulink set_param function. All block parameters have attributes that indicate whether they are:

The HDL Cosimulation block does not have any tunable parameters; thus, you get an error if you try to change a value while the simulation is running. However, it does have a few evaluated parameters.

You can see the list of parameters and their attributes by performing a right-mouse click on the block, selecting View Mask, and then the Parameters tab. The Variable column shows the programmatic parameter names. Alternatively, you can get the names programmatically by selecting the HDL Cosimulation block and then typing the following commands at the MATLAB prompt:

>> get_param(gcb, 'DialogParameters')

Some examples of using MATLAB to control simulations and mask parameter values follow. Usually, the commands are put into an M-script or M-function file and automatically called by several callback hooks available to the model developer. You can place the code in any of these suggested locations, or anywhere you choose:

Examples

The following example shows the one way of programmatically controlling the HDL Cosimulation block parameters.

Scripting the Value of the Socket Number for HDL Simulator Communication.   In a regression environment, you may need to determine the socket number for the Simulink/HDL simulator connection during the simulation to avoid collisions with other simulation runs. This example shows code that could handle that task. The script is for a 32-bit Linux platform.

ttcp_exec = [matlabroot '/toolbox/shared/hdllink/scripts/ttcp_glnx'];
 [status, results] = system([ttcp_exec ' -a']);
 if ~s
   parsed_result = strread(results,'%s');
   avail_port = parsed_result{2};
 else
   error(results);
 end
set_param('MyModel/HDL Cosimulation', 'CommPortNumber', avail_port);

Adding a Value Change Dump (VCD) File

A value change dump (VCD) file logs changes to variable values, such as the values of signals, in a file during a simulation session. VCD files can be useful during design verification. Some examples of how you might apply VCD files include the following cases:

VCD files can provide data that you might not otherwise acquire unless you understood the details of a device's internal logic. In addition, they include data that can be graphically displayed or analyzed with postprocessing tools.

For example, including the extraction of data about a particular section of a design hierarchy or data generated during a specific time interval.

The To VCD File block provided in the EDA Simulator Link DS block library serves as a VCD file generator during Simulink sessions. The block generates a VCD file that contains information about changes to signals connected to the block's input ports and names the file with a specified file name.

To generate a VCD file, perform the following steps:

  1. Open your Simulink model, if it is not already open.

  2. Identify where you want to add the To VCD File block. For example, you might temporarily replace a scope with this block.

  3. In the Simulink Library Browser, click the EDA Simulator Link DS block library.

  4. Copy the To VCD File block from the Library Browser to your model by clicking the block and dragging it from the browser to your model window.

  5. Connect the block ports to appropriate blocks in your Simulink model.

  6. Configure the To VCD File block by specifying values for parameters in the Block Parameters dialog box, as follows:

    1. Double-click the block icon. Simulink displays the following dialog box.

    2. Specify a file name for the generated VCD file in the VCD file name text box.

      • If you specify a file name only, Simulink places the file in your current MATLAB directory.

      • Specify a complete path name to place the generated file in a different location.

      • If you want the generated file to have a .vcd file type extension, you must specify it explicitly.

        Note   Do not give the same file name to different VCD blocks. Doing so results in invalid VCD files.

    3. Specify an integer in the Number of input ports text box that indicates the number of block input ports on which signal data is to be collected. The block can handle up to 943 (830,584) signals, each of which maps to a unique symbol in the VCD file.

    4. Click OK.

  7. Choose a timing relationship between Simulink and the HDL simulator. The time scale options specify a correspondence between one second of Simulink time and some quantity of HDL simulator time. Choose relative time or absolute time. For more on the To VCD File time scale, see the reference documentation for the To VCD File block.

  8. Run the simulation. Simulink captures the simulation data in the VCD file as the simulation runs.

For a description of the VCD file format see VCD File Format.

  


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